Search in sources :

Example 1 with EndpointInstance

use of org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance 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 2 with EndpointInstance

use of org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance in project jetty.project by eclipse.

the class JsrServerEndpointImpl method create.

@Override
public EventDriver create(Object websocket, WebSocketPolicy policy) throws Throwable {
    if (!(websocket instanceof EndpointInstance)) {
        throw new IllegalStateException(String.format("Websocket %s must be an %s", websocket.getClass().getName(), EndpointInstance.class.getName()));
    }
    EndpointInstance ei = (EndpointInstance) websocket;
    AnnotatedServerEndpointMetadata metadata = (AnnotatedServerEndpointMetadata) ei.getMetadata();
    JsrEvents<ServerEndpoint, ServerEndpointConfig> events = new JsrEvents<>(metadata);
    // Handle @OnMessage maxMessageSizes
    int maxBinaryMessage = getMaxMessageSize(policy.getMaxBinaryMessageSize(), metadata.onBinary, metadata.onBinaryStream);
    int maxTextMessage = getMaxMessageSize(policy.getMaxTextMessageSize(), metadata.onText, metadata.onTextStream);
    policy.setMaxBinaryMessageSize(maxBinaryMessage);
    policy.setMaxTextMessageSize(maxTextMessage);
    JsrAnnotatedEventDriver driver = new JsrAnnotatedEventDriver(policy, ei, events);
    // Handle @PathParam values
    ServerEndpointConfig config = (ServerEndpointConfig) ei.getConfig();
    if (config instanceof PathParamServerEndpointConfig) {
        PathParamServerEndpointConfig ppconfig = (PathParamServerEndpointConfig) config;
        driver.setPathParameters(ppconfig.getPathParamMap());
    }
    return driver;
}
Also used : JsrEvents(org.eclipse.jetty.websocket.jsr356.annotations.JsrEvents) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) EndpointInstance(org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance) ServerEndpoint(javax.websocket.server.ServerEndpoint) JsrAnnotatedEventDriver(org.eclipse.jetty.websocket.jsr356.endpoints.JsrAnnotatedEventDriver) ServerEndpoint(javax.websocket.server.ServerEndpoint)

Example 3 with EndpointInstance

use of org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance in project jetty.project by eclipse.

the class JsrServerExtendsEndpointImpl method create.

@Override
public EventDriver create(Object websocket, WebSocketPolicy policy) {
    if (!(websocket instanceof EndpointInstance)) {
        throw new IllegalStateException(String.format("Websocket %s must be an %s", websocket.getClass().getName(), EndpointInstance.class.getName()));
    }
    EndpointInstance ei = (EndpointInstance) websocket;
    JsrEndpointEventDriver driver = new JsrEndpointEventDriver(policy, ei);
    ServerEndpointConfig config = (ServerEndpointConfig) ei.getConfig();
    if (config instanceof PathParamServerEndpointConfig) {
        PathParamServerEndpointConfig ppconfig = (PathParamServerEndpointConfig) config;
        driver.setPathParameters(ppconfig.getPathParamMap());
    }
    return driver;
}
Also used : JsrEndpointEventDriver(org.eclipse.jetty.websocket.jsr356.endpoints.JsrEndpointEventDriver) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) EndpointInstance(org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance)

Example 4 with EndpointInstance

use of org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance in project jetty.project by eclipse.

the class JsrClientEndpointImpl method create.

@Override
public EventDriver create(Object websocket, WebSocketPolicy policy) throws DeploymentException {
    if (!(websocket instanceof EndpointInstance)) {
        throw new IllegalStateException(String.format("Websocket %s must be an %s", websocket.getClass().getName(), EndpointInstance.class.getName()));
    }
    EndpointInstance ei = (EndpointInstance) websocket;
    AnnotatedClientEndpointMetadata metadata = (AnnotatedClientEndpointMetadata) ei.getMetadata();
    JsrEvents<ClientEndpoint, ClientEndpointConfig> events = new JsrEvents<>(metadata);
    // Handle @OnMessage maxMessageSizes
    int maxBinaryMessage = getMaxMessageSize(policy.getMaxBinaryMessageSize(), metadata.maxBinaryMessageSize());
    int maxTextMessage = getMaxMessageSize(policy.getMaxTextMessageSize(), metadata.maxTextMessageSize());
    policy.setMaxBinaryMessageSize(maxBinaryMessage);
    policy.setMaxTextMessageSize(maxTextMessage);
    return new JsrAnnotatedEventDriver(policy, ei, events);
}
Also used : JsrEvents(org.eclipse.jetty.websocket.jsr356.annotations.JsrEvents) EndpointInstance(org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance) ClientEndpointConfig(javax.websocket.ClientEndpointConfig) ClientEndpoint(javax.websocket.ClientEndpoint) JsrAnnotatedEventDriver(org.eclipse.jetty.websocket.jsr356.endpoints.JsrAnnotatedEventDriver) ClientEndpoint(javax.websocket.ClientEndpoint)

Example 5 with EndpointInstance

use of org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance in project jetty.project by eclipse.

the class JsrClientEndpointImpl method supports.

@Override
public boolean supports(Object websocket) {
    if (!(websocket instanceof EndpointInstance)) {
        return false;
    }
    EndpointInstance ei = (EndpointInstance) websocket;
    Object endpoint = ei.getEndpoint();
    ClientEndpoint anno = endpoint.getClass().getAnnotation(ClientEndpoint.class);
    return (anno != null);
}
Also used : EndpointInstance(org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance) ClientEndpoint(javax.websocket.ClientEndpoint)

Aggregations

EndpointInstance (org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance)11 ClientEndpointConfig (javax.websocket.ClientEndpointConfig)5 ServerEndpointConfig (javax.websocket.server.ServerEndpointConfig)5 ClientEndpoint (javax.websocket.ClientEndpoint)3 ServerEndpoint (javax.websocket.server.ServerEndpoint)3 WebSocketPolicy (org.eclipse.jetty.websocket.api.WebSocketPolicy)3 EventDriver (org.eclipse.jetty.websocket.common.events.EventDriver)3 JsrEvents (org.eclipse.jetty.websocket.jsr356.annotations.JsrEvents)3 EmptyClientEndpointConfig (org.eclipse.jetty.websocket.jsr356.client.EmptyClientEndpointConfig)3 IOException (java.io.IOException)2 URI (java.net.URI)2 Extension (javax.websocket.Extension)2 DummyConnection (org.eclipse.jetty.websocket.common.test.DummyConnection)2 AnnotatedEndpointScanner (org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner)2 AnnotatedClientEndpointMetadata (org.eclipse.jetty.websocket.jsr356.client.AnnotatedClientEndpointMetadata)2 SimpleEndpointMetadata (org.eclipse.jetty.websocket.jsr356.client.SimpleEndpointMetadata)2 JsrAnnotatedEventDriver (org.eclipse.jetty.websocket.jsr356.endpoints.JsrAnnotatedEventDriver)2 JsrEndpointEventDriver (org.eclipse.jetty.websocket.jsr356.endpoints.JsrEndpointEventDriver)2 EndpointMetadata (org.eclipse.jetty.websocket.jsr356.metadata.EndpointMetadata)2 ArrayList (java.util.ArrayList)1