Search in sources :

Example 1 with ClientEndpoint

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

the class WsWebSocketContainer method createClientEndpointConfig.

private ClientEndpointConfig createClientEndpointConfig(Class<?> annotatedEndpointClass) throws DeploymentException {
    ClientEndpoint annotation = annotatedEndpointClass.getAnnotation(ClientEndpoint.class);
    if (annotation == null) {
        throw new DeploymentException(sm.getString("wsWebSocketContainer.missingAnnotation", annotatedEndpointClass.getName()));
    }
    Class<? extends ClientEndpointConfig.Configurator> configuratorClazz = annotation.configurator();
    ClientEndpointConfig.Configurator configurator = null;
    if (!ClientEndpointConfig.Configurator.class.equals(configuratorClazz)) {
        try {
            configurator = configuratorClazz.getConstructor().newInstance();
        } catch (ReflectiveOperationException 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 config;
}
Also used : DeploymentException(jakarta.websocket.DeploymentException) ClientEndpointConfig(jakarta.websocket.ClientEndpointConfig) ClientEndpoint(jakarta.websocket.ClientEndpoint)

Aggregations

ClientEndpoint (jakarta.websocket.ClientEndpoint)1 ClientEndpointConfig (jakarta.websocket.ClientEndpointConfig)1 DeploymentException (jakarta.websocket.DeploymentException)1