@Test public void standardWebSocketClientConfiguratorInsertsHandshakeHeaders() throws Exception { URI uri = new URI("ws://localhost/abc"); this.headers.add("foo", "bar"); 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(); Map<String, List<String>> headers = new HashMap<>(); endpointConfig.getConfigurator().beforeRequest(headers); assertEquals(1, headers.size()); }
@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(); assertEquals("No auth header for: " + entry.getKey(), "123", httpHeaders.getFirst("auth")); } }
@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")); }
WebSocketHttpHeaders headers = new WebSocketHttpHeaders(); String auth = "user" + ":" + "password"; headers.add("Authorization", "Basic " + new String(Base64.getEncoder().encode(auth.getBytes()))); stompClient.connect(url, headers, new MyStompSessionHandler());