Java Code Examples for org.springframework.web.socket.WebSocketHttpHeaders#setSecWebSocketProtocol()

The following examples show how to use org.springframework.web.socket.WebSocketHttpHeaders#setSecWebSocketProtocol() . 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: DefaultHandshakeHandlerTests.java    From spring4-understanding with Apache License 2.0 7 votes vote down vote up
@Test
public void subProtocolCapableHandlerNoMatch() throws Exception {

	given(this.upgradeStrategy.getSupportedVersions()).willReturn(new String[]{"13"});

	this.servletRequest.setMethod("GET");

	WebSocketHttpHeaders headers = new WebSocketHttpHeaders(this.request.getHeaders());
	headers.setUpgrade("WebSocket");
	headers.setConnection("Upgrade");
	headers.setSecWebSocketVersion("13");
	headers.setSecWebSocketKey("82/ZS2YHjEnUN97HLL8tbw==");
	headers.setSecWebSocketProtocol("v10.stomp");

	WebSocketHandler handler = new SubProtocolCapableHandler("v12.stomp", "v11.stomp");
	Map<String, Object> attributes = Collections.<String, Object>emptyMap();
	this.handshakeHandler.doHandshake(this.request, this.response, handler, attributes);

	verify(this.upgradeStrategy).upgrade(this.request, this.response,
			null, Collections.<WebSocketExtension>emptyList(), null, handler, attributes);
}
 
Example 2
Source File: DefaultHandshakeHandlerTests.java    From spring-analysis-note with MIT License 7 votes vote down vote up
@Test
public void supportedSubProtocols() {
	this.handshakeHandler.setSupportedProtocols("stomp", "mqtt");
	given(this.upgradeStrategy.getSupportedVersions()).willReturn(new String[] {"13"});
	this.servletRequest.setMethod("GET");

	WebSocketHttpHeaders headers = new WebSocketHttpHeaders(this.request.getHeaders());
	headers.setUpgrade("WebSocket");
	headers.setConnection("Upgrade");
	headers.setSecWebSocketVersion("13");
	headers.setSecWebSocketKey("82/ZS2YHjEnUN97HLL8tbw==");
	headers.setSecWebSocketProtocol("STOMP");

	WebSocketHandler handler = new TextWebSocketHandler();
	Map<String, Object> attributes = Collections.emptyMap();
	this.handshakeHandler.doHandshake(this.request, this.response, handler, attributes);

	verify(this.upgradeStrategy).upgrade(this.request, this.response, "STOMP",
			Collections.emptyList(), null, handler, attributes);
}
 
Example 3
Source File: WebSocketConnectionManagerTests.java    From java-technology-stack with MIT License 7 votes vote down vote up
@Test
public void openConnection() throws Exception {
	List<String> subprotocols = Arrays.asList("abc");

	TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(false);
	WebSocketHandler handler = new TextWebSocketHandler();

	WebSocketConnectionManager manager = new WebSocketConnectionManager(client, handler , "/path/{id}", "123");
	manager.setSubProtocols(subprotocols);
	manager.openConnection();

	WebSocketHttpHeaders expectedHeaders = new WebSocketHttpHeaders();
	expectedHeaders.setSecWebSocketProtocol(subprotocols);

	assertEquals(expectedHeaders, client.headers);
	assertEquals(new URI("/path/123"), client.uri);

	WebSocketHandlerDecorator loggingHandler = (WebSocketHandlerDecorator) client.webSocketHandler;
	assertEquals(LoggingWebSocketHandlerDecorator.class, loggingHandler.getClass());

	assertSame(handler, loggingHandler.getDelegate());
}
 
