Search in sources :

Example 1 with PojoEndpointClient

use of org.apache.tomcat.websocket.pojo.PojoEndpointClient in project tomcat70 by apache.

the class WsWebSocketContainer method connectToServer.

@Override
public Session connectToServer(Object pojo, URI path) throws DeploymentException {
    ClientEndpoint annotation = pojo.getClass().getAnnotation(ClientEndpoint.class);
    if (annotation == null) {
        throw new DeploymentException(sm.getString("wsWebSocketContainer.missingAnnotation", pojo.getClass().getName()));
    }
    Endpoint ep = new PojoEndpointClient(pojo, Arrays.asList(annotation.decoders()));
    Class<? extends ClientEndpointConfig.Configurator> configuratorClazz = annotation.configurator();
    ClientEndpointConfig.Configurator configurator = null;
    if (!ClientEndpointConfig.Configurator.class.equals(configuratorClazz)) {
        try {
            configurator = configuratorClazz.newInstance();
        } catch (InstantiationException e) {
            throw new DeploymentException(sm.getString("wsWebSocketContainer.defaultConfiguratorFail"), e);
        } catch (IllegalAccessException e) {
            throw new DeploymentException(sm.getString("wsWebSocketContainer.defaultConfiguratorFail"), e);
        }
    }
    ClientEndpointConfig.Builder builder = ClientEndpointConfig.Builder.create();
    // Avoid NPE when using RI API JAR - see BZ 56343
    if (configurator != null) {
        builder.configurator(configurator);
    }
    ClientEndpointConfig config = builder.decoders(Arrays.asList(annotation.decoders())).encoders(Arrays.asList(annotation.encoders())).preferredSubprotocols(Arrays.asList(annotation.subprotocols())).build();
    return connectToServer(ep, config, path);
}
Also used : Endpoint(javax.websocket.Endpoint) ClientEndpoint(javax.websocket.ClientEndpoint) PojoEndpointClient(org.apache.tomcat.websocket.pojo.PojoEndpointClient) DeploymentException(javax.websocket.DeploymentException) ClientEndpointConfig(javax.websocket.ClientEndpointConfig) ClientEndpoint(javax.websocket.ClientEndpoint)

Example 2 with PojoEndpointClient

use of org.apache.tomcat.websocket.pojo.PojoEndpointClient 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)

Aggregations

PojoEndpointClient (org.apache.tomcat.websocket.pojo.PojoEndpointClient)2 ClientEndpoint (jakarta.websocket.ClientEndpoint)1 ClientEndpointConfig (jakarta.websocket.ClientEndpointConfig)1 Endpoint (jakarta.websocket.Endpoint)1 Extension (jakarta.websocket.Extension)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 ClientEndpoint (javax.websocket.ClientEndpoint)1 ClientEndpointConfig (javax.websocket.ClientEndpointConfig)1 DeploymentException (javax.websocket.DeploymentException)1 Endpoint (javax.websocket.Endpoint)1