Refine search
public JSR356AsyncSupport(AtmosphereConfig config, ServletContext ctx) { super(config); ServerContainer container = (ServerContainer) ctx.getAttribute(ServerContainer.class.getName()); if (ctx.getServerInfo().contains("WebLogic")) { logger.error("{} must use JDK 1.8+ with WebSocket", ctx.getServerInfo()); 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);
private void initServerContainer(ServerContainer serverContainer) { if (this.asyncSendTimeout != null) { serverContainer.setAsyncSendTimeout(this.asyncSendTimeout); } if (this.maxSessionIdleTimeout != null) { serverContainer.setDefaultMaxSessionIdleTimeout(this.maxSessionIdleTimeout); } if (this.maxTextMessageBufferSize != null) { serverContainer.setDefaultMaxTextMessageBufferSize(this.maxTextMessageBufferSize); } if (this.maxBinaryMessageBufferSize != null) { serverContainer.setDefaultMaxBinaryMessageBufferSize(this.maxBinaryMessageBufferSize); } }
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); }
Object mappingsAdded = context.getAttribute(FACES_INITIALIZER_MAPPINGS_ADDED); if (mappingsAdded != null) { context.removeAttribute(FACES_INITIALIZER_MAPPINGS_ADDED); context.setAttribute(WebConfiguration.BooleanWebContextInitParameter.EnableDistributable.getQualifiedName(), TRUE); serverContainer.addEndpoint(ServerEndpointConfig.Builder.create(WebsocketEndpoint.class, URI_TEMPLATE).build());
/** * Register web socket endpoint if necessary, i.e. when it's enabled via context param and not already installed. * @param context The involved servlet context. */ public static void registerEndpointIfNecessary(ServletContext context) { if (TRUE.equals(context.getAttribute(Socket.class.getName()))) { return; } if (!parseBoolean(context.getInitParameter(PARAM_SOCKET_ENDPOINT_ENABLED))) { return; } try { ServerContainer container = (ServerContainer) context.getAttribute(ServerContainer.class.getName()); ServerEndpointConfig config = ServerEndpointConfig.Builder.create(SocketEndpoint.class, SocketEndpoint.URI_TEMPLATE).build(); container.addEndpoint(config); context.setAttribute(Socket.class.getName(), TRUE); } catch (Exception e) { throw new FacesException(e); } }
@WebListener public class MyApplication implements ServletContextListener { private final static String SERVER_CONTAINER_ATTRIBUTE = "javax.websocket.server.ServerContainer"; @Override public void contextInitialized(ServletContextEvent sce) { ServletContext container = sce.getServletContext(); final ServerContainer serverContainer = (ServerContainer) container.getAttribute(SERVER_CONTAINER_ATTRIBUTE); try { serverContainer.addEndpoint(new MyEndpointConfig(MyEndpoint.class, "/wstest")); } catch (DeploymentException e) { e.printStackTrace(); } } }
String propsFile = getParam(PROPS_FILE); if (isNotBlank(propsFile)) { URL url = config.getServletContext().getClassLoader().getResource(propsFile); if (url == null && propsFile.startsWith("/")) { url = config.getServletContext().getResource(propsFile); URL url = config.getServletContext().getClassLoader().getResource("groovity.properties"); if (url != null) { LOG.info("Found groovity.properties on classpath"); if (webSocketServer != null) { webSocketServer.addEndpoint(ServerEndpointConfig.Builder .create(GroovityServerEndpoint.class, "/ws/{socketName}") .configurator(new GroovityServerEndpoint.Configurator(groovityScriptViewFactory, getServletContext())).build());
@Override public void contextInitialized(ServletContextEvent servletContextEvent) { ServerContainer serverContainer = (ServerContainer)servletContextEvent.getServletContext().getAttribute(ServerContainer.class.getName()); if (serverContainer == null) return; Object deployed = servletContextEvent.getServletContext().getAttribute(WEBSOCKET_DEPLOYED_ATTR); if (deployed != null) return; serverContainer.setDefaultMaxSessionIdleTimeout(gravity.getGravityConfig().getChannelIdleTimeoutMillis()); serverEndpointConfig.getUserProperties().put("servletContext", servletContextEvent.getServletContext()); serverEndpointConfig.getUserProperties().put("gravity", gravity); serverContainer.addEndpoint(serverEndpointConfig); servletContextEvent.getServletContext().setAttribute(WEBSOCKET_DEPLOYED_ATTR, true);
@Override public void contextInitialized(final ServletContextEvent sce) { final javax.websocket.server.ServerContainer serverContainer = (javax.websocket.server.ServerContainer) sce .getServletContext().getAttribute( "javax.websocket.server.ServerContainer"); try { final URI myUrl = URI.create(sce.getServletContext() .getInitParameter("servletUrl")); final ServerEndpointConfig config = ServerEndpointConfig.Builder .create(WebsocketEndpoint.class, myUrl.getPath()).build(); config.getUserProperties().put("servletUrl", myUrl); serverContainer.addEndpoint(config); } catch (final DeploymentException e) { LOG.log(Level.WARNING, "Couldn't initialize websocket server endpoint.", e); } }
public static void install(WebSocketTransport webSocketTransport, ServletContext servletContext) throws DeploymentException { String contextPath = servletContext.getContextPath(); if (contextPath == null) contextPath = ""; if (! contextPath.startsWith("/")) contextPath = "/" + contextPath; if (contextPath.endsWith("/")) contextPath = contextPath.substring(0, contextPath.length() - 1); if (log.isDebugEnabled()) log.debug("Context Path: " + contextPath); String endpointPath = webSocketTransport.getEndpointPath(); if (endpointPath == null) endpointPath = ""; if (! endpointPath.startsWith("/")) endpointPath = "/" + endpointPath; if (endpointPath.endsWith("/")) endpointPath = endpointPath.substring(0, endpointPath.length() - 1); if (log.isDebugEnabled()) log.debug("Endpoint Path: " + endpointPath); // find server container ServerContainer serverContainer = (ServerContainer) servletContext.getAttribute("javax.websocket.server.ServerContainer"); if (serverContainer == null) throw new DeploymentException("Cannot find ServerContainer"); // set default timeout long oldDefaultMaxSessionIdleTimeout = serverContainer.getDefaultMaxSessionIdleTimeout(); long newDefaultMaxSessionIdleTimeout = 0; serverContainer.setDefaultMaxSessionIdleTimeout(newDefaultMaxSessionIdleTimeout); if (log.isDebugEnabled()) log.debug("Changed default max session idle timeout from " + oldDefaultMaxSessionIdleTimeout + " to " + newDefaultMaxSessionIdleTimeout); // install install(serverContainer, webSocketTransport, contextPath, endpointPath, "/{path}"); for (UriMessagingContainerFactoryMount messagingContainerFactoryMount : webSocketTransport.getUriMessagingContainerRegistry().getMessagingContainerFactoryMounts()) { install(serverContainer, webSocketTransport, contextPath, endpointPath, messagingContainerFactoryMount.getMessagingContainerFactoryPath() + "/{path}"); } }
ServerContainer container = (ServerContainer)context.getAttribute(ServerContainer.class.getName()); if (container == null) { throw new IllegalArgumentException("Missing WebSocket ServerContainer"); maxMessageSize = container.getDefaultMaxTextMessageBufferSize(); container.setDefaultMaxTextMessageBufferSize(maxMessageSize); long idleTimeout = getOption(IDLE_TIMEOUT_OPTION, container.getDefaultMaxSessionIdleTimeout()); container.setDefaultMaxSessionIdleTimeout(idleTimeout); .build(); try { container.addEndpoint(config); } catch (DeploymentException x) { throw new RuntimeException(x);
@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); }
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); } }
Object mappingsAdded = context.getAttribute(FACES_INITIALIZER_MAPPINGS_ADDED); if (mappingsAdded != null) { context.removeAttribute(FACES_INITIALIZER_MAPPINGS_ADDED); context.setAttribute(WebConfiguration.BooleanWebContextInitParameter.EnableDistributable.getQualifiedName(), TRUE); serverContainer.addEndpoint(ServerEndpointConfig.Builder.create(WebsocketEndpoint.class, URI_TEMPLATE).build());
/** * Register web socket endpoint if necessary, i.e. when it's enabled via context param and not already installed. * @param context The involved servlet context. */ public static void registerEndpointIfNecessary(ServletContext context) { if (TRUE.equals(context.getAttribute(Socket.class.getName()))) { return; } if (!parseBoolean(context.getInitParameter(PARAM_SOCKET_ENDPOINT_ENABLED))) { return; } try { ServerContainer container = (ServerContainer) context.getAttribute(ServerContainer.class.getName()); ServerEndpointConfig config = ServerEndpointConfig.Builder.create(SocketEndpoint.class, SocketEndpoint.URI_TEMPLATE).build(); container.addEndpoint(config); context.setAttribute(Socket.class.getName(), TRUE); } catch (Exception e) { throw new FacesException(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 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 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); }
Object mappingsAdded = context.getAttribute(FACES_INITIALIZER_MAPPINGS_ADDED); if (mappingsAdded != null) { context.removeAttribute(FACES_INITIALIZER_MAPPINGS_ADDED); context.setAttribute(WebConfiguration.BooleanWebContextInitParameter.EnableDistributable.getQualifiedName(), TRUE); serverContainer.addEndpoint(ServerEndpointConfig.Builder.create(WebsocketEndpoint.class, URI_TEMPLATE).build());
@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); } }