本文整理了Java中org.springframework.web.socket.WebSocketHttpHeaders.setSecWebSocketProtocol()
方法的一些代码示例,展示了WebSocketHttpHeaders.setSecWebSocketProtocol()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebSocketHttpHeaders.setSecWebSocketProtocol()
方法的具体详情如下:
包路径:org.springframework.web.socket.WebSocketHttpHeaders
类名称:WebSocketHttpHeaders
方法名:setSecWebSocketProtocol
[英]Sets the (new) value of the Sec-WebSocket-Protocol header.
[中]设置Sec WebSocket协议头的(新)值。
代码示例来源:origin: spring-projects/spring-framework
/**
* Set the sub-protocols to use. If configured, specified sub-protocols will be
* requested in the handshake through the {@code Sec-WebSocket-Protocol} header. The
* resulting WebSocket session will contain the protocol accepted by the server, if
* any.
*/
public void setSubProtocols(List<String> protocols) {
this.headers.setSecWebSocketProtocol(protocols);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void clientEndpointConfig() throws Exception {
URI uri = new URI("ws://localhost/abc");
List<String> protocols = Collections.singletonList("abc");
this.headers.setSecWebSocketProtocol(protocols);
this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
ArgumentCaptor<ClientEndpointConfig> captor = ArgumentCaptor.forClass(ClientEndpointConfig.class);
verify(this.wsContainer).connectToServer(any(Endpoint.class), captor.capture(), any(URI.class));
ClientEndpointConfig endpointConfig = captor.getValue();
assertEquals(protocols, endpointConfig.getPreferredSubprotocols());
}
代码示例来源:origin: spring-projects/spring-framework
@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());
}
代码示例来源:origin: spring-projects/spring-framework
@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());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void handshakeHeaders() throws Exception {
URI uri = new URI("ws://localhost/abc");
List<String> protocols = Collections.singletonList("abc");
this.headers.setSecWebSocketProtocol(protocols);
this.headers.add("foo", "bar");
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
assertEquals(1, session.getHandshakeHeaders().size());
assertEquals("bar", session.getHandshakeHeaders().getFirst("foo"));
}
代码示例来源:origin: spring-projects/spring-framework
@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());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void subProtocolNegotiation() throws Exception {
WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
headers.setSecWebSocketProtocol("foo");
URI url = new URI(getWsBaseUrl() + "/ws");
WebSocketSession session = this.webSocketClient.doHandshake(new TextWebSocketHandler(), headers, url).get();
assertEquals("foo", session.getAcceptedProtocol());
session.close();
}
代码示例来源:origin: spring-projects/spring-framework
@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);
}
代码示例来源:origin: spring-projects/spring-framework
@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);
}
代码示例来源:origin: spring-projects/spring-framework
@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);
}
代码示例来源:origin: spring-projects/spring-integration
@Override
protected void openConnection() {
logger.info("Connecting to WebSocket at " + getUri());
ClientWebSocketContainer.this.headers.setSecWebSocketProtocol(getSubProtocols());
ListenableFuture<WebSocketSession> future =
this.client.doHandshake(ClientWebSocketContainer.this.webSocketHandler,
ClientWebSocketContainer.this.headers, getUri());
future.addCallback(new ListenableFutureCallback<WebSocketSession>() {
@Override
public void onSuccess(WebSocketSession session) {
ClientWebSocketContainer.this.clientSession = session;
logger.info("Successfully connected");
ClientWebSocketContainer.this.connectionLatch.countDown();
}
@Override
public void onFailure(Throwable t) {
logger.error("Failed to connect", t);
ClientWebSocketContainer.this.openConnectionException = t;
ClientWebSocketContainer.this.connectionLatch.countDown();
}
});
}
代码示例来源:origin: org.springframework/spring-websocket
/**
* Set the sub-protocols to use. If configured, specified sub-protocols will be
* requested in the handshake through the {@code Sec-WebSocket-Protocol} header. The
* resulting WebSocket session will contain the protocol accepted by the server, if
* any.
*/
public void setSubProtocols(List<String> protocols) {
this.headers.setSecWebSocketProtocol(protocols);
}
代码示例来源:origin: apache/servicemix-bundles
/**
* Set the sub-protocols to use. If configured, specified sub-protocols will be
* requested in the handshake through the {@code Sec-WebSocket-Protocol} header. The
* resulting WebSocket session will contain the protocol accepted by the server, if
* any.
*/
public void setSubProtocols(List<String> protocols) {
this.headers.setSecWebSocketProtocol(protocols);
}
代码示例来源:origin: org.springframework.integration/spring-integration-websocket
@Override
protected void openConnection() {
logger.info("Connecting to WebSocket at " + getUri());
ClientWebSocketContainer.this.headers.setSecWebSocketProtocol(getSubProtocols());
ListenableFuture<WebSocketSession> future =
this.client.doHandshake(ClientWebSocketContainer.this.webSocketHandler,
ClientWebSocketContainer.this.headers, getUri());
future.addCallback(new ListenableFutureCallback<WebSocketSession>() {
@Override
public void onSuccess(WebSocketSession session) {
ClientWebSocketContainer.this.clientSession = session;
logger.info("Successfully connected");
ClientWebSocketContainer.this.connectionLatch.countDown();
}
@Override
public void onFailure(Throwable t) {
logger.error("Failed to connect", t);
ClientWebSocketContainer.this.openConnectionException = t;
ClientWebSocketContainer.this.connectionLatch.countDown();
}
});
}
内容来源于网络,如有侵权,请联系作者删除!