Search in sources :

Example 11 with EndpointInstance

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

the class JsrServerEndpointImpl method supports.

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

Example 12 with EndpointInstance

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

the class OnPartialTest method toEventDriver.

public EventDriver toEventDriver(Object websocket) throws Throwable {
    WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
    policy.setInputBufferSize(1024);
    policy.setMaxBinaryMessageBufferSize(1024);
    policy.setMaxTextMessageBufferSize(1024);
    // Create EventDriver
    EventDriverImpl driverImpl = new JsrServerEndpointImpl();
    Class<?> endpoint = websocket.getClass();
    ServerEndpoint anno = endpoint.getAnnotation(ServerEndpoint.class);
    Assert.assertThat("Endpoint: " + endpoint + " should be annotated with @ServerEndpoint", anno, notNullValue());
    WebSocketContainerScope containerScope = new SimpleContainerScope(policy);
    // Event Driver Factory
    EventDriverFactory factory = new EventDriverFactory(containerScope);
    factory.addImplementation(new JsrServerEndpointImpl());
    ServerEndpointConfig config = new BasicServerEndpointConfig(containerScope, endpoint, "/");
    AnnotatedServerEndpointMetadata metadata = new AnnotatedServerEndpointMetadata(containerScope, endpoint, config);
    AnnotatedEndpointScanner<ServerEndpoint, ServerEndpointConfig> scanner = new AnnotatedEndpointScanner<>(metadata);
    scanner.scan();
    EndpointInstance ei = new EndpointInstance(websocket, config, metadata);
    EventDriver driver = driverImpl.create(ei, policy);
    Assert.assertThat("EventDriver", driver, notNullValue());
    // Create Local JsrSession
    String id = testname.getMethodName();
    URI requestURI = URI.create("ws://localhost/" + id);
    DummyConnection connection = new DummyConnection();
    ClientContainer container = new ClientContainer();
    container.start();
    @SuppressWarnings("resource") JsrSession session = new JsrSession(container, id, requestURI, driver, connection);
    session.setPolicy(policy);
    session.start();
    session.open();
    return driver;
}
Also used : WebSocketPolicy(org.eclipse.jetty.websocket.api.WebSocketPolicy) EventDriverFactory(org.eclipse.jetty.websocket.common.events.EventDriverFactory) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) WebSocketContainerScope(org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope) DummyConnection(org.eclipse.jetty.websocket.common.test.DummyConnection) ClientContainer(org.eclipse.jetty.websocket.jsr356.ClientContainer) EndpointInstance(org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance) JsrSession(org.eclipse.jetty.websocket.jsr356.JsrSession) ServerEndpoint(javax.websocket.server.ServerEndpoint) URI(java.net.URI) EventDriver(org.eclipse.jetty.websocket.common.events.EventDriver) AnnotatedEndpointScanner(org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner) SimpleContainerScope(org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope) EventDriverImpl(org.eclipse.jetty.websocket.common.events.EventDriverImpl)

Example 13 with EndpointInstance

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

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