Example 4
Source File: DefaultHandshakeHandlerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void supportedSubProtocols() {
	this.handshakeHandler.setSupportedProtocols("stomp", "mqtt");
	given(this.upgradeStrategy.getSupportedVersions()).willReturn(new String[] {"13"});
	this.servletRequest.setMethod("GET");

	WebSocketHttpHeaders headers = new WebSocketHttpHeaders(this.request.getHeaders());
	headers.setUpgrade("WebSocket");
	headers.setConnection("Upgrade");
	headers.setSecWebSocketVersion("13");
	headers.setSecWebSocketKey("82/ZS2YHjEnUN97HLL8tbw==");
	headers.setSecWebSocketProtocol("STOMP");

	WebSocketHandler handler = new TextWebSocketHandler();
	Map<String, Object> attributes = Collections.emptyMap();
	this.handshakeHandler.doHandshake(this.request, this.response, handler, attributes);

	verify(this.upgradeStrategy).upgrade(this.request, this.response, "STOMP",
			Collections.emptyList(), null, handler, attributes);
}
 
Example 5
Source File: DefaultHandshakeHandlerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void subProtocolCapableHandler() throws Exception {

	given(this.upgradeStrategy.getSupportedVersions()).willReturn(new String[]{"13"});

	this.servletRequest.setMethod("GET");

	WebSocketHttpHeaders headers = new WebSocketHttpHeaders(this.request.getHeaders());
	headers.setUpgrade("WebSocket");
	headers.setConnection("Upgrade");
	headers.setSecWebSocketVersion("13");
	headers.setSecWebSocketKey("82/ZS2YHjEnUN97HLL8tbw==");
	headers.setSecWebSocketProtocol("v11.stomp");

	WebSocketHandler handler = new SubProtocolCapableHandler("v12.stomp", "v11.stomp");
	Map<String, Object> attributes = Collections.<String, Object>emptyMap();
	this.handshakeHandler.doHandshake(this.request, this.response, handler, attributes);

	verify(this.upgradeStrategy).upgrade(this.request, this.response,
			"v11.stomp", Collections.<WebSocketExtension>emptyList(), null, handler, attributes);
}
 
Example 6
Source File: DefaultHandshakeHandlerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void supportedSubProtocols() throws Exception {

	this.handshakeHandler.setSupportedProtocols("stomp", "mqtt");

	given(this.upgradeStrategy.getSupportedVersions()).willReturn(new String[] {"13"});

	this.servletRequest.setMethod("GET");

	WebSocketHttpHeaders headers = new WebSocketHttpHeaders(this.request.getHeaders());
	headers.setUpgrade("WebSocket");
	headers.setConnection("Upgrade");
	headers.setSecWebSocketVersion("13");
	headers.setSecWebSocketKey("82/ZS2YHjEnUN97HLL8tbw==");
	headers.setSecWebSocketProtocol("STOMP");

	WebSocketHandler handler = new TextWebSocketHandler();
	Map<String, Object> attributes = Collections.<String, Object>emptyMap();
	this.handshakeHandler.doHandshake(this.request, this.response, handler, attributes);

	verify(this.upgradeStrategy).upgrade(this.request, this.response,
			"STOMP", Collections.<WebSocketExtension>emptyList(), null, handler, attributes);
}
 
Example 7
Source File: JettyWebSocketClientTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void doHandshake() throws Exception {

	WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
	headers.setSecWebSocketProtocol(Arrays.asList("echo"));

	this.wsSession = this.client.doHandshake(new TextWebSocketHandler(), headers, new URI(this.wsUrl)).get();

	assertEquals(this.wsUrl, this.wsSession.getUri().toString());
	assertEquals("echo", this.wsSession.getAcceptedProtocol());
}
 
Example 8
Source File: WebSocketConnectionManagerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void openConnection() throws Exception {
	List<String> subprotocols = Arrays.asList("abc");

	TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(false);
	WebSocketHandler handler = new TextWebSocketHandler();

	WebSocketConnectionManager manager = new WebSocketConnectionManager(client, handler , "/path/{id}", "123");
	manager.setSubProtocols(subprotocols);
	manager.openConnection();

	WebSocketHttpHeaders expectedHeaders = new WebSocketHttpHeaders();
	expectedHeaders.setSecWebSocketProtocol(subprotocols);

	assertEquals(expectedHeaders, client.headers);
	assertEquals(new URI("/path/123"), client.uri);

	WebSocketHandlerDecorator loggingHandler = (WebSocketHandlerDecorator) client.webSocketHandler;
	assertEquals(LoggingWebSocketHandlerDecorator.class, loggingHandler.getClass());

	assertSame(handler, loggingHandler.getDelegate());
}
 
