Search in sources :

Example 1 with ClientConfigurator

use of io.undertow.websockets.jsr.test.annotated.ClientConfigurator in project undertow by undertow-io.

the class WebsocketBasicAuthTestCase method testAuthenticatedWebsocket.

@Test
public void testAuthenticatedWebsocket() throws Exception {
    ProgramaticClientEndpoint endpoint = new ProgramaticClientEndpoint();
    ClientEndpointConfig clientEndpointConfig = ClientEndpointConfig.Builder.create().configurator(new ClientConfigurator() {

        @Override
        public void beforeRequest(Map<String, List<String>> headers) {
            headers.put(AUTHORIZATION.toString(), Collections.singletonList(BASIC + " " + FlexBase64.encodeString("user1:password1".getBytes(), false)));
        }
    }).build();
    ContainerProvider.getWebSocketContainer().connectToServer(endpoint, clientEndpointConfig, new URI("ws://" + DefaultServer.getHostAddress("default") + ":" + DefaultServer.getHostPort("default") + "/servletContext/secured"));
    Assert.assertEquals("user1", endpoint.getResponses().poll(15, TimeUnit.SECONDS));
    endpoint.session.close();
    endpoint.closeLatch.await(10, TimeUnit.SECONDS);
}
Also used : ClientEndpointConfig(javax.websocket.ClientEndpointConfig) ClientConfigurator(io.undertow.websockets.jsr.test.annotated.ClientConfigurator) Map(java.util.Map) HashMap(java.util.HashMap) URI(java.net.URI) Test(org.junit.Test)

Aggregations

ClientConfigurator (io.undertow.websockets.jsr.test.annotated.ClientConfigurator)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ClientEndpointConfig (javax.websocket.ClientEndpointConfig)1 Test (org.junit.Test)1