use of javax.websocket.server.ServerContainer in project jetty.project by eclipse.
the class BasicAppTest method startServer.
@BeforeClass
public static void startServer() throws Exception {
JettyLogHandler.config();
server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(0);
server.addConnector(connector);
EmbeddedCdiHandler context = new EmbeddedCdiHandler();
File baseDir = MavenTestingUtils.getTestResourcesDir();
context.setBaseResource(Resource.newResource(baseDir));
context.setContextPath("/");
server.setHandler(context);
// Add some websockets
ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
container.addEndpoint(EchoSocket.class);
container.addEndpoint(InfoSocket.class);
server.start();
String host = connector.getHost();
if (host == null) {
host = "localhost";
}
int port = connector.getLocalPort();
serverHttpURI = new URI(String.format("http://%s:%d/", host, port));
serverWebsocketURI = new URI(String.format("ws://%s:%d/", host, port));
}
use of javax.websocket.server.ServerContainer in project jetty.project by eclipse.
the class CdiAppTest method startServer.
@BeforeClass
public static void startServer() throws Exception {
JettyLogHandler.config();
server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(0);
server.addConnector(connector);
EmbeddedCdiHandler context = new EmbeddedCdiHandler();
WebSocketCdiInitializer.configureContext(context);
File baseDir = MavenTestingUtils.getTestResourcesDir();
context.setBaseResource(Resource.newResource(baseDir));
context.setContextPath("/");
server.setHandler(context);
// Add some websockets
ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
container.addEndpoint(EchoSocket.class);
container.addEndpoint(InfoSocket.class);
server.start();
String host = connector.getHost();
if (host == null) {
host = "localhost";
}
int port = connector.getLocalPort();
serverWebsocketURI = new URI(String.format("ws://%s:%d/", host, port));
}
use of javax.websocket.server.ServerContainer in project jetty.project by eclipse.
the class BasicEchoSocketConfigContextListener method contextInitialized.
@Override
public void contextInitialized(ServletContextEvent sce) {
ServerContainer container = (ServerContainer) sce.getServletContext().getAttribute(ServerContainer.class.getName());
// Build up a configuration with a specific path
// Intentionally using alternate path in config (which differs from @ServerEndpoint declaration)
String path = "/echo-alt";
ServerEndpointConfig.Builder builder = ServerEndpointConfig.Builder.create(BasicEchoSocket.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 LargeEchoContextListener method contextInitialized.
@Override
public void contextInitialized(ServletContextEvent sce) {
ServerContainer container = (ServerContainer) sce.getServletContext().getAttribute(ServerContainer.class.getName());
container.setDefaultMaxTextMessageBufferSize(128 * 1024);
}
use of javax.websocket.server.ServerContainer in project jetty.project by eclipse.
the class IdleTimeoutContextListener method contextInitialized.
@Override
public void contextInitialized(ServletContextEvent sce) {
ServerContainer container = (ServerContainer) sce.getServletContext().getAttribute(ServerContainer.class.getName());
// Build up a configuration with a specific path
String path = "/idle-onopen-endpoint";
ServerEndpointConfig.Builder builder = ServerEndpointConfig.Builder.create(OnOpenIdleTimeoutEndpoint.class, path);
try {
container.addEndpoint(builder.build());
} catch (DeploymentException e) {
throw new RuntimeException("Unable to add endpoint via config file", e);
}
}
Aggregations