Search in sources :

Example 1 with AnnotatedEndpointScanner

use of org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner in project jetty.project by eclipse.

the class ServerAnnotatedEndpointScanner_InvalidSignaturesTest method testScan_InvalidSignature.

@Test
public void testScan_InvalidSignature() throws DeploymentException {
    WebSocketContainerScope container = new SimpleContainerScope(WebSocketPolicy.newClientPolicy());
    AnnotatedServerEndpointMetadata metadata = new AnnotatedServerEndpointMetadata(container, pojo, null);
    AnnotatedEndpointScanner<ServerEndpoint, ServerEndpointConfig> scanner = new AnnotatedEndpointScanner<>(metadata);
    try {
        scanner.scan();
        Assert.fail("Expected " + InvalidSignatureException.class + " with message that references " + expectedAnnoClass + " annotation");
    } catch (InvalidSignatureException e) {
        if (LOG.isDebugEnabled())
            LOG.debug("{}:{}", e.getClass(), e.getMessage());
        Assert.assertThat("Message", e.getMessage(), containsString(expectedAnnoClass.getSimpleName()));
    }
}
Also used : InvalidSignatureException(org.eclipse.jetty.websocket.common.events.annotated.InvalidSignatureException) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) WebSocketContainerScope(org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope) AnnotatedEndpointScanner(org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner) SimpleContainerScope(org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope) ServerEndpoint(javax.websocket.server.ServerEndpoint) Test(org.junit.Test)

Example 2 with AnnotatedEndpointScanner

use of org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner in project jetty.project by eclipse.

the class OnCloseTest method testOnCloseCall.

@Test
public void testOnCloseCall() throws Exception {
    // Scan annotations
    AnnotatedClientEndpointMetadata metadata = new AnnotatedClientEndpointMetadata(container, testcase.closeClass);
    AnnotatedEndpointScanner<ClientEndpoint, ClientEndpointConfig> scanner = new AnnotatedEndpointScanner<>(metadata);
    scanner.scan();
    // Build up EventDriver
    WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
    ClientEndpointConfig config = metadata.getConfig();
    TrackingSocket endpoint = (TrackingSocket) testcase.closeClass.newInstance();
    EndpointInstance ei = new EndpointInstance(endpoint, config, metadata);
    JsrEvents<ClientEndpoint, ClientEndpointConfig> jsrevents = new JsrEvents<>(metadata);
    EventDriver driver = new JsrAnnotatedEventDriver(policy, ei, jsrevents);
    // Execute onClose call
    driver.onClose(new CloseInfo(StatusCode.NORMAL, "normal"));
    // Test captured event
    EventQueue<String> events = endpoint.eventQueue;
    Assert.assertThat("Number of Events Captured", events.size(), is(1));
    String closeEvent = events.poll();
    Assert.assertThat("Close Event", closeEvent, is(testcase.expectedCloseEvent));
}
Also used : WebSocketPolicy(org.eclipse.jetty.websocket.api.WebSocketPolicy) JsrEvents(org.eclipse.jetty.websocket.jsr356.annotations.JsrEvents) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) EventDriver(org.eclipse.jetty.websocket.common.events.EventDriver) AnnotatedEndpointScanner(org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner) ClientEndpointConfig(javax.websocket.ClientEndpointConfig) ClientEndpoint(javax.websocket.ClientEndpoint) AnnotatedClientEndpointMetadata(org.eclipse.jetty.websocket.jsr356.client.AnnotatedClientEndpointMetadata) Test(org.junit.Test)

Example 3 with AnnotatedEndpointScanner

use of org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner in project jetty.project by eclipse.

the class ClientAnnotatedEndpointScanner_InvalidSignaturesTest method testScan_InvalidSignature.

