Search in sources :

Example 6 with AnnotatedEndpointScanner

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

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

the class ServerAnnotatedEndpointScanner_GoodSignaturesTest method testScan_Basic.

@Test
public void testScan_Basic() throws Exception {
    WebSocketContainerScope container = new SimpleContainerScope(WebSocketPolicy.newClientPolicy());
    AnnotatedServerEndpointMetadata metadata = new AnnotatedServerEndpointMetadata(container, testcase.pojo, null);
    AnnotatedEndpointScanner<ServerEndpoint, ServerEndpointConfig> scanner = new AnnotatedEndpointScanner<>(metadata);
    scanner.scan();
    Assert.assertThat("Metadata", metadata, notNullValue());
    JsrCallable method = (JsrCallable) testcase.metadataField.get(metadata);
    Assert.assertThat(testcase.metadataField.toString(), method, notNullValue());
    int len = testcase.expectedParameters.length;
    for (int i = 0; i < len; i++) {
        Class<?> expectedParam = testcase.expectedParameters[i];
        Class<?> actualParam = method.getParamTypes()[i];
        Assert.assertTrue("Parameter[" + i + "] - expected:[" + expectedParam + "], actual:[" + actualParam + "]", actualParam.equals(expectedParam));
    }
}
Also used : ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) WebSocketContainerScope(org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope) JsrCallable(org.eclipse.jetty.websocket.jsr356.annotations.JsrCallable) AnnotatedEndpointScanner(org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner) SimpleContainerScope(org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope) ServerEndpoint(javax.websocket.server.ServerEndpoint) ServerEndpoint(javax.websocket.server.ServerEndpoint) Test(org.junit.Test)

Example 8 with AnnotatedEndpointScanner

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

the class ClientAnnotatedEndpointScanner_GoodSignaturesTest method testScan_Basic.

@Test
public void testScan_Basic() throws Exception {
    AnnotatedClientEndpointMetadata metadata = new AnnotatedClientEndpointMetadata(container, testcase.pojo);
    AnnotatedEndpointScanner<ClientEndpoint, ClientEndpointConfig> scanner = new AnnotatedEndpointScanner<>(metadata);
    scanner.scan();
    Assert.assertThat("Metadata", metadata, notNullValue());
    JsrCallable cm = (JsrCallable) testcase.metadataField.get(metadata);
    Assert.assertThat(testcase.metadataField.toString(), cm, notNullValue());
    int len = testcase.expectedParameters.length;
    for (int i = 0; i < len; i++) {
        Class<?> expectedParam = testcase.expectedParameters[i];
        Class<?> actualParam = cm.getParamTypes()[i];
        Assert.assertTrue("Parameter[" + i + "] - expected:[" + expectedParam + "], actual:[" + actualParam + "]", actualParam.equals(expectedParam));
    }
}
Also used : JsrCallable(org.eclipse.jetty.websocket.jsr356.annotations.JsrCallable) AnnotatedEndpointScanner(org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner) ClientEndpointConfig(javax.websocket.ClientEndpointConfig) ClientEndpoint(javax.websocket.ClientEndpoint) AnnotatedClientEndpointMetadata(org.eclipse.jetty.websocket.jsr356.client.AnnotatedClientEndpointMetadata) ClientEndpoint(javax.websocket.ClientEndpoint) Test(org.junit.Test)

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