use of org.eclipse.jetty.websocket.jsr356.client.AnnotatedClientEndpointMetadata 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.client.AnnotatedClientEndpointMetadata in project jetty.project by eclipse.
the class ClientAnnotatedEndpointScanner_InvalidSignaturesTest method testScan_InvalidSignature.
@Test
public void testScan_InvalidSignature() throws DeploymentException {
AnnotatedClientEndpointMetadata metadata = new AnnotatedClientEndpointMetadata(container, pojo);
AnnotatedEndpointScanner<ClientEndpoint, ClientEndpointConfig> scanner = new AnnotatedEndpointScanner<>(metadata);
try {
scanner.scan();
Assert.fail("Expected " + InvalidSignatureException.class + " with message that references " + expectedAnnoClass + " annotation");
} catch (InvalidSignatureException e) {
if (LOG.isDebugEnabled())
LOG.debug("{}:{}", e.getClass(), e.getMessage());
Assert.assertThat("Message", e.getMessage(), containsString(expectedAnnoClass.getSimpleName()));
}
}
use of org.eclipse.jetty.websocket.jsr356.client.AnnotatedClientEndpointMetadata 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);
}
use of org.eclipse.jetty.websocket.jsr356.client.AnnotatedClientEndpointMetadata in project jetty.project by eclipse.
the class ClientContainer method getClientEndpointMetadata.
public EndpointMetadata getClientEndpointMetadata(Class<?> endpoint, EndpointConfig config) {
synchronized (endpointClientMetadataCache) {
EndpointMetadata metadata = endpointClientMetadataCache.get(endpoint);
if (metadata != null) {
return metadata;
}
ClientEndpoint anno = endpoint.getAnnotation(ClientEndpoint.class);
if (anno != null) {
// Annotated takes precedence here
AnnotatedClientEndpointMetadata annoMetadata = new AnnotatedClientEndpointMetadata(this, endpoint);
AnnotatedEndpointScanner<ClientEndpoint, ClientEndpointConfig> scanner = new AnnotatedEndpointScanner<>(annoMetadata);
scanner.scan();
metadata = annoMetadata;
} else if (Endpoint.class.isAssignableFrom(endpoint)) {
// extends Endpoint
@SuppressWarnings("unchecked") Class<? extends Endpoint> eendpoint = (Class<? extends Endpoint>) endpoint;
metadata = new SimpleEndpointMetadata(eendpoint, config);
} else {
StringBuilder err = new StringBuilder();
err.append("Not a recognized websocket [");
err.append(endpoint.getName());
err.append("] does not extend @").append(ClientEndpoint.class.getName());
err.append(" or extend from ").append(Endpoint.class.getName());
throw new InvalidWebSocketException(err.toString());
}
endpointClientMetadataCache.put(endpoint, metadata);
return metadata;
}
}
use of org.eclipse.jetty.websocket.jsr356.client.AnnotatedClientEndpointMetadata in project jetty.project by eclipse.
the class ClientContainer method newClientEndpointInstance.
public EndpointInstance newClientEndpointInstance(Object endpoint, ClientEndpointConfig config) {
EndpointMetadata metadata = getClientEndpointMetadata(endpoint.getClass(), config);
ClientEndpointConfig cec = config;
if (config == null) {
if (metadata instanceof AnnotatedClientEndpointMetadata) {
cec = ((AnnotatedClientEndpointMetadata) metadata).getConfig();
} else {
cec = new EmptyClientEndpointConfig();
}
}
return new EndpointInstance(endpoint, cec, metadata);
}
Aggregations