private void registerEndpoint(ServerEndpointConfig endpointConfig) { ServerContainer serverContainer = getServerContainer(); Assert.state(serverContainer != null, "No ServerContainer set"); try { if (logger.isDebugEnabled()) { logger.debug("Registering ServerEndpointConfig: " + endpointConfig); } serverContainer.addEndpoint(endpointConfig); } catch (DeploymentException ex) { throw new IllegalStateException("Failed to register ServerEndpointConfig: " + endpointConfig, ex); } }
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); } }
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); try { ServerContainer wscontainer = WebSocketServerContainerInitializer.configureContext(context); wscontainer.addEndpoint(new RPDEndpointConfig()); server.start(); server.join(); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public void compileRoute(Route route) { log.debug("Adding websocket to {} with endpoint {} in server container {}", route.getUri(), route.getControllerClass(), serverContainer.getClass().getCanonicalName()); Class<?> endpointClass = route.getControllerClass(); // this must subclass an Endpoint to be valid if (!Endpoint.class.isAssignableFrom(endpointClass)) { throw new IllegalArgumentException("WebSocket controller class must be of type " + Endpoint.class.getCanonicalName()); } try { // programatically add endpoint to websocket container serverContainer.addEndpoint(new Jsr356ServerEndpointConfig(route)); } catch (DeploymentException e) { throw new RuntimeException(e); } }
public static void setWebSocketServer(ServletContextHandler servletContextHandler) throws ServletException, DeploymentException { // Add javax.websocket support ServerContainer container = WebSocketServerContainerInitializer.configureContext(servletContextHandler); container.setDefaultMaxSessionIdleTimeout(7*24*3600*1000); // Add echo endpoint to server container container.addEndpoint(BasicSocket.class); }
@Test public void addAnnotatedEndpointClassesWithServletContextOnly() throws Exception { this.exporter.setAnnotatedEndpointClasses(AnnotatedDummyEndpoint.class, AnnotatedDummyEndpointBean.class); this.exporter.setServletContext(this.servletContext); this.exporter.afterPropertiesSet(); this.exporter.afterSingletonsInstantiated(); verify(this.serverContainer).addEndpoint(AnnotatedDummyEndpoint.class); verify(this.serverContainer).addEndpoint(AnnotatedDummyEndpointBean.class); }
@Test public void addAnnotatedEndpointClassesWithExplicitServerContainerOnly() throws Exception { this.exporter.setAnnotatedEndpointClasses(AnnotatedDummyEndpoint.class, AnnotatedDummyEndpointBean.class); this.exporter.setServerContainer(this.serverContainer); this.exporter.afterPropertiesSet(); this.exporter.afterSingletonsInstantiated(); verify(this.serverContainer).addEndpoint(AnnotatedDummyEndpoint.class); verify(this.serverContainer).addEndpoint(AnnotatedDummyEndpointBean.class); }
@Test public void addAnnotatedEndpointClasses() throws Exception { this.exporter.setAnnotatedEndpointClasses(AnnotatedDummyEndpoint.class); this.exporter.setApplicationContext(this.webAppContext); this.exporter.afterPropertiesSet(); this.exporter.afterSingletonsInstantiated(); verify(this.serverContainer).addEndpoint(AnnotatedDummyEndpoint.class); verify(this.serverContainer).addEndpoint(AnnotatedDummyEndpointBean.class); }
for (int i = 0; i < pathLength; i++) { try { container.addEndpoint(ServerEndpointConfig.Builder.create(JSR356Endpoint.class, b.toString()).configurator(configurator).build()); } catch (DeploymentException e) { logger.warn("Duplicate Servlet Mapping Path {}. Use {} init-param to prevent this message", servletPath, ApplicationConfig.JSR356_MAPPING_PATH);
@Test public void addServerEndpointConfigBeanWithExplicitServerContainer() throws Exception { ServerEndpointRegistration endpointRegistration = new ServerEndpointRegistration("/dummy", new DummyEndpoint()); this.webAppContext.getBeanFactory().registerSingleton("dummyEndpoint", endpointRegistration); this.servletContext.removeAttribute("javax.websocket.server.ServerContainer"); this.exporter.setServerContainer(this.serverContainer); this.exporter.setApplicationContext(this.webAppContext); this.exporter.afterPropertiesSet(); this.exporter.afterSingletonsInstantiated(); verify(this.serverContainer).addEndpoint(endpointRegistration); }
@Test public void addServerEndpointConfigBean() throws Exception { ServerEndpointRegistration endpointRegistration = new ServerEndpointRegistration("/dummy", new DummyEndpoint()); this.webAppContext.getBeanFactory().registerSingleton("dummyEndpoint", endpointRegistration); this.exporter.setApplicationContext(this.webAppContext); this.exporter.afterPropertiesSet(); this.exporter.afterSingletonsInstantiated(); verify(this.serverContainer).addEndpoint(endpointRegistration); }
@Test public void addServerEndpointConfigBeanWithExplicitServletContext() throws Exception { ServerEndpointRegistration endpointRegistration = new ServerEndpointRegistration("/dummy", new DummyEndpoint()); this.webAppContext.getBeanFactory().registerSingleton("dummyEndpoint", endpointRegistration); this.exporter.setServletContext(this.servletContext); this.exporter.setApplicationContext(this.webAppContext); this.exporter.afterPropertiesSet(); this.exporter.afterSingletonsInstantiated(); verify(this.serverContainer).addEndpoint(endpointRegistration); }
ClientQueue clientQueue = ... ServerContainer container = ... container.addEndpoint(ServerEndpointConfig.Builder .create(MyWebSocketEndpoint.class, "/") // the endpoint url .configurator(new MyWebSocketEndpointConfigurator(clientQueue _)) .build());
private void configureWebSocketServlet(ServletContextHandler servletContextHandler) throws ServletException, DeploymentException { ServerContainer wscontainer = WebSocketServerContainerInitializer.configureContext(servletContextHandler); wscontainer.addEndpoint(SpawnWebSocket.class); }
@Override public void start(Context context) { for (Class<?> endpointClass : serverEndpointClasses) { try { serverContainer.addEndpoint(endpointClass); } catch (DeploymentException e) { throw new PluginException("Unable to deploy WebSocket server endpoint " + endpointClass, e); } } }
@Override public void contextInitialized(ServletContextEvent sce) { ServletContext container = sce.getServletContext(); final ServerContainer serverContainer = (ServerContainer) container .getAttribute(SERVER_CONTAINER_ATTRIBUTE); try { serverContainer.addEndpoint(new WicketServerEndpointConfig()); } catch (DeploymentException e) { throw new WicketSpringBootException(e); } }
private void initWebsocketRpcRuntime(ServletContextEvent sce) { ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute("javax.websocket.server.ServerContainer"); ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(WebsocketEndpoint.class, RpcConfig.getPath()+"/wskt").build(); try { sc.addEndpoint(sec); } catch (DeploymentException ex) { throw new RuntimeException(ex); } }
public static void setWebSocketServer(ServletContextHandler servletContextHandler) throws ServletException, DeploymentException { // Add javax.websocket support ServerContainer container = WebSocketServerContainerInitializer.configureContext(servletContextHandler); container.setDefaultMaxSessionIdleTimeout(7*24*3600*1000); // Add echo endpoint to server container container.addEndpoint(BasicSocket.class); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { ServerContainer container = (ServerContainer) servletContext.getAttribute(ServerContainer.class.getName()); try { // adding annotated endpoint cause wrapping it by server, that is not good in our case ServerEndpointConfig.Builder secb = ServerEndpointConfig.Builder.create(WsProxy.class, "/containers/{container}/attach/ws"); secb.configurator(new SpringConfigurator()); container.addEndpoint(secb.build()); } catch (Exception e) { log.error("Can not deploy", e); } }
private void initWebsocketRpcRuntime(final ServletContext ctx, final RpcSpringContext rpcCtx) { LOGGER.info("Starting Websocket RPC runtime"); ServerEndpointConfig.Configurator cfg = new WebsocketEndpointConfigurator(ctx, rpcCtx); ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(WebsocketEndpoint.class, RpcConfig.getInstance().getPath() + "/wskt").configurator(cfg).build(); try { rpcCtx.getWebsocketContainer().addEndpoint(sec); } catch (DeploymentException ex) { throw new RuntimeException(ex); } } }