Search in sources :

Example 1 with ServerEndpoint

use of jakarta.websocket.server.ServerEndpoint in project tomcat by apache.

the class WsServerContainer method addEndpoint.

void addEndpoint(Class<?> pojo, boolean fromAnnotatedPojo) throws DeploymentException {
    if (deploymentFailed) {
        throw new DeploymentException(sm.getString("serverContainer.failedDeployment", servletContext.getContextPath(), servletContext.getVirtualServerName()));
    }
    ServerEndpointConfig sec;
    try {
        ServerEndpoint annotation = pojo.getAnnotation(ServerEndpoint.class);
        if (annotation == null) {
            throw new DeploymentException(sm.getString("serverContainer.missingAnnotation", pojo.getName()));
        }
        String path = annotation.value();
        // Validate encoders
        validateEncoders(annotation.encoders(), getInstanceManager(Thread.currentThread().getContextClassLoader()));
        // ServerEndpointConfig
        Class<? extends Configurator> configuratorClazz = annotation.configurator();
        Configurator configurator = null;
        if (!configuratorClazz.equals(Configurator.class)) {
            try {
                configurator = annotation.configurator().getConstructor().newInstance();
            } catch (ReflectiveOperationException e) {
                throw new DeploymentException(sm.getString("serverContainer.configuratorFail", annotation.configurator().getName(), pojo.getClass().getName()), e);
            }
        }
        sec = ServerEndpointConfig.Builder.create(pojo, path).decoders(Arrays.asList(annotation.decoders())).encoders(Arrays.asList(annotation.encoders())).subprotocols(Arrays.asList(annotation.subprotocols())).configurator(configurator).build();
    } catch (DeploymentException de) {
        failDeployment();
        throw de;
    }
    addEndpoint(sec, fromAnnotatedPojo);
}
Also used : ServerEndpointConfig(jakarta.websocket.server.ServerEndpointConfig) Configurator(jakarta.websocket.server.ServerEndpointConfig.Configurator) DeploymentException(jakarta.websocket.DeploymentException) ServerEndpoint(jakarta.websocket.server.ServerEndpoint)

Aggregations

DeploymentException (jakarta.websocket.DeploymentException)1 ServerEndpoint (jakarta.websocket.server.ServerEndpoint)1 ServerEndpointConfig (jakarta.websocket.server.ServerEndpointConfig)1 Configurator (jakarta.websocket.server.ServerEndpointConfig.Configurator)1