use of org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope 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;
}
use of org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope 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));
}
}
use of org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope in project jetty.project by eclipse.
the class MessageOutputStreamTest method setupSession.
@Before
public void setupSession() throws Exception {
policy = WebSocketPolicy.newServerPolicy();
policy.setInputBufferSize(1024);
policy.setMaxBinaryMessageBufferSize(1024);
// Container
WebSocketContainerScope containerScope = new SimpleContainerScope(policy, bufferPool);
// Event Driver factory
EventDriverFactory factory = new EventDriverFactory(containerScope);
// local socket
EventDriver driver = factory.wrap(new TrackingSocket("local"));
// remote socket
socket = new TrackingSocket("remote");
OutgoingFrames socketPipe = FramePipes.to(factory.wrap(socket));
session = new LocalWebSocketSession(containerScope, testname, driver);
session.setPolicy(policy);
// talk to our remote socket
session.setOutgoingHandler(socketPipe);
// start session
session.start();
// open connection
session.open();
}
use of org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope in project jetty.project by eclipse.
the class WebSocketCdiListener method lifeCycleStarting.
@Override
public void lifeCycleStarting(LifeCycle event) {
if (event instanceof WebSocketContainerScope) {
if (LOG.isDebugEnabled()) {
LOG.debug("started websocket container [{}]", event);
}
ContainerListener listener = new ContainerListener((WebSocketContainerScope) event);
if (event instanceof ContainerLifeCycle) {
ContainerLifeCycle container = (ContainerLifeCycle) event;
container.addLifeCycleListener(listener);
container.addEventListener(listener);
} else {
throw new RuntimeException("Unable to setup CDI against non-container: " + event.getClass().getName());
}
}
}
use of org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope in project jetty.project by eclipse.
the class ExtensionStackTest method createExtensionStack.
private ExtensionStack createExtensionStack() {
WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
WebSocketContainerScope container = new SimpleContainerScope(policy, bufferPool);
WebSocketExtensionFactory factory = new WebSocketExtensionFactory(container);
return new ExtensionStack(factory);
}
Aggregations