use of javax.websocket.server.ServerEndpointConfig in project tomcat70 by apache.
the class TestWsServerContainer method testDuplicatePaths_01.
@Test(expected = javax.websocket.DeploymentException.class)
public void testDuplicatePaths_01() throws Exception {
WsServerContainer sc = new WsServerContainer(new TesterServletContext());
ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(Object.class, "/a/b/c").build();
ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(Object.class, "/a/b/c").build();
sc.addEndpoint(configA);
sc.addEndpoint(configB);
}
use of javax.websocket.server.ServerEndpointConfig in project tomcat70 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 AngularBeans by bessemHmidi.
the class SockJsServlet method configuratorFor.
private ServerEndpointConfig.Configurator configuratorFor(final String prefix, final boolean isRaw) {
return new ServerEndpointConfig.Configurator() {
@Override
public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
try {
return endpointClass.getConstructor(SockJsServer.class, String.class, String.class).newInstance(sockJsServer, getServletContext().getContextPath(), prefix);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
if (isRaw) {
// headers with for raw websocket requests
return;
}
String path = request.getRequestURI().getPath();
Matcher matcher = SESSION_PATTERN.matcher(path);
if (matcher.matches()) {
String sessionId = matcher.group(1);
saveHeaders(sessionId, request.getHeaders());
}
}
};
}
use of javax.websocket.server.ServerEndpointConfig in project AngularBeans by bessemHmidi.
the class AngularBeansServletContextListener method initJSR356.
public void initJSR356() throws ServletException {
sockJsServer = new SockJsServer();
sockJsServer.init();
if (sockJsServer.options.websocket) {
// Make sure we listen on all possible mappings of the servlet
// for (String mapping :
// getServletContext().getServletRegistration(context.getServletName()).getMappings())
// {
final String commonPrefix = extractPrefixFromMapping("/rt-service/*");
//
String websocketPath = commonPrefix + "/{server}/{session}/websocket";
ServerEndpointConfig sockJsConfig = ServerEndpointConfig.Builder.create(SockJsEndpoint.class, websocketPath).configurator(configuratorFor(commonPrefix, false)).build();
// rt-service/websocket
String rawWebsocketPath = commonPrefix + "/websocket";
ServerEndpointConfig rawWsConfig = ServerEndpointConfig.Builder.create(RawWebsocketEndpoint.class, rawWebsocketPath).configurator(configuratorFor(commonPrefix, true)).build();
ServerContainer serverContainer = (ServerContainer) context.getAttribute("javax.websocket.server.ServerContainer");
try {
serverContainer.addEndpoint(sockJsConfig);
serverContainer.addEndpoint(rawWsConfig);
Logger.getLogger(this.getClass().getSimpleName()).info("deployement of programmatic Web socket EndPoint :" + rawWebsocketPath);
} catch (DeploymentException ex) {
throw new ServletException("Error deploying websocket endpoint:", ex);
}
}
}
use of javax.websocket.server.ServerEndpointConfig in project AngularBeans by bessemHmidi.
the class AngularBeansServletContextListener method configuratorFor.
private ServerEndpointConfig.Configurator configuratorFor(final String prefix, final boolean isRaw) {
return new ServerEndpointConfig.Configurator() {
@Override
public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
try {
return endpointClass.getConstructor(SockJsServer.class, String.class, String.class).newInstance(sockJsServer, context.getContextPath(), prefix);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
if (isRaw) {
// headers with for raw websocket requests
return;
}
String path = request.getRequestURI().getPath();
Matcher matcher = SESSION_PATTERN.matcher(path);
if (matcher.matches()) {
String sessionId = matcher.group(1);
saveHeaders(sessionId, request.getHeaders());
}
}
};
}
Aggregations