Java Code Examples for org.springframework.web.socket.sockjs.frame.SockJsFrameFormat#format()

The following examples show how to use org.springframework.web.socket.sockjs.frame.SockJsFrameFormat#format() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpSendingTransportHandlerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void frameFormats() throws Exception {
	this.servletRequest.setQueryString("c=callback");
	this.servletRequest.addParameter("c", "callback");

	SockJsFrame frame = SockJsFrame.openFrame();

	SockJsFrameFormat format = new XhrPollingTransportHandler().getFrameFormat(this.request);
	String formatted = format.format(frame);
	assertEquals(frame.getContent() + "\n", formatted);

	format = new XhrStreamingTransportHandler().getFrameFormat(this.request);
	formatted = format.format(frame);
	assertEquals(frame.getContent() + "\n", formatted);

	format = new HtmlFileTransportHandler().getFrameFormat(this.request);
	formatted = format.format(frame);
	assertEquals("<script>\np(\"" + frame.getContent() + "\");\n</script>\r\n", formatted);

	format = new EventSourceTransportHandler().getFrameFormat(this.request);
	formatted = format.format(frame);
	assertEquals("data: " + frame.getContent() + "\r\n\r\n", formatted);
}
 
Example 2
Source File: HttpSendingTransportHandlerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void frameFormats() throws Exception {
	this.servletRequest.setQueryString("c=callback");
	this.servletRequest.addParameter("c", "callback");

	SockJsFrame frame = SockJsFrame.openFrame();

	SockJsFrameFormat format = new XhrPollingTransportHandler().getFrameFormat(this.request);
	String formatted = format.format(frame);
	assertEquals(frame.getContent() + "\n", formatted);

	format = new XhrStreamingTransportHandler().getFrameFormat(this.request);
	formatted = format.format(frame);
	assertEquals(frame.getContent() + "\n", formatted);

	format = new HtmlFileTransportHandler().getFrameFormat(this.request);
	formatted = format.format(frame);
	assertEquals("<script>\np(\"" + frame.getContent() + "\");\n</script>\r\n", formatted);

	format = new EventSourceTransportHandler().getFrameFormat(this.request);
	formatted = format.format(frame);
	assertEquals("data: " + frame.getContent() + "\r\n\r\n", formatted);
}
 
Example 3
Source File: AbstractHttpSockJsSession.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected void writeFrameInternal(SockJsFrame frame) throws IOException {
	if (isActive()) {
		SockJsFrameFormat frameFormat = this.frameFormat;
		ServerHttpResponse response = this.response;
		if (frameFormat != null && response != null) {
			String formattedFrame = frameFormat.format(frame);
			if (logger.isTraceEnabled()) {
				logger.trace("Writing to HTTP response: " + formattedFrame);
			}
			response.getBody().write(formattedFrame.getBytes(SockJsFrame.CHARSET));
			response.flush();
		}
	}
}
 
Example 4
Source File: AbstractHttpSockJsSession.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected void writeFrameInternal(SockJsFrame frame) throws IOException {
	if (isActive()) {
		SockJsFrameFormat frameFormat = this.frameFormat;
		ServerHttpResponse response = this.response;
		if (frameFormat != null && response != null) {
			String formattedFrame = frameFormat.format(frame);
			if (logger.isTraceEnabled()) {
				logger.trace("Writing to HTTP response: " + formattedFrame);
			}
			response.getBody().write(formattedFrame.getBytes(SockJsFrame.CHARSET));
			response.flush();
		}
	}
}
 
Example 5
Source File: HttpSendingTransportHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void frameFormats() throws Exception {
	this.servletRequest.setQueryString("c=callback");
	this.servletRequest.addParameter("c", "callback");

	SockJsFrame frame = SockJsFrame.openFrame();

	SockJsFrameFormat format = new XhrPollingTransportHandler().getFrameFormat(this.request);
	String formatted = format.format(frame);
	assertEquals(frame.getContent() + "\n", formatted);

	format = new XhrStreamingTransportHandler().getFrameFormat(this.request);
	formatted = format.format(frame);
	assertEquals(frame.getContent() + "\n", formatted);

	format = new HtmlFileTransportHandler().getFrameFormat(this.request);
	formatted = format.format(frame);
	assertEquals("<script>\np(\"" + frame.getContent() + "\");\n</script>\r\n", formatted);

	format = new EventSourceTransportHandler().getFrameFormat(this.request);
	formatted = format.format(frame);
	assertEquals("data: " + frame.getContent() + "\r\n\r\n", formatted);

	format = new JsonpPollingTransportHandler().getFrameFormat(this.request);
	formatted = format.format(frame);
	assertEquals("/**/callback(\"" + frame.getContent() + "\");\r\n", formatted);
}