use of javax.websocket.server.ServerEndpointConfig 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 javax.websocket.server.ServerEndpointConfig in project jetty.project by eclipse.
the class JsrServerExtendsEndpointImpl method create.
@Override
public EventDriver create(Object websocket, WebSocketPolicy policy) {
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;
JsrEndpointEventDriver driver = new JsrEndpointEventDriver(policy, ei);
ServerEndpointConfig config = (ServerEndpointConfig) ei.getConfig();
if (config instanceof PathParamServerEndpointConfig) {
PathParamServerEndpointConfig ppconfig = (PathParamServerEndpointConfig) config;
driver.setPathParameters(ppconfig.getPathParamMap());
}
return driver;
}
use of javax.websocket.server.ServerEndpointConfig in project tomcat by apache.
the class WsServerContainer method addEndpoint.
/**
* Provides the equivalent of {@link #addEndpoint(ServerEndpointConfig)}
* for publishing plain old java objects (POJOs) that have been annotated as
* WebSocket endpoints.
*
* @param pojo The annotated POJO
*/
@Override
public void addEndpoint(Class<?> pojo) throws DeploymentException {
ServerEndpoint annotation = pojo.getAnnotation(ServerEndpoint.class);
if (annotation == null) {
throw new DeploymentException(sm.getString("serverContainer.missingAnnotation", pojo.getName()));
}
String path = annotation.value();
// Validate encoders
validateEncoders(annotation.encoders());
// ServerEndpointConfig
ServerEndpointConfig sec;
Class<? extends Configurator> configuratorClazz = annotation.configurator();
Configurator configurator = null;
if (!configuratorClazz.equals(Configurator.class)) {
try {
configurator = annotation.configurator().newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new DeploymentException(sm.getString("serverContainer.configuratorFail", annotation.configurator().getName(), pojo.getClass().getName()), e);
}
}
sec = ServerEndpointConfig.Builder.create(pojo, path).decoders(Arrays.asList(annotation.decoders())).encoders(Arrays.asList(annotation.encoders())).subprotocols(Arrays.asList(annotation.subprotocols())).configurator(configurator).build();
addEndpoint(sec);
}
use of javax.websocket.server.ServerEndpointConfig in project tomcat by apache.
the class TestWsServerContainer method testDuplicatePaths_02.
@Test(expected = javax.websocket.DeploymentException.class)
public void testDuplicatePaths_02() throws Exception {
WsServerContainer sc = new WsServerContainer(new TesterServletContext());
ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(Object.class, "/a/b/{var}").build();
ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(Object.class, "/a/b/{var}").build();
sc.addEndpoint(configA);
sc.addEndpoint(configB);
}
use of javax.websocket.server.ServerEndpointConfig in project tomcat by apache.
the class TestWsServerContainer method testDuplicatePaths_03.
@Test(expected = javax.websocket.DeploymentException.class)
public void testDuplicatePaths_03() throws Exception {
WsServerContainer sc = new WsServerContainer(new TesterServletContext());
ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(Object.class, "/a/b/{var1}").build();
ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(Object.class, "/a/b/{var2}").build();
sc.addEndpoint(configA);
sc.addEndpoint(configB);
}
Aggregations