Example 9
Source File: DefaultHandshakeHandlerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void subProtocolCapableHandlerNoMatch() {
	given(this.upgradeStrategy.getSupportedVersions()).willReturn(new String[] {"13"});

	this.servletRequest.setMethod("GET");

	WebSocketHttpHeaders headers = new WebSocketHttpHeaders(this.request.getHeaders());
	headers.setUpgrade("WebSocket");
	headers.setConnection("Upgrade");
	headers.setSecWebSocketVersion("13");
	headers.setSecWebSocketKey("82/ZS2YHjEnUN97HLL8tbw==");
	headers.setSecWebSocketProtocol("v10.stomp");

	WebSocketHandler handler = new SubProtocolCapableHandler("v12.stomp", "v11.stomp");
	Map<String, Object> attributes = Collections.<String, Object>emptyMap();
	this.handshakeHandler.doHandshake(this.request, this.response, handler, attributes);

	verify(this.upgradeStrategy).upgrade(this.request, this.response, null,
			Collections.emptyList(), null, handler, attributes);
}
 
Example 10
Source File: DefaultHandshakeHandlerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void subProtocolCapableHandler() {
	given(this.upgradeStrategy.getSupportedVersions()).willReturn(new String[] {"13"});

	this.servletRequest.setMethod("GET");

	WebSocketHttpHeaders headers = new WebSocketHttpHeaders(this.request.getHeaders());
	headers.setUpgrade("WebSocket");
	headers.setConnection("Upgrade");
	headers.setSecWebSocketVersion("13");
	headers.setSecWebSocketKey("82/ZS2YHjEnUN97HLL8tbw==");
	headers.setSecWebSocketProtocol("v11.stomp");

	WebSocketHandler handler = new SubProtocolCapableHandler("v12.stomp", "v11.stomp");
	Map<String, Object> attributes = Collections.<String, Object>emptyMap();
	this.handshakeHandler.doHandshake(this.request, this.response, handler, attributes);

	verify(this.upgradeStrategy).upgrade(this.request, this.response, "v11.stomp",
			Collections.emptyList(), null, handler, attributes);
}
 
Example 11
Source File: WebSocketConnectionManagerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void openConnection() throws Exception {
	List<String> subprotocols = Arrays.asList("abc");

	TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(false);
	WebSocketHandler handler = new TextWebSocketHandler();

	WebSocketConnectionManager manager = new WebSocketConnectionManager(client, handler , "/path/{id}", "123");
	manager.setSubProtocols(subprotocols);
	manager.openConnection();

	WebSocketHttpHeaders expectedHeaders = new WebSocketHttpHeaders();
	expectedHeaders.setSecWebSocketProtocol(subprotocols);

	assertEquals(expectedHeaders, client.headers);
	assertEquals(new URI("/path/123"), client.uri);

	WebSocketHandlerDecorator loggingHandler = (WebSocketHandlerDecorator) client.webSocketHandler;
	assertEquals(LoggingWebSocketHandlerDecorator.class, loggingHandler.getClass());

	assertSame(handler, loggingHandler.getDelegate());
}
 
Example 12
Source File: DefaultHandshakeHandlerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void subProtocolCapableHandlerNoMatch() {
	given(this.upgradeStrategy.getSupportedVersions()).willReturn(new String[] {"13"});

	this.servletRequest.setMethod("GET");

	WebSocketHttpHeaders headers = new WebSocketHttpHeaders(this.request.getHeaders());
	headers.setUpgrade("WebSocket");
	headers.setConnection("Upgrade");
	headers.setSecWebSocketVersion("13");
	headers.setSecWebSocketKey("82/ZS2YHjEnUN97HLL8tbw==");
	headers.setSecWebSocketProtocol("v10.stomp");

	WebSocketHandler handler = new SubProtocolCapableHandler("v12.stomp", "v11.stomp");
	Map<String, Object> attributes = Collections.<String, Object>emptyMap();
	this.handshakeHandler.doHandshake(this.request, this.response, handler, attributes);

	verify(this.upgradeStrategy).upgrade(this.request, this.response, null,
			Collections.emptyList(), null, handler, attributes);
}
 
