Search in sources :

Example 1 with SimpleEndpointMetadata

use of org.eclipse.jetty.websocket.jsr356.client.SimpleEndpointMetadata 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 SimpleEndpointMetadata

use of org.eclipse.jetty.websocket.jsr356.client.SimpleEndpointMetadata in project jetty.project by eclipse.

the class JsrSessionTest method initSession.

@Before
public void initSession() {
    container = new ClientContainer();
    String id = JsrSessionTest.class.getSimpleName();
    URI requestURI = URI.create("ws://localhost/" + id);
    WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
    ClientEndpointConfig config = new EmptyClientEndpointConfig();
    DummyEndpoint websocket = new DummyEndpoint();
    SimpleEndpointMetadata metadata = new SimpleEndpointMetadata(websocket.getClass());
    // Executor executor = null;
    EndpointInstance ei = new EndpointInstance(websocket, config, metadata);
    EventDriver driver = new JsrEndpointEventDriver(policy, ei);
    DummyConnection connection = new DummyConnection();
    session = new JsrSession(container, id, requestURI, driver, connection);
}
Also used : WebSocketPolicy(org.eclipse.jetty.websocket.api.WebSocketPolicy) DummyEndpoint(org.eclipse.jetty.websocket.jsr356.samples.DummyEndpoint) SimpleEndpointMetadata(org.eclipse.jetty.websocket.jsr356.client.SimpleEndpointMetadata) DummyConnection(org.eclipse.jetty.websocket.common.test.DummyConnection) EndpointInstance(org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance) URI(java.net.URI) EmptyClientEndpointConfig(org.eclipse.jetty.websocket.jsr356.client.EmptyClientEndpointConfig) EventDriver(org.eclipse.jetty.websocket.common.events.EventDriver) JsrEndpointEventDriver(org.eclipse.jetty.websocket.jsr356.endpoints.JsrEndpointEventDriver) JsrEndpointEventDriver(org.eclipse.jetty.websocket.jsr356.endpoints.JsrEndpointEventDriver) EmptyClientEndpointConfig(org.eclipse.jetty.websocket.jsr356.client.EmptyClientEndpointConfig) ClientEndpointConfig(javax.websocket.ClientEndpointConfig) Before(org.junit.Before)

Aggregations

ClientEndpointConfig (javax.websocket.ClientEndpointConfig)2 EmptyClientEndpointConfig (org.eclipse.jetty.websocket.jsr356.client.EmptyClientEndpointConfig)2 SimpleEndpointMetadata (org.eclipse.jetty.websocket.jsr356.client.SimpleEndpointMetadata)2 URI (java.net.URI)1 ClientEndpoint (javax.websocket.ClientEndpoint)1 Endpoint (javax.websocket.Endpoint)1 InvalidWebSocketException (org.eclipse.jetty.websocket.api.InvalidWebSocketException)1 WebSocketPolicy (org.eclipse.jetty.websocket.api.WebSocketPolicy)1 EventDriver (org.eclipse.jetty.websocket.common.events.EventDriver)1 DummyConnection (org.eclipse.jetty.websocket.common.test.DummyConnection)1 AnnotatedEndpointScanner (org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner)1 AnnotatedClientEndpointMetadata (org.eclipse.jetty.websocket.jsr356.client.AnnotatedClientEndpointMetadata)1 EndpointInstance (org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance)1 JsrEndpointEventDriver (org.eclipse.jetty.websocket.jsr356.endpoints.JsrEndpointEventDriver)1 EndpointMetadata (org.eclipse.jetty.websocket.jsr356.metadata.EndpointMetadata)1 DummyEndpoint (org.eclipse.jetty.websocket.jsr356.samples.DummyEndpoint)1 Before (org.junit.Before)1