use of javax.websocket.server.ServerContainer in project jetty.project by eclipse.
the class BasicEchoEndpointConfigContextListener method contextInitialized.
@Override
public void contextInitialized(ServletContextEvent sce) {
ServerContainer container = (ServerContainer) sce.getServletContext().getAttribute(ServerContainer.class.getName());
if (container == null)
throw new IllegalStateException("No Websocket ServerContainer in " + sce.getServletContext());
// Build up a configuration with a specific path
String path = "/echo";
ServerEndpointConfig.Builder builder = ServerEndpointConfig.Builder.create(BasicEchoEndpoint.class, path);
try {
container.addEndpoint(builder.build());
} catch (DeploymentException e) {
throw new RuntimeException("Unable to add endpoint via config file", e);
}
}
use of javax.websocket.server.ServerContainer in project jetty.project by eclipse.
the class BasicEchoEndpointContextListener method contextInitialized.
@Override
public void contextInitialized(ServletContextEvent sce) {
ServerContainer container = (ServerContainer) sce.getServletContext().getAttribute(ServerContainer.class.getName());
try {
container.addEndpoint(ServerEndpointConfig.Builder.create(PongMessageEndpoint.class, "/ping").build());
container.addEndpoint(ServerEndpointConfig.Builder.create(PongMessageEndpoint.class, "/pong").build());
} catch (DeploymentException e) {
throw new RuntimeException("Unable to add endpoint via config file", e);
}
}
use of javax.websocket.server.ServerContainer 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.ServerContainer in project undertow by undertow-io.
the class BinaryEndpointServlet method init.
@Override
public void init(ServletConfig c) throws ServletException {
String websocketPath = "/partial";
ServerEndpointConfig config = ServerEndpointConfig.Builder.create(BinaryPartialEndpoint.class, websocketPath).build();
ServerContainer serverContainer = (ServerContainer) c.getServletContext().getAttribute("javax.websocket.server.ServerContainer");
try {
serverContainer.addEndpoint(config);
} catch (DeploymentException ex) {
throw new ServletException("Error deploying websocket endpoint:", ex);
}
}
use of javax.websocket.server.ServerContainer in project quickstart by wildfly.
the class Frontend method init.
public void init(@Observes @Initialized(ApplicationScoped.class) ServletContext servletContext) {
if (servletContext == null) {
log.severe(format("Failed to deploy frontend endpoint %s: %s", WEBSOCKET_PATH, "ServletContext not available"));
return;
}
ServerContainer serverContainer = (ServerContainer) servletContext.getAttribute("javax.websocket.server.ServerContainer");
if (serverContainer == null) {
log.severe(format("Failed to deploy frontend endpoint %s: %s", WEBSOCKET_PATH, "javax.websocket.server.ServerContainer ServerContainer not available"));
return;
}
// WebSocket does not honor CDI contexts in the default configuration; by default a new object is created for each new
// websocket.
// We can work around this by supplying a custom ServerEndpointConfig.Configurator that returns the same instance of the
// endpoint for each new websocket. Unfortunately this precludes us from using annotations, and forces us to extend the
// abstract class Endpoint, and forces us to add the server endpoint programmatically upon startup of the servlet
// context.
ServerEndpointConfig config = ServerEndpointConfig.Builder.create(Frontend.class, WEBSOCKET_PATH).configurator(new ServerEndpointConfig.Configurator() {
@SuppressWarnings("unchecked")
@Override
public <T> T getEndpointInstance(final Class<T> endpointClass) throws InstantiationException {
if (endpointClass.isAssignableFrom(Frontend.class)) {
return (T) Frontend.this;
}
return super.getEndpointInstance(endpointClass);
}
}).build();
try {
serverContainer.addEndpoint(config);
} catch (DeploymentException e) {
log.log(Level.SEVERE, format("Failed to deploy frontend endpoint %s: %s", WEBSOCKET_PATH, e.getMessage()), e);
}
}
Aggregations