Example 13
Source File: DefaultHandshakeHandlerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void subProtocolCapableHandler() {
	given(this.upgradeStrategy.getSupportedVersions()).willReturn(new String[] {"13"});

	this.servletRequest.setMethod("GET");

	WebSocketHttpHeaders headers = new WebSocketHttpHeaders(this.request.getHeaders());
	headers.setUpgrade("WebSocket");
	headers.setConnection("Upgrade");
	headers.setSecWebSocketVersion("13");
	headers.setSecWebSocketKey("82/ZS2YHjEnUN97HLL8tbw==");
	headers.setSecWebSocketProtocol("v11.stomp");

	WebSocketHandler handler = new SubProtocolCapableHandler("v12.stomp", "v11.stomp");
	Map<String, Object> attributes = Collections.<String, Object>emptyMap();
	this.handshakeHandler.doHandshake(this.request, this.response, handler, attributes);

	verify(this.upgradeStrategy).upgrade(this.request, this.response, "v11.stomp",
			Collections.emptyList(), null, handler, attributes);
}
 
Example 14
Source File: JettyWebSocketClientTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void doHandshakeWithTaskExecutor() throws Exception {

	WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
	headers.setSecWebSocketProtocol(Arrays.asList("echo"));

	this.client.setTaskExecutor(new SimpleAsyncTaskExecutor());
	this.wsSession = this.client.doHandshake(new TextWebSocketHandler(), headers, new URI(this.wsUrl)).get();

	assertEquals(this.wsUrl, this.wsSession.getUri().toString());
	assertEquals("echo", this.wsSession.getAcceptedProtocol());
}
 
Example 15
Source File: JettyWebSocketClientTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void doHandshake() throws Exception {

	WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
	headers.setSecWebSocketProtocol(Arrays.asList("echo"));

	this.wsSession = this.client.doHandshake(new TextWebSocketHandler(), headers, new URI(this.wsUrl)).get();

	assertEquals(this.wsUrl, this.wsSession.getUri().toString());
	assertEquals("echo", this.wsSession.getAcceptedProtocol());
}
 
Example 16
Source File: JettyWebSocketClientTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void doHandshakeWithTaskExecutor() throws Exception {

	WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
	headers.setSecWebSocketProtocol(Arrays.asList("echo"));

	this.client.setTaskExecutor(new SimpleAsyncTaskExecutor());
	this.wsSession = this.client.doHandshake(new TextWebSocketHandler(), headers, new URI(this.wsUrl)).get();

	assertEquals(this.wsUrl, this.wsSession.getUri().toString());
	assertEquals("echo", this.wsSession.getAcceptedProtocol());
}
 
Example 17
Source File: JettyWebSocketClientTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void doHandshakeWithTaskExecutor() throws Exception {

	WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
	headers.setSecWebSocketProtocol(Arrays.asList("echo"));

	this.client.setTaskExecutor(new SimpleAsyncTaskExecutor());
	this.wsSession = this.client.doHandshake(new TextWebSocketHandler(), headers, new URI(this.wsUrl)).get();

	assertEquals(this.wsUrl, this.wsSession.getUri().toString());
	assertEquals("echo", this.wsSession.getAcceptedProtocol());
}
 
Example 18
Source File: JettyWebSocketClientTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void doHandshake() throws Exception {

	WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
	headers.setSecWebSocketProtocol(Arrays.asList("echo"));

	this.wsSession = this.client.doHandshake(new TextWebSocketHandler(), headers, new URI(this.wsUrl)).get();

	assertEquals(this.wsUrl, this.wsSession.getUri().toString());
	assertEquals("echo", this.wsSession.getAcceptedProtocol());
}