use of org.eclipse.jetty.websocket.jsr356.annotations.JsrEvents 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));
}
use of org.eclipse.jetty.websocket.jsr356.annotations.JsrEvents 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;
}
use of org.eclipse.jetty.websocket.jsr356.annotations.JsrEvents 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);
}
Aggregations