Java Code Examples for org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService#handleRequest()

The following examples show how to use org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService#handleRequest() . 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: DefaultSockJsServiceTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void handleTransportRequestWebsocket() throws Exception {
	TransportHandlingSockJsService wsService = new TransportHandlingSockJsService(
			this.taskScheduler, this.wsTransportHandler);
	String sockJsPath = "/websocket";
	setRequest("GET", sockJsPrefix + sockJsPath);
	wsService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
	assertNotEquals(403, this.servletResponse.getStatus());

	resetRequestAndResponse();
	List<String> allowed = Collections.singletonList("https://mydomain1.com");
	OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
	wsService.setHandshakeInterceptors(Collections.singletonList(interceptor));
	setRequest("GET", sockJsPrefix + sockJsPath);
	this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain1.com");
	wsService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
	assertNotEquals(403, this.servletResponse.getStatus());

	resetRequestAndResponse();
	setRequest("GET", sockJsPrefix + sockJsPath);
	this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain2.com");
	wsService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
	assertEquals(403, this.servletResponse.getStatus());
}
 
Example 2
Source File: DefaultSockJsServiceTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void handleTransportRequestWebsocket() throws Exception {
	TransportHandlingSockJsService wsService = new TransportHandlingSockJsService(
			this.taskScheduler, this.wsTransportHandler);
	String sockJsPath = "/websocket";
	setRequest("GET", sockJsPrefix + sockJsPath);
	wsService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
	assertNotEquals(403, this.servletResponse.getStatus());

	resetRequestAndResponse();
	List<String> allowed = Collections.singletonList("http://mydomain1.com");
	OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
	wsService.setHandshakeInterceptors(Collections.singletonList(interceptor));
	setRequest("GET", sockJsPrefix + sockJsPath);
	this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain1.com");
	wsService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
	assertNotEquals(403, this.servletResponse.getStatus());

	resetRequestAndResponse();
	setRequest("GET", sockJsPrefix + sockJsPath);
	this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain2.com");
	wsService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
	assertEquals(403, this.servletResponse.getStatus());
}
 
Example 3
Source File: DefaultSockJsServiceTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
 public void handleTransportRequestJsonp() throws Exception {
	TransportHandlingSockJsService jsonpService = new TransportHandlingSockJsService(this.taskScheduler, this.jsonpHandler, this.jsonpSendHandler);
	String sockJsPath = sessionUrlPrefix+ "jsonp";
	setRequest("GET", sockJsPrefix + sockJsPath);
	jsonpService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
	assertEquals(404, this.servletResponse.getStatus());

	resetRequestAndResponse();
	jsonpService.setAllowedOrigins(Collections.singletonList("http://mydomain1.com"));
	setRequest("GET", sockJsPrefix + sockJsPath);
	jsonpService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
	assertEquals(404, this.servletResponse.getStatus());

	resetRequestAndResponse();
	jsonpService.setAllowedOrigins(Collections.singletonList("*"));
	setRequest("GET", sockJsPrefix + sockJsPath);
	jsonpService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
	assertNotEquals(404, this.servletResponse.getStatus());
}
 
Example 4
Source File: DefaultSockJsServiceTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void handleTransportRequestWebsocket() throws Exception {
	TransportHandlingSockJsService wsService = new TransportHandlingSockJsService(this.taskScheduler, this.wsTransportHandler);
	String sockJsPath = "/websocket";
	setRequest("GET", sockJsPrefix + sockJsPath);
	wsService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
	assertNotEquals(403, this.servletResponse.getStatus());

	resetRequestAndResponse();
	List<String> allowed = Collections.singletonList("http://mydomain1.com");
	OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
	wsService.setHandshakeInterceptors(Collections.singletonList(interceptor));
	setRequest("GET", sockJsPrefix + sockJsPath);
	this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain1.com");
	wsService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
	assertNotEquals(403, this.servletResponse.getStatus());

	resetRequestAndResponse();
	setRequest("GET", sockJsPrefix + sockJsPath);
	this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain2.com");
	wsService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
	assertEquals(403, this.servletResponse.getStatus());
}