本文整理汇总了Java中org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer类的典型用法代码示例。如果您正苦于以下问题:Java WebSocketServerContainerInitializer类的具体用法?Java WebSocketServerContainerInitializer怎么用?Java WebSocketServerContainerInitializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WebSocketServerContainerInitializer类属于org.eclipse.jetty.websocket.jsr356.server.deploy包,在下文中一共展示了WebSocketServerContainerInitializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; //导入依赖的package包/类
public void start() throws Exception {
server = new Server(port);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.addFilter(AuthenticationFilter.class, "/*", null);
context.setServer(server);
// Add static files handler
context.setBaseResource(Resource.newResource(JettyServer.class.getResource("/webapp")));
context.addServlet(DefaultServlet.class,"/");
context.setWelcomeFiles(new String[]{"index.html"});
ServerContainer wsContainer = WebSocketServerContainerInitializer.configureContext(context);
wsContainer.addEndpoint(createEndpointConfig(EchoEndpoint.class));
server.setHandler(context);
server.start();
}
示例2: setWebSocketEndpoints
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; //导入依赖的package包/类
/**
*
* @param context the context to add the web socket endpoints to
* @param rtEventResource The instance of the websocket endpoint to return
* @throws DeploymentException
*/
private static void setWebSocketEndpoints(ServletContextHandler context,
EventsResource rtEventResource)
throws DeploymentException, ServletException {
ServerContainer wsContainer = WebSocketServerContainerInitializer.configureContext(context);
ServerEndpointConfig serverConfig =
ServerEndpointConfig.Builder
.create(EventsResource.class, EventsResource.RT_EVENT_ENDPOINT)
.configurator(new Configurator() {
@Override
public <T> T getEndpointInstance(Class<T> endpointClass)
throws InstantiationException {
return endpointClass.cast(rtEventResource);
}
}).build();
wsContainer.addEndpoint(serverConfig);
}
示例3: beforeClass
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() throws Exception {
ccowServer = new Server(serverPort);
final CCOWContextListener c = new CCOWContextListener(commonContext, new InlinedContextAgentRepositoryModule());
final MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
ccowServer.addBean(mbContainer);
final ServletContextHandler webSocketServletContextHandler = new ServletContextHandler(ccowServer, "/ws",
ServletContextHandler.SESSIONS);
webSocketServletContextHandler.addEventListener(c);
WebSocketServerContainerInitializer.configureContext(webSocketServletContextHandler);
final ServletContextHandler restServletContextHandler = new ServletContextHandler(ccowServer, "/");
restServletContextHandler.addEventListener(c);
restServletContextHandler.addFilter(AppGuiceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
final ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(new Handler[] { webSocketServletContextHandler, restServletContextHandler});
ccowServer.setHandler(contexts);
ccowServer.start();
}
示例4: createComputeRealtimeServer
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; //导入依赖的package包/类
/**
* Creates a new {@link ComputeRealtimeServer}
*
* @param config
* The chatalytics config
* @return A newly created {@link ComputeRealtimeServer}
*/
public ComputeRealtimeServer createComputeRealtimeServer() {
Server server = new Server(config.computeConfig.rtComputePort);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, "/*");
jerseyServlet.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES,
StatusResource.class.getPackage().toString());
server.setHandler(context);
ServerContainer wscontainer;
try {
wscontainer = WebSocketServerContainerInitializer.configureContext(context);
wscontainer.addEndpoint(RealtimeResource.class);
} catch (ServletException | DeploymentException e) {
throw new RuntimeException("Can't instantiate websocket. Reason: " + e.getMessage());
}
return new ComputeRealtimeServer(server);
}
示例5: start
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; //导入依赖的package包/类
/**
* Initialize a websocket server
*/
public static void start() {
if(isRunning()){
return;
}
server = new Server();
connector = new ServerConnector(server);
connector.setPort(8787);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler(
ServletContextHandler.SESSIONS);
context.setContextPath("/");
server.setHandler(context);
try {
ServerContainer wscontainer = WebSocketServerContainerInitializer
.configureContext(context);
wscontainer.addEndpoint(WebsocketEndpoint.class);
synchronized (server) {
server.start();
}
} catch (Throwable t) {
t.printStackTrace(System.err);
}
}
示例6: startServer
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; //导入依赖的package包/类
@Override
protected void startServer(int port, final Action<ServerWebSocket> websocketAction) throws
Exception {
server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(port);
server.addConnector(connector);
ServletContextHandler handler = new ServletContextHandler();
server.setHandler(handler);
ServerContainer container = WebSocketServerContainerInitializer.configureContext(handler);
ServerEndpointConfig config = ServerEndpointConfig.Builder.create(AsityServerEndpoint.class,
TEST_URI)
.configurator(new Configurator() {
@Override
public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
return endpointClass.cast(new AsityServerEndpoint().onwebsocket(websocketAction));
}
})
.build();
container.addEndpoint(config);
server.start();
}
示例7: run
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; //导入依赖的package包/类
public void run() {
try {
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(port);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.setContextPath(contextPath);
context.addFilter(GuiceFilter.class, "/api/*", null);
server.setHandler(context);
ServerContainer wsContainer = WebSocketServerContainerInitializer.configureContext(context);
KafkaWebsocketEndpoint.Configurator.setKafkaProps(consumerProps, producerProps);
wsContainer.addEndpoint(KafkaWebsocketEndpoint.class);
server.start();
server.join();
} catch (Exception e) {
logger.error("Failed to start the server: ", e);
}
}
示例8: main
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
Server server = new Server(9090);
ClassList classlist = Configuration.ClassList.setServerDefault(server);
classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
WebAppContext webapp = new WebAppContext();
webapp.setParentLoaderPriority(true);
webapp.setConfigurationDiscovered(true);
webapp.setContextPath("/");
webapp.setResourceBase("src/main/webapp");
webapp.setWar("src/main/webapp");
ServletHolder servletHolder = webapp.addServlet(DemoUIServlet.class, "/*");
servletHolder.setAsyncSupported(true);
servletHolder.setInitParameter("org.atmosphere.cpr.asyncSupport", JSR356AsyncSupport.class.getName());
server.setHandler(webapp);
ServerContainer webSocketServer = WebSocketServerContainerInitializer.configureContext(webapp);
webSocketServer.setDefaultMaxSessionIdleTimeout(10000000);
server.start();
log.info("Browse http://localhost:9090 to see the demo");
server.join();
}
示例9: startServer
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; //导入依赖的package包/类
@Override
protected void startServer() throws Exception {
server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(port);
server.addConnector(connector);
ServletContextHandler handler = new ServletContextHandler();
server.setHandler(handler);
ServerContainer container = WebSocketServerContainerInitializer.configureContext(handler);
ServerEndpointConfig config = ServerEndpointConfig.Builder.create(VibeServerEndpoint.class, "/test")
.configurator(new Configurator() {
@Override
public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
return endpointClass.cast(new VibeServerEndpoint().onwebsocket(performer.serverAction()));
}
})
.build();
container.addEndpoint(config);
server.start();
}
示例10: JettyServer
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; //导入依赖的package包/类
/**
* Constructor.
*
* @param port the port to listen on.
*/
JettyServer(final int port) {
server = new Server(port);
// Initialize the context handler
context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/ws/onos");
server.setHandler(context);
// Initialize the WebSocket layer
container =
WebSocketServerContainerInitializer.configureContext(context);
try {
container.addEndpoint(TopologyWebSocket.class);
} catch (DeploymentException e) {
log.debug("Exception adding WebSocket endpoint: ", e);
}
}
示例11: start
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; //导入依赖的package包/类
public void start() {
server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(port);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
server.setHandler(context);
ServerContainer wscontainer = WebSocketServerContainerInitializer.configureContext(context);
try {
wscontainer.addEndpoint(new RPDEndpointConfig());
server.start();
server.join();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例12: start
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; //导入依赖的package包/类
public void start() throws Exception {
server = new Server(port);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.addFilter(GuiceFilter.class, "/*", null);
context.addEventListener(guiceConfig);
// ServletHolder servletHolder = new ServletHolder(ServletContainer.class);
// servletHolder.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
// servletHolder.setInitParameter("com.sun.jersey.config.property.packages", "com.gdiama");
// servletHolder.setInitParameter("com.sun.jersey.config.feature.Debug", "true");
// servletHolder.setInitParameter("com.sun.jersey.config.feature.Trace", "true");
// servletHolder.setInitParameter("com.sun.jersey.spi.container.ContainerRequestFilters", "com.sun.jersey.api.container.filter.LoggingFilter");
// servletHolder.setInitParameter("com.sun.jersey.spi.container.ContainerResponseFilters", "com.sun.jersey.api.container.filter.LoggingFilter");
// context.addServlet(servletHolder, "/rest/*");
context.setServer(server);
ServerContainer wscontainer = WebSocketServerContainerInitializer.configureContext(context);
wscontainer.addEndpoint(WebsocketEndpoint.class);
server.setHandler(context);
server.start();
}
示例13: run
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; //导入依赖的package包/类
protected static void run(final CountDownLatch latch) throws Exception {
final Server server = new Server();
final ServerConnector serverConnector = new ServerConnector(server);
serverConnector.setPort(PORT);
server.addConnector(serverConnector);
final ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
contextHandler.setContextPath("/");
server.setHandler(contextHandler);
WebSocketServerContainerInitializer.configureContext(contextHandler).addEndpoint(serverEndpointConfig());
server.start();
final ClientContainer container = new ClientContainer();
container.start();
connect(container, latch);
container.stop();
server.stop();
}
示例14: setup
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; //导入依赖的package包/类
private Server setup() throws IOException, DeploymentException, ServletException {
synchronized (this) {
checkState(server == null, "Server already started.");
}
MatlabInstancePool pool
= new MatlabInstancePool(MatlabInstancePoolConfiguration
.builder()
.withMaximalNumInstances(getOptions().getThreads())
.withInstanceConfig(MatlabInstanceConfiguration
.builder()
.withBaseDir(getOptions().getPath())
.hidden(getOptions().isHidden())
.build())
.build());
Server jetty = new Server(getOptions().getPort());
ServletContextHandler handler
= new ServletContextHandler(ServletContextHandler.SESSIONS);
handler.setContextPath("/");
jetty.setHandler(handler);
handler.addLifeCycleListener(new MatlabInstancePoolDestroyer(pool));
ServerContainer sc = WebSocketServerContainerInitializer.configureContext(handler);
sc.addEndpoint(ServerEndpointConfig.Builder.create(MatlabServerEndpoint.class, "/")
.configurator(new MatlabServerEndpointConfigurator(pool)).build());
return jetty;
}
示例15: createWebsocketHandler
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; //导入依赖的package包/类
private void createWebsocketHandler(final HandlerCollection handlerCollection) {
// https://github.com/jetty-project/embedded-jetty-websocket-examples/blob/master/javax.websocket-example/src/main/java/org/eclipse/jetty/demo/EventServer.java
try {
final Set<Class<?>> managedClasses = collectAnnotated(WEBSOCKET_MANAGED_CLASSES);
final ServletContextHandler context = initContext("/websockets", managedClasses);
handlerCollection.addHandler(context);
final ServerContainer wscontainer = WebSocketServerContainerInitializer.configureContext(context);
managedClasses.forEach(c -> registerEndpoint(wscontainer, c));
} catch (final ServletException e) {
throw new TestEEfiException("Failed to initialize websockets", e);
}
}