Search in sources :

Example 6 with Extension

use of jakarta.websocket.Extension in project tomcat by apache.

the class TesterWsClientAutobahn method executeTestCase.

private static void executeTestCase(WebSocketContainer wsc, int testCase) throws Exception {
    URI uri = new URI("ws://" + HOST + ":" + PORT + "/runCase?case=" + testCase + "&agent=" + USER_AGENT);
    TestCaseClient testCaseClient = new TestCaseClient();
    Extension permessageDeflate = new WsExtension("permessage-deflate");
    // Advertise support for client_max_window_bits
    // Client only supports some values so there will be some failures here
    // Note Autobahn returns a 400 response if you provide a value for
    // client_max_window_bits
    permessageDeflate.getParameters().add(new WsExtensionParameter("client_max_window_bits", null));
    List<Extension> extensions = new ArrayList<>(1);
    extensions.add(permessageDeflate);
    Endpoint ep = new PojoEndpointClient(testCaseClient, null, null);
    ClientEndpointConfig.Builder builder = ClientEndpointConfig.Builder.create();
    ClientEndpointConfig config = builder.extensions(extensions).build();
    wsc.connectToServer(ep, config, uri);
    testCaseClient.waitForClose();
}
Also used : Extension(jakarta.websocket.Extension) Endpoint(jakarta.websocket.Endpoint) ClientEndpoint(jakarta.websocket.ClientEndpoint) PojoEndpointClient(org.apache.tomcat.websocket.pojo.PojoEndpointClient) ArrayList(java.util.ArrayList) ClientEndpointConfig(jakarta.websocket.ClientEndpointConfig) URI(java.net.URI)

Example 7 with Extension

use of jakarta.websocket.Extension in project tomcat by apache.

the class TestUtil method doTestParseExtensionHeaderMultiple.

private void doTestParseExtensionHeaderMultiple(String header) {
    // Simple test
    List<Extension> result = new ArrayList<>();
    Util.parseExtensionHeader(result, header);
    Assert.assertEquals(3, result.size());
    Extension ext = result.get(0);
    Assert.assertEquals("ext", ext.getName());
    List<Parameter> params = ext.getParameters();
    Assert.assertEquals(2, params.size());
    Parameter paramA = params.get(0);
    Assert.assertEquals("a", paramA.getName());
    Assert.assertEquals("1", paramA.getValue());
    Parameter paramB = params.get(1);
    Assert.assertEquals("b", paramB.getName());
    Assert.assertEquals("2", paramB.getValue());
    Extension ext2 = result.get(1);
    Assert.assertEquals("ext2", ext2.getName());
    List<Parameter> params2 = ext2.getParameters();
    Assert.assertEquals(2, params2.size());
    Parameter paramC = params2.get(0);
    Assert.assertEquals("c", paramC.getName());
    Assert.assertNull(paramC.getValue());
    Parameter paramD = params2.get(1);
    Assert.assertEquals("d", paramD.getName());
    Assert.assertEquals("xyz", paramD.getValue());
    Extension ext3 = result.get(2);
    Assert.assertEquals("ext3", ext3.getName());
    List<Parameter> params3 = ext3.getParameters();
    Assert.assertEquals(0, params3.size());
}
Also used : Extension(jakarta.websocket.Extension) ArrayList(java.util.ArrayList) Parameter(jakarta.websocket.Extension.Parameter)

Example 8 with Extension

use of jakarta.websocket.Extension in project tomcat by apache.

the class TestUtil method doTestParseExtensionHeaderSimple.

private void doTestParseExtensionHeaderSimple(String header) {
    // Simple test
    List<Extension> result = new ArrayList<>();
    Util.parseExtensionHeader(result, header);
    Assert.assertEquals(1, result.size());
    Extension ext = result.get(0);
    Assert.assertEquals("ext", ext.getName());
    List<Parameter> params = ext.getParameters();
    Assert.assertEquals(2, params.size());
    Parameter paramA = params.get(0);
    Assert.assertEquals("a", paramA.getName());
    Assert.assertEquals("1", paramA.getValue());
    Parameter paramB = params.get(1);
    Assert.assertEquals("b", paramB.getName());
    Assert.assertEquals("2", paramB.getValue());
}
Also used : Extension(jakarta.websocket.Extension) ArrayList(java.util.ArrayList) Parameter(jakarta.websocket.Extension.Parameter)

Example 9 with Extension

use of jakarta.websocket.Extension in project tomcat by apache.

the class WsWebSocketContainer method generateExtensionHeaders.

private static List<String> generateExtensionHeaders(List<Extension> extensions) {
    List<String> result = new ArrayList<>(extensions.size());
    for (Extension extension : extensions) {
        StringBuilder header = new StringBuilder();
        header.append(extension.getName());
        for (Extension.Parameter param : extension.getParameters()) {
            header.append(';');
            header.append(param.getName());
            String value = param.getValue();
            if (value != null && value.length() > 0) {
                header.append('=');
                header.append(value);
            }
        }
        result.add(header.toString());
    }
    return result;
}
Also used : Extension(jakarta.websocket.Extension) ArrayList(java.util.ArrayList)

Example 10 with Extension

use of jakarta.websocket.Extension in project tomcat by apache.

the class PerMessageDeflate method getExtensionResponse.

@Override
public Extension getExtensionResponse() {
    Extension result = new WsExtension(NAME);
    List<Extension.Parameter> params = result.getParameters();
    if (!serverContextTakeover) {
        params.add(new WsExtensionParameter(SERVER_NO_CONTEXT_TAKEOVER, null));
    }
    if (serverMaxWindowBits != -1) {
        params.add(new WsExtensionParameter(SERVER_MAX_WINDOW_BITS, Integer.toString(serverMaxWindowBits)));
    }
    if (!clientContextTakeover) {
        params.add(new WsExtensionParameter(CLIENT_NO_CONTEXT_TAKEOVER, null));
    }
    if (clientMaxWindowBits != -1) {
        params.add(new WsExtensionParameter(CLIENT_MAX_WINDOW_BITS, Integer.toString(clientMaxWindowBits)));
    }
    return result;
}
Also used : Extension(jakarta.websocket.Extension) Parameter(jakarta.websocket.Extension.Parameter)

Aggregations

Extension (jakarta.websocket.Extension)12 ArrayList (java.util.ArrayList)10 Endpoint (jakarta.websocket.Endpoint)3 Parameter (jakarta.websocket.Extension.Parameter)3 URI (java.net.URI)3 List (java.util.List)3 ClientEndpoint (jakarta.websocket.ClientEndpoint)2 ClientEndpointConfig (jakarta.websocket.ClientEndpointConfig)2 DeploymentException (jakarta.websocket.DeploymentException)2 InetSocketAddress (java.net.InetSocketAddress)2 Transformation (org.apache.tomcat.websocket.Transformation)2 WebSocketExtension (org.springframework.web.socket.WebSocketExtension)2 ServletException (jakarta.servlet.ServletException)1 EndpointConfig (jakarta.websocket.EndpointConfig)1 HandshakeResponse (jakarta.websocket.HandshakeResponse)1 Session (jakarta.websocket.Session)1 WebSocketContainer (jakarta.websocket.WebSocketContainer)1 ServerEndpoint (jakarta.websocket.server.ServerEndpoint)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1