Search in sources :

Example 1 with EndpointMetadata

use of org.eclipse.jetty.websocket.jsr356.metadata.EndpointMetadata in project jetty.project by eclipse.

the class ClientContainer method getClientEndpointMetadata.

public EndpointMetadata getClientEndpointMetadata(Class<?> endpoint, EndpointConfig config) {
    synchronized (endpointClientMetadataCache) {
        EndpointMetadata metadata = endpointClientMetadataCache.get(endpoint);
        if (metadata != null) {
            return metadata;
        }
        ClientEndpoint anno = endpoint.getAnnotation(ClientEndpoint.class);
        if (anno != null) {
            // Annotated takes precedence here
            AnnotatedClientEndpointMetadata annoMetadata = new AnnotatedClientEndpointMetadata(this, endpoint);
            AnnotatedEndpointScanner<ClientEndpoint, ClientEndpointConfig> scanner = new AnnotatedEndpointScanner<>(annoMetadata);
            scanner.scan();
            metadata = annoMetadata;
        } else if (Endpoint.class.isAssignableFrom(endpoint)) {
            // extends Endpoint
            @SuppressWarnings("unchecked") Class<? extends Endpoint> eendpoint = (Class<? extends Endpoint>) endpoint;
            metadata = new SimpleEndpointMetadata(eendpoint, config);
        } else {
            StringBuilder err = new StringBuilder();
            err.append("Not a recognized websocket [");
            err.append(endpoint.getName());
            err.append("] does not extend @").append(ClientEndpoint.class.getName());
            err.append(" or extend from ").append(Endpoint.class.getName());
            throw new InvalidWebSocketException(err.toString());
        }
        endpointClientMetadataCache.put(endpoint, metadata);
        return metadata;
    }
}
Also used : SimpleEndpointMetadata(org.eclipse.jetty.websocket.jsr356.client.SimpleEndpointMetadata) InvalidWebSocketException(org.eclipse.jetty.websocket.api.InvalidWebSocketException) Endpoint(javax.websocket.Endpoint) ClientEndpoint(javax.websocket.ClientEndpoint) AnnotatedEndpointScanner(org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner) EmptyClientEndpointConfig(org.eclipse.jetty.websocket.jsr356.client.EmptyClientEndpointConfig) ClientEndpointConfig(javax.websocket.ClientEndpointConfig) ClientEndpoint(javax.websocket.ClientEndpoint) AnnotatedClientEndpointMetadata(org.eclipse.jetty.websocket.jsr356.client.AnnotatedClientEndpointMetadata) SimpleEndpointMetadata(org.eclipse.jetty.websocket.jsr356.client.SimpleEndpointMetadata) AnnotatedClientEndpointMetadata(org.eclipse.jetty.websocket.jsr356.client.AnnotatedClientEndpointMetadata) EndpointMetadata(org.eclipse.jetty.websocket.jsr356.metadata.EndpointMetadata)

Example 2 with EndpointMetadata

use of org.eclipse.jetty.websocket.jsr356.metadata.EndpointMetadata in project jetty.project by eclipse.

the class ClientContainer method newClientEndpointInstance.

public EndpointInstance newClientEndpointInstance(Object endpoint, ClientEndpointConfig config) {
    EndpointMetadata metadata = getClientEndpointMetadata(endpoint.getClass(), config);
    ClientEndpointConfig cec = config;
    if (config == null) {
        if (metadata instanceof AnnotatedClientEndpointMetadata) {
            cec = ((AnnotatedClientEndpointMetadata) metadata).getConfig();
        } else {
            cec = new EmptyClientEndpointConfig();
        }
    }
    return new EndpointInstance(endpoint, cec, metadata);
}
Also used : EmptyClientEndpointConfig(org.eclipse.jetty.websocket.jsr356.client.EmptyClientEndpointConfig) EndpointInstance(org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance) EmptyClientEndpointConfig(org.eclipse.jetty.websocket.jsr356.client.EmptyClientEndpointConfig) ClientEndpointConfig(javax.websocket.ClientEndpointConfig) AnnotatedClientEndpointMetadata(org.eclipse.jetty.websocket.jsr356.client.AnnotatedClientEndpointMetadata) SimpleEndpointMetadata(org.eclipse.jetty.websocket.jsr356.client.SimpleEndpointMetadata) AnnotatedClientEndpointMetadata(org.eclipse.jetty.websocket.jsr356.client.AnnotatedClientEndpointMetadata) EndpointMetadata(org.eclipse.jetty.websocket.jsr356.metadata.EndpointMetadata)

Example 3 with EndpointMetadata

use of org.eclipse.jetty.websocket.jsr356.metadata.EndpointMetadata in project jetty.project by eclipse.

the class ServerContainer method newClientEndpointInstance.

public EndpointInstance newClientEndpointInstance(Object endpoint, ServerEndpointConfig config, String path) {
    EndpointMetadata metadata = getClientEndpointMetadata(endpoint.getClass(), config);
    ServerEndpointConfig cec = config;
    if (config == null) {
        if (metadata instanceof AnnotatedServerEndpointMetadata) {
            cec = ((AnnotatedServerEndpointMetadata) metadata).getConfig();
        } else {
            cec = new BasicServerEndpointConfig(this, endpoint.getClass(), path);
        }
    }
    return new EndpointInstance(endpoint, cec, metadata);
}
Also used : ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) EndpointInstance(org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance) EndpointMetadata(org.eclipse.jetty.websocket.jsr356.metadata.EndpointMetadata)

Aggregations

EndpointMetadata (org.eclipse.jetty.websocket.jsr356.metadata.EndpointMetadata)3 ClientEndpointConfig (javax.websocket.ClientEndpointConfig)2 AnnotatedClientEndpointMetadata (org.eclipse.jetty.websocket.jsr356.client.AnnotatedClientEndpointMetadata)2 EmptyClientEndpointConfig (org.eclipse.jetty.websocket.jsr356.client.EmptyClientEndpointConfig)2 SimpleEndpointMetadata (org.eclipse.jetty.websocket.jsr356.client.SimpleEndpointMetadata)2 EndpointInstance (org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance)2 ClientEndpoint (javax.websocket.ClientEndpoint)1 Endpoint (javax.websocket.Endpoint)1 ServerEndpointConfig (javax.websocket.server.ServerEndpointConfig)1 InvalidWebSocketException (org.eclipse.jetty.websocket.api.InvalidWebSocketException)1 AnnotatedEndpointScanner (org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner)1