use of org.springframework.web.socket.WebSocketHttpHeaders in project spring-framework by spring-projects.
the class SockJsClientTests method connectAndUseSubsetOfHandshakeHeadersForHttpRequests.
@Test
public void connectAndUseSubsetOfHandshakeHeadersForHttpRequests() 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.setHttpHeaderNames("auth");
this.sockJsClient.doHandshake(handler, headers, new URI(URL)).addCallback(this.connectCallback);
assertThat(headersCaptor.getValue().size()).isEqualTo(1);
assertThat(headersCaptor.getValue().getFirst("auth")).isEqualTo("123");
assertThat(this.xhrTransport.getRequest().getHttpRequestHeaders().size()).isEqualTo(1);
assertThat(this.xhrTransport.getRequest().getHttpRequestHeaders().getFirst("auth")).isEqualTo("123");
}
use of org.springframework.web.socket.WebSocketHttpHeaders in project spring-framework by spring-projects.
the class AbstractSockJsIntegrationTests method echoXhrWithHeaders.
// SPR-13254
@Test
public void echoXhrWithHeaders() throws Exception {
AbstractXhrTransport xhrTransport = createXhrTransport();
xhrTransport.setXhrStreamingDisabled(true);
WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
headers.add("auth", "123");
testEcho(10, xhrTransport, headers);
for (Map.Entry<String, HttpHeaders> entry : this.testFilter.requests.entrySet()) {
HttpHeaders httpHeaders = entry.getValue();
assertThat(httpHeaders.getFirst("auth")).as("No auth header for: " + entry.getKey()).isEqualTo("123");
}
}
use of org.springframework.web.socket.WebSocketHttpHeaders in project spring-framework by spring-projects.
the class DefaultHandshakeHandlerTests method initHeaders.
private WebSocketHttpHeaders initHeaders(HttpHeaders httpHeaders) {
WebSocketHttpHeaders headers = new WebSocketHttpHeaders(httpHeaders);
headers.setUpgrade("WebSocket");
headers.setConnection("Upgrade");
headers.setSecWebSocketVersion("13");
headers.setSecWebSocketKey("82/ZS2YHjEnUN97HLL8tbw==");
return headers;
}
use of org.springframework.web.socket.WebSocketHttpHeaders in project yaps-client by serdaroquai.
the class RemoteConnectionManager method connect.
@Scheduled(fixedDelay = 10000)
private void connect() throws InterruptedException, ExecutionException, JSONException {
if (isConnected.compareAndSet(false, true)) {
try {
logger.info(String.format("Establishing websocket connection to %s", remoteUrl));
WebSocketHttpHeaders handshakeHeaders = new WebSocketHttpHeaders();
handshakeHeaders.set("token", token);
handshakeHeaders.set("userId", userId);
ListenableFuture<StompSession> connect = stompClient.connect(remoteUrl, handshakeHeaders, this);
stompSession = connect.get();
} catch (Exception e) {
logger.error(String.format("Could not connect to %s", remoteUrl));
disconnect();
}
}
}
Aggregations