use of org.springframework.web.socket.WebSocketHttpHeaders in project portal by ixinportal.
the class KeySegmentationTask method buildTask.
public static void buildTask(final WebSocketSession session, final WebSocketMessage<?> message) throws UnsupportedEncodingException, NoSuchAlgorithmException, URISyntaxException {
// header 获取云盾秘钥连接 // TODO: 2017/11/29
final WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
MobileSecretKeyConfigExample configExample = new MobileSecretKeyConfigExample();
MobileSecretKeyConfig keyConfig = accesskeyLiensConfigService.selectByConfig(configExample);
// keyConfig.getPasswordNumber()
headers.add("appId", keyConfig.getPasswordNumber());
headers.add("Content-Signature", Base64.encode(HMACSHA1.getHmacSHA1(/*keyConfig.getPasswordNumber(),keyConfig.getPassword()*/
"1", "123"), false));
final URI uri = new URI(/*keyConfig.getConnectAddress()*/
"ws://192.168.102.237:8080/km/webSocketServer");
Runnable task = new Runnable() {
@Override
public void run() {
WebSocketClient webSocketClient = new StandardWebSocketClient();
webSocketClient.doHandshake(new KeySegmentationWebSocketHandler(session, message), headers, uri);
}
};
threadPool.execute(task);
}
use of org.springframework.web.socket.WebSocketHttpHeaders in project spring-framework by spring-projects.
the class WebSocketConnectionManagerTests method openConnection.
@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);
assertThat(client.headers).isEqualTo(expectedHeaders);
assertThat(client.uri).isEqualTo(new URI("/path/123"));
WebSocketHandlerDecorator loggingHandler = (WebSocketHandlerDecorator) client.webSocketHandler;
assertThat(loggingHandler.getClass()).isEqualTo(LoggingWebSocketHandlerDecorator.class);
assertThat(loggingHandler.getDelegate()).isSameAs(handler);
}
use of org.springframework.web.socket.WebSocketHttpHeaders in project spring-framework by spring-projects.
the class SockJsClientTests method connectWithHandshakeHeaders.
// SPR-13254
@Test
public void connectWithHandshakeHeaders() throws Exception {
ArgumentCaptor<HttpHeaders> headersCaptor = setupInfoRequest(false);
this.xhrTransport.setStreamingDisabled(true);
WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
headers.set("foo", "bar");
headers.set("auth", "123");
this.sockJsClient.doHandshake(handler, headers, new URI(URL)).addCallback(this.connectCallback);
HttpHeaders httpHeaders = headersCaptor.getValue();
assertThat(httpHeaders.size()).isEqualTo(2);
assertThat(httpHeaders.getFirst("foo")).isEqualTo("bar");
assertThat(httpHeaders.getFirst("auth")).isEqualTo("123");
httpHeaders = this.xhrTransport.getRequest().getHttpRequestHeaders();
assertThat(httpHeaders.size()).isEqualTo(2);
assertThat(httpHeaders.getFirst("foo")).isEqualTo("bar");
assertThat(httpHeaders.getFirst("auth")).isEqualTo("123");
}
use of org.springframework.web.socket.WebSocketHttpHeaders in project spring-framework by spring-projects.
the class JettyWebSocketClientTests method doHandshake.
@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());
}
use of org.springframework.web.socket.WebSocketHttpHeaders in project spring-framework by spring-projects.
the class JettyWebSocketClientTests method doHandshakeWithTaskExecutor.
@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());
}
Aggregations