javax.websocket.server.ServerContainer Java Examples
The following examples show how to use
javax.websocket.server.ServerContainer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestWsServerContainer.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Override public void contextInitialized(ServletContextEvent sce) { super.contextInitialized(sce); ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute( Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE); ServerEndpointConfig sec = ServerEndpointConfig.Builder.create( TesterEchoServer.Basic.class, "/{param}").build(); try { sc.addEndpoint(sec); } catch (DeploymentException e) { throw new RuntimeException(e); } }
Example #2
Source File: StartupListener.java From mdw with Apache License 2.0 | 6 votes |
@Override public void contextInitialized(ServletContextEvent contextEvent) { ServletContext servletContext = contextEvent.getServletContext(); mdwMain = new MdwMain(); String container = "Tomcat"; // TODO if (ApplicationContext.isSpringBoot()) { ServerContainer serverContainer = (ServerContainer)servletContext.getAttribute("javax.websocket.server.ServerContainer"); try { serverContainer.addEndpoint(WebSocketMessenger.class); } catch (Exception ex) { ex.printStackTrace(); } mdwMain.startup(container, SpringBootApplication.getBootDir().toString(), servletContext.getContextPath()); } else { mdwMain.startup(container, servletContext.getRealPath("/"), servletContext.getContextPath()); new InitialRequest().submit(); } }
Example #3
Source File: WebSocketListener.java From seed with Mozilla Public License 2.0 | 6 votes |
@Override public void contextInitialized(ServletContextEvent sce) { ServerContainer container = (ServerContainer) sce.getServletContext().getAttribute(SERVER_CONTAINER); if (container != null) { for (Class<?> endpointClass : serverEndpointClasses) { try { LOGGER.debug("Publishing WebSocket server endpoint {}", endpointClass.getCanonicalName()); container.addEndpoint(endpointClass); } catch (DeploymentException e) { throw SeedException.wrap(e, WebErrorCode.CANNOT_PUBLISH_WEBSOCKET_ENDPOINT) .put("class", endpointClass); } } } else { LOGGER.info("No WebSocket implementation found, WebSocket support disabled"); } }
Example #4
Source File: TesterEndpointConfig.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public void contextInitialized(ServletContextEvent sce) { super.contextInitialized(sce); ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute( Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE); try { ServerEndpointConfig sec = getServerEndpointConfig(); if (sec == null) { sc.addEndpoint(getEndpointClass()); } else { sc.addEndpoint(sec); } } catch (DeploymentException e) { throw new RuntimeException(e); } }
Example #5
Source File: TestCloseBug58624.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public void contextInitialized(ServletContextEvent sce) { super.contextInitialized(sce); ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute( Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE); ServerEndpointConfig sec = ServerEndpointConfig.Builder.create( Bug58624ServerEndpoint.class, PATH).build(); try { sc.addEndpoint(sec); } catch (DeploymentException e) { throw new RuntimeException(e); } }
Example #6
Source File: ServerEndpointExporter.java From spring-analysis-note with MIT License | 6 votes |
private void registerEndpoint(Class<?> endpointClass) { ServerContainer serverContainer = getServerContainer(); Assert.state(serverContainer != null, "No ServerContainer set. Most likely the server's own WebSocket ServletContainerInitializer " + "has not run yet. Was the Spring ApplicationContext refreshed through a " + "org.springframework.web.context.ContextLoaderListener, " + "i.e. after the ServletContext has been fully initialized?"); try { if (logger.isDebugEnabled()) { logger.debug("Registering @ServerEndpoint class: " + endpointClass); } serverContainer.addEndpoint(endpointClass); } catch (DeploymentException ex) { throw new IllegalStateException("Failed to register @ServerEndpoint class: " + endpointClass, ex); } }
Example #7
Source File: TestWsWebSocketContainer.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public void contextInitialized(ServletContextEvent sce) { super.contextInitialized(sce); ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute( Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE); try { sc.addEndpoint(ServerEndpointConfig.Builder.create( ConstantTxEndpoint.class, PATH).build()); if (TestWsWebSocketContainer.timeoutOnContainer) { sc.setAsyncSendTimeout(TIMEOUT_MS); } } catch (DeploymentException e) { throw new IllegalStateException(e); } }
Example #8
Source File: CamelWebSocketJSR356Recorder.java From camel-quarkus with Apache License 2.0 | 6 votes |
public void registerServerContainer(DeploymentManager deploymentManager) { ServletContextImpl servletContext = deploymentManager.getDeployment().getServletContext(); ServerContainer container = (ServerContainer) servletContext.getAttribute(ServerContainer.class.getName()); JSR356WebSocketComponent.registerServer(servletContext.getContextPath(), container); WebSocketDeploymentInfo deploymentInfo = (WebSocketDeploymentInfo) servletContext .getAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME); for (ServerEndpointConfig config : deploymentInfo.getProgramaticEndpoints()) { try { CamelServerEndpoint endpoint = config.getConfigurator().getEndpointInstance(CamelServerEndpoint.class); JSR356WebSocketComponent.ContextBag context = JSR356WebSocketComponent .getContext(servletContext.getContextPath()); context.getEndpoints().put(config.getPath(), endpoint); } catch (InstantiationException e) { throw new RuntimeException(e); } } }
Example #9
Source File: TesterEchoServer.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public void contextInitialized(ServletContextEvent sce) { super.contextInitialized(sce); ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute( Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE); try { sc.addEndpoint(Async.class); sc.addEndpoint(Basic.class); sc.addEndpoint(BasicLimitLow.class); sc.addEndpoint(BasicLimitHigh.class); sc.addEndpoint(WriterError.class); sc.addEndpoint(RootEcho.class); } catch (DeploymentException e) { throw new IllegalStateException(e); } }
Example #10
Source File: StartupListener.java From mdw with Apache License 2.0 | 6 votes |
@Override public void contextInitialized(ServletContextEvent contextEvent) { ServletContext servletContext = contextEvent.getServletContext(); mdwMain = new MdwMain(); String container = "Tomcat"; // TODO ServerContainer serverContainer = (ServerContainer)servletContext.getAttribute("javax.websocket.server.ServerContainer"); try { serverContainer.addEndpoint(WebSocketMessenger.class); } catch (Exception ex) { ex.printStackTrace(); } // mdw-spring-boot mdwMain.startup(container, mdwStarter.getBootDir().toString(), servletContext.getContextPath()); }
Example #11
Source File: WebSphereRequestUpgradeStrategy.java From spring-analysis-note with MIT License | 6 votes |
@Override public void upgradeInternal(ServerHttpRequest httpRequest, ServerHttpResponse httpResponse, @Nullable String selectedProtocol, List<Extension> selectedExtensions, Endpoint endpoint) throws HandshakeFailureException { HttpServletRequest request = getHttpServletRequest(httpRequest); HttpServletResponse response = getHttpServletResponse(httpResponse); StringBuffer requestUrl = request.getRequestURL(); String path = request.getRequestURI(); // shouldn't matter Map<String, String> pathParams = Collections.<String, String> emptyMap(); ServerEndpointRegistration endpointConfig = new ServerEndpointRegistration(path, endpoint); endpointConfig.setSubprotocols(Collections.singletonList(selectedProtocol)); endpointConfig.setExtensions(selectedExtensions); try { ServerContainer container = getContainer(request); upgradeMethod.invoke(container, request, response, endpointConfig, pathParams); } catch (Exception ex) { throw new HandshakeFailureException( "Servlet request failed to upgrade to WebSocket for " + requestUrl, ex); } }
Example #12
Source File: TestWsWebSocketContainer.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Override public void contextInitialized(ServletContextEvent sce) { super.contextInitialized(sce); ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute( Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE); try { sc.addEndpoint(ServerEndpointConfig.Builder.create( ConstantTxEndpoint.class, PATH).build()); if (TestWsWebSocketContainer.timeoutOnContainer) { sc.setAsyncSendTimeout(TIMEOUT_MS); } } catch (DeploymentException e) { throw new IllegalStateException(e); } }
Example #13
Source File: TestClose.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Override public void contextInitialized(ServletContextEvent sce) { super.contextInitialized(sce); ServerContainer sc = (ServerContainer) sce .getServletContext() .getAttribute( Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE); ServerEndpointConfig sec = ServerEndpointConfig.Builder.create( getEndpointClass(), PATH).build(); try { sc.addEndpoint(sec); } catch (DeploymentException e) { throw new RuntimeException(e); } }
Example #14
Source File: TestWsServerContainer.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Override public void contextInitialized(ServletContextEvent sce) { super.contextInitialized(sce); ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute( Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE); ServerEndpointConfig sec = ServerEndpointConfig.Builder.create( TesterEchoServer.Basic.class, "/{param}").build(); try { sc.addEndpoint(sec); } catch (DeploymentException e) { throw new RuntimeException(e); } }
Example #15
Source File: ServerContainerInitializeListener.java From everrest with Eclipse Public License 2.0 | 6 votes |
@Override public final void contextInitialized(ServletContextEvent sce) { final ServletContext servletContext = sce.getServletContext(); webApplicationDeclaredRoles = new WebApplicationDeclaredRoles(servletContext); everrestConfiguration = (EverrestConfiguration)servletContext.getAttribute(EVERREST_CONFIG_ATTRIBUTE); if (everrestConfiguration == null) { everrestConfiguration = new EverrestConfiguration(); } final ServerContainer serverContainer = (ServerContainer)servletContext.getAttribute("javax.websocket.server.ServerContainer"); try { serverEndpointConfig = createServerEndpointConfig(servletContext); serverContainer.addEndpoint(serverEndpointConfig); } catch (DeploymentException e) { throw new IllegalStateException(e.getMessage(), e); } }
Example #16
Source File: Demo_JettyWebSocketServer.java From haxademic with MIT License | 6 votes |
protected void firstFrame() { server = new Server(); ServerConnector connector = new ServerConnector(server); connector.setPort(8787); server.addConnector(connector); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/websocket"); server.setHandler(context); try { ServerContainer wscontainer = WebSocketServerContainerInitializer.initialize(context); wscontainer.addEndpoint(WebsocketEndpoint.class); synchronized (server) { server.start(); } } catch (Throwable t) { t.printStackTrace(System.err); } }
Example #17
Source File: TestWsWebSocketContainer.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Override public void contextInitialized(ServletContextEvent sce) { super.contextInitialized(sce); ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute( Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE); try { sc.addEndpoint(ServerEndpointConfig.Builder.create( ConstantTxEndpoint.class, PATH).build()); if (TestWsWebSocketContainer.timoutOnContainer) { sc.setAsyncSendTimeout(TIMEOUT_MS); } } catch (DeploymentException e) { throw new IllegalStateException(e); } }
Example #18
Source File: TesterEchoServer.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Override public void contextInitialized(ServletContextEvent sce) { super.contextInitialized(sce); ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute( Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE); try { sc.addEndpoint(Async.class); sc.addEndpoint(Basic.class); sc.addEndpoint(BasicLimitLow.class); sc.addEndpoint(BasicLimitHigh.class); sc.addEndpoint(RootEcho.class); } catch (DeploymentException e) { throw new IllegalStateException(e); } }
Example #19
Source File: WebSphereRequestUpgradeStrategy.java From java-technology-stack with MIT License | 6 votes |
@Override public void upgradeInternal(ServerHttpRequest httpRequest, ServerHttpResponse httpResponse, @Nullable String selectedProtocol, List<Extension> selectedExtensions, Endpoint endpoint) throws HandshakeFailureException { HttpServletRequest request = getHttpServletRequest(httpRequest); HttpServletResponse response = getHttpServletResponse(httpResponse); StringBuffer requestUrl = request.getRequestURL(); String path = request.getRequestURI(); // shouldn't matter Map<String, String> pathParams = Collections.<String, String> emptyMap(); ServerEndpointRegistration endpointConfig = new ServerEndpointRegistration(path, endpoint); endpointConfig.setSubprotocols(Collections.singletonList(selectedProtocol)); endpointConfig.setExtensions(selectedExtensions); try { ServerContainer container = getContainer(request); upgradeMethod.invoke(container, request, response, endpointConfig, pathParams); } catch (Exception ex) { throw new HandshakeFailureException( "Servlet request failed to upgrade to WebSocket for " + requestUrl, ex); } }
Example #20
Source File: WebSphereRequestUpgradeStrategy.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public void upgradeInternal(ServerHttpRequest httpRequest, ServerHttpResponse httpResponse, String selectedProtocol, List<Extension> selectedExtensions, Endpoint endpoint) throws HandshakeFailureException { HttpServletRequest request = getHttpServletRequest(httpRequest); HttpServletResponse response = getHttpServletResponse(httpResponse); StringBuffer requestUrl = request.getRequestURL(); String path = request.getRequestURI(); // shouldn't matter Map<String, String> pathParams = Collections.<String, String> emptyMap(); ServerEndpointRegistration endpointConfig = new ServerEndpointRegistration(path, endpoint); endpointConfig.setSubprotocols(Collections.singletonList(selectedProtocol)); endpointConfig.setExtensions(selectedExtensions); try { ServerContainer container = getContainer(request); upgradeMethod.invoke(container, request, response, endpointConfig, pathParams); } catch (Exception ex) { throw new HandshakeFailureException( "Servlet request failed to upgrade to WebSocket for " + requestUrl, ex); } }
Example #21
Source File: ServletServerContainerFactoryBean.java From java-technology-stack with MIT License | 6 votes |
@Override public void afterPropertiesSet() { Assert.state(this.servletContext != null, "A ServletContext is required to access the javax.websocket.server.ServerContainer instance"); this.serverContainer = (ServerContainer) this.servletContext.getAttribute( "javax.websocket.server.ServerContainer"); Assert.state(this.serverContainer != null, "Attribute 'javax.websocket.server.ServerContainer' not found in ServletContext"); if (this.asyncSendTimeout != null) { this.serverContainer.setAsyncSendTimeout(this.asyncSendTimeout); } if (this.maxSessionIdleTimeout != null) { this.serverContainer.setDefaultMaxSessionIdleTimeout(this.maxSessionIdleTimeout); } if (this.maxTextMessageBufferSize != null) { this.serverContainer.setDefaultMaxTextMessageBufferSize(this.maxTextMessageBufferSize); } if (this.maxBinaryMessageBufferSize != null) { this.serverContainer.setDefaultMaxBinaryMessageBufferSize(this.maxBinaryMessageBufferSize); } }
Example #22
Source File: TesterEchoServer.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Override public void contextInitialized(ServletContextEvent sce) { super.contextInitialized(sce); ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute( Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE); try { sc.addEndpoint(Async.class); sc.addEndpoint(Basic.class); sc.addEndpoint(BasicLimitLow.class); sc.addEndpoint(BasicLimitHigh.class); sc.addEndpoint(RootEcho.class); } catch (DeploymentException e) { throw new IllegalStateException(e); } }
Example #23
Source File: ServerEndpointExporter.java From java-technology-stack with MIT License | 6 votes |
private void registerEndpoint(Class<?> endpointClass) { ServerContainer serverContainer = getServerContainer(); Assert.state(serverContainer != null, "No ServerContainer set. Most likely the server's own WebSocket ServletContainerInitializer " + "has not run yet. Was the Spring ApplicationContext refreshed through a " + "org.springframework.web.context.ContextLoaderListener, " + "i.e. after the ServletContext has been fully initialized?"); try { if (logger.isDebugEnabled()) { logger.debug("Registering @ServerEndpoint class: " + endpointClass); } serverContainer.addEndpoint(endpointClass); } catch (DeploymentException ex) { throw new IllegalStateException("Failed to register @ServerEndpoint class: " + endpointClass, ex); } }
Example #24
Source File: TestCloseBug58624.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Override public void contextInitialized(ServletContextEvent sce) { super.contextInitialized(sce); ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute( Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE); ServerEndpointConfig sec = ServerEndpointConfig.Builder.create( Bug58624ServerEndpoint.class, PATH).build(); try { sc.addEndpoint(sec); } catch (DeploymentException e) { throw new RuntimeException(e); } }
Example #25
Source File: TestWsRemoteEndpointImplServer.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Override public void contextInitialized(ServletContextEvent sce) { super.contextInitialized(sce); ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute( Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE); List<Class<? extends Encoder>> encoders = new ArrayList<Class<? extends Encoder>>(); encoders.add(Bug58624Encoder.class); ServerEndpointConfig sec = ServerEndpointConfig.Builder.create( Bug58624Endpoint.class, PATH).encoders(encoders).build(); try { sc.addEndpoint(sec); } catch (DeploymentException e) { throw new RuntimeException(e); } }
Example #26
Source File: AbstractStandardUpgradeStrategy.java From spring4-understanding with Apache License 2.0 | 5 votes |
protected ServerContainer getContainer(HttpServletRequest request) { ServletContext servletContext = request.getServletContext(); String attrName = "javax.websocket.server.ServerContainer"; ServerContainer container = (ServerContainer) servletContext.getAttribute(attrName); Assert.notNull(container, "No 'javax.websocket.server.ServerContainer' ServletContext attribute. " + "Are you running in a Servlet container that supports JSR-356?"); return container; }
Example #27
Source File: TestWsWebSocketContainer.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public void contextInitialized(ServletContextEvent sce) { super.contextInitialized(sce); ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute( Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE); try { sc.addEndpoint(BlockingPojo.class); } catch (DeploymentException e) { throw new IllegalStateException(e); } }
Example #28
Source File: WebSocketServer.java From product-cep with Apache License 2.0 | 5 votes |
public void start(int port) { server = new Server(); ServerConnector connector = new ServerConnector(server); connector.setPort(port); server.addConnector(connector); // Setup the basic application "context" for this application at "/" // This is also known as the handler tree (in jetty speak) ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); server.setHandler(context); try { // Initialize javax.websocket layer ServerContainer wscontainer = WebSocketServerContainerInitializer.configureContext(context); // Add WebSocket endpoint to javax.websocket layer wscontainer.addEndpoint(EventSocket.class); new Thread(new Runnable() { @Override public void run() { try { server.start(); server.join(); } catch (Exception e) { log.error(e); } } }).start(); } catch (Throwable t) { log.error(t); } }
Example #29
Source File: TesterFirehoseServer.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public void contextInitialized(ServletContextEvent sce) { super.contextInitialized(sce); ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute( Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE); try { sc.addEndpoint(Endpoint.class); } catch (DeploymentException e) { throw new IllegalStateException(e); } }
Example #30
Source File: WebSocketServer.java From product-cep with Apache License 2.0 | 5 votes |
public void start(int port, String host) { server = new Server(); ServerConnector connector = new ServerConnector(server); connector.setHost(host); connector.setPort(port); server.addConnector(connector); // Setup the basic application "context" for this application at "/" // This is also known as the handler tree (in jetty speak) ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); server.setHandler(context); try { // Initialize javax.websocket layer ServerContainer wscontainer = WebSocketServerContainerInitializer.configureContext(context); // Add WebSocket endpoint to javax.websocket layer wscontainer.addEndpoint(EventSocket.class); new Thread(new Runnable() { @Override public void run() { try { server.start(); server.join(); } catch (Exception e) { log.error(e); } } }).start(); } catch (Throwable t) { log.error(t); } }