Search in sources :

Example 11 with WebSocketHttpHeaders

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");
}
Also used : WebSocketHttpHeaders(org.springframework.web.socket.WebSocketHttpHeaders) HttpHeaders(org.springframework.http.HttpHeaders) WebSocketHttpHeaders(org.springframework.web.socket.WebSocketHttpHeaders) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 12 with WebSocketHttpHeaders

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");
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) WebSocketHttpHeaders(org.springframework.web.socket.WebSocketHttpHeaders) WebSocketHttpHeaders(org.springframework.web.socket.WebSocketHttpHeaders) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 13 with WebSocketHttpHeaders

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;
}
Also used : WebSocketHttpHeaders(org.springframework.web.socket.WebSocketHttpHeaders)

Example 14 with WebSocketHttpHeaders

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();
        }
    }
}
Also used : StompSession(org.springframework.messaging.simp.stomp.StompSession) WebSocketHttpHeaders(org.springframework.web.socket.WebSocketHttpHeaders) JSONException(org.json.JSONException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ExecutionException(java.util.concurrent.ExecutionException) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

WebSocketHttpHeaders (org.springframework.web.socket.WebSocketHttpHeaders)14 URI (java.net.URI)8 Test (org.junit.jupiter.api.Test)4 HttpHeaders (org.springframework.http.HttpHeaders)4 Test (org.junit.Test)3 TextWebSocketHandler (org.springframework.web.socket.handler.TextWebSocketHandler)3 WebSocketExtension (org.springframework.web.socket.WebSocketExtension)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 MobileSecretKeyConfig (com.itrus.portal.db.MobileSecretKeyConfig)1 MobileSecretKeyConfigExample (com.itrus.portal.db.MobileSecretKeyConfigExample)1 KeySegmentationWebSocketHandler (com.itrus.portal.mobile.controller.websocket.handler.KeySegmentationWebSocketHandler)1 WebSocketContainer (jakarta.websocket.WebSocketContainer)1 IOException (java.io.IOException)1 Principal (java.security.Principal)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 JSONException (org.json.JSONException)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 SimpleAsyncTaskExecutor (org.springframework.core.task.SimpleAsyncTaskExecutor)1