@Test
public void testScan_InvalidSignature() throws DeploymentException {
    AnnotatedClientEndpointMetadata metadata = new AnnotatedClientEndpointMetadata(container, pojo);
    AnnotatedEndpointScanner<ClientEndpoint, ClientEndpointConfig> scanner = new AnnotatedEndpointScanner<>(metadata);
    try {
        scanner.scan();
        Assert.fail("Expected " + InvalidSignatureException.class + " with message that references " + expectedAnnoClass + " annotation");
    } catch (InvalidSignatureException e) {
        if (LOG.isDebugEnabled())
            LOG.debug("{}:{}", e.getClass(), e.getMessage());
        Assert.assertThat("Message", e.getMessage(), containsString(expectedAnnoClass.getSimpleName()));
    }
}
Also used : InvalidSignatureException(org.eclipse.jetty.websocket.common.events.annotated.InvalidSignatureException) AnnotatedEndpointScanner(org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner) ClientEndpointConfig(javax.websocket.ClientEndpointConfig) ClientEndpoint(javax.websocket.ClientEndpoint) AnnotatedClientEndpointMetadata(org.eclipse.jetty.websocket.jsr356.client.AnnotatedClientEndpointMetadata) Test(org.junit.Test)

Example 4 with AnnotatedEndpointScanner

use of org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner 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 5 with AnnotatedEndpointScanner

use of org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner in project jetty.project by eclipse.

the class ServerContainer method getServerEndpointMetadata.

public ServerEndpointMetadata getServerEndpointMetadata(final Class<?> endpoint, final ServerEndpointConfig config) throws DeploymentException {
    ServerEndpointMetadata metadata = null;
    ServerEndpoint anno = endpoint.getAnnotation(ServerEndpoint.class);
    if (anno != null) {
        // Annotated takes precedence here
        AnnotatedServerEndpointMetadata ametadata = new AnnotatedServerEndpointMetadata(this, endpoint, config);
        AnnotatedEndpointScanner<ServerEndpoint, ServerEndpointConfig> scanner = new AnnotatedEndpointScanner<>(ametadata);
        metadata = ametadata;
        scanner.scan();
    } else if (Endpoint.class.isAssignableFrom(endpoint)) {
        // extends Endpoint
        @SuppressWarnings("unchecked") Class<? extends Endpoint> eendpoint = (Class<? extends Endpoint>) endpoint;
        metadata = new SimpleServerEndpointMetadata(eendpoint, config);
    } else {
        StringBuilder err = new StringBuilder();
        err.append("Not a recognized websocket [");
        err.append(endpoint.getName());
        err.append("] does not extend @").append(ServerEndpoint.class.getName());
        err.append(" or extend from ").append(Endpoint.class.getName());
        throw new DeploymentException("Unable to identify as valid Endpoint: " + endpoint);
    }
    return metadata;
}
Also used : ServerEndpoint(javax.websocket.server.ServerEndpoint) Endpoint(javax.websocket.Endpoint) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) AnnotatedEndpointScanner(org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner) DeploymentException(javax.websocket.DeploymentException) ServerEndpoint(javax.websocket.server.ServerEndpoint)

Aggregations

AnnotatedEndpointScanner (org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner)8 Test (org.junit.Test)5 ClientEndpoint (javax.websocket.ClientEndpoint)4 ClientEndpointConfig (javax.websocket.ClientEndpointConfig)4 ServerEndpoint (javax.websocket.server.ServerEndpoint)4 ServerEndpointConfig (javax.websocket.server.ServerEndpointConfig)4 AnnotatedClientEndpointMetadata (org.eclipse.jetty.websocket.jsr356.client.AnnotatedClientEndpointMetadata)4 SimpleContainerScope (org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope)3 WebSocketContainerScope (org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope)3 Endpoint (javax.websocket.Endpoint)2 WebSocketPolicy (org.eclipse.jetty.websocket.api.WebSocketPolicy)2 EventDriver (org.eclipse.jetty.websocket.common.events.EventDriver)2 InvalidSignatureException (org.eclipse.jetty.websocket.common.events.annotated.InvalidSignatureException)2 JsrCallable (org.eclipse.jetty.websocket.jsr356.annotations.JsrCallable)2 URI (java.net.URI)1 DeploymentException (javax.websocket.DeploymentException)1 InvalidWebSocketException (org.eclipse.jetty.websocket.api.InvalidWebSocketException)1 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)1 EventDriverFactory (org.eclipse.jetty.websocket.common.events.EventDriverFactory)1 EventDriverImpl (org.eclipse.jetty.websocket.common.events.EventDriverImpl)1