Package javax.websocket.server

Examples of javax.websocket.server.ServerContainer


    private static final String PATH = "/{path";
    private final AtmosphereConfigurator configurator;

    public JSR356AsyncSupport(AtmosphereConfig config) {
        super(config);
        ServerContainer container = (ServerContainer) config.getServletContext().getAttribute(ServerContainer.class.getName());

        if (container == null) {
            throw new IllegalStateException("ServerContainer is null. Make sure you are using JDK7 and your server has websocket support enabled");
        }

        int pathLength = 5;
        String s = config.getInitParameter(ApplicationConfig.JSR356_PATH_MAPPING_LENGTH);
        if (s != null) {
            pathLength = Integer.valueOf(s);
        }
        logger.trace("JSR356 Path mapping Size {}", pathLength);

        String servletPath = config.getInitParameter(ApplicationConfig.JSR356_MAPPING_PATH);
        if (servletPath == null) {
            servletPath = IOUtils.guestServletPath(config);
            if (servletPath.equals("/") || servletPath.equals("/*")) {
                servletPath = PATH +"}";
            }
        }
        logger.info("JSR 356 Mapping path {}", servletPath);
        configurator = new AtmosphereConfigurator(config.framework());

        StringBuilder b = new StringBuilder(servletPath);
        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);
                logger.trace("", e);
                servletPath = IOUtils.guestServletPath(config);
                logger.warn("Duplicate guess {}", servletPath, e);
View Full Code Here


    }

    @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);
        }
View Full Code Here

    }

    @Override
    public void contextInitialized(ServletContextEvent sce)
    {
        ServerContainer container = (ServerContainer)sce.getServletContext().getAttribute(ServerContainer.class.getName());
        try
        {
            Configurator config = new Config();
           
            container.addEndpoint(ServerEndpointConfig.Builder.create(PongMessageEndpoint.class,"/ping").configurator(config).build());
            container.addEndpoint(ServerEndpointConfig.Builder.create(PongMessageEndpoint.class,"/pong").configurator(config).build());
            container.addEndpoint(ServerEndpointConfig.Builder.create(PongSocket.class,"/ping-socket").build());
            container.addEndpoint(ServerEndpointConfig.Builder.create(PongSocket.class,"/pong-socket").build());
        }
        catch (DeploymentException e)
        {
            throw new RuntimeException("Unable to add endpoint directly",e);
        }
View Full Code Here

    }

    @Override
    public void contextInitialized(ServletContextEvent sce)
    {
        ServerContainer container = (ServerContainer)sce.getServletContext().getAttribute(ServerContainer.class.getName());
        container.setDefaultMaxTextMessageBufferSize(128 * 1024);
    }
View Full Code Here

    }

    @Override
    public void contextInitialized(ServletContextEvent sce)
    {
        ServerContainer container = (ServerContainer)sce.getServletContext().getAttribute(ServerContainer.class.getName());
        try
        {
            container.addEndpoint(BasicEchoSocket.class);
        }
        catch (DeploymentException e)
        {
            throw new RuntimeException("Unable to add endpoint directly",e);
        }
View Full Code Here

    }

    @Override
    public void contextInitialized(ServletContextEvent sce)
    {
        ServerContainer container = (ServerContainer)sce.getServletContext().getAttribute(ServerContainer.class.getName());
       
        try
        {
            container.addEndpoint(ServerEndpointConfig.Builder.create(PongMessageEndpoint.class,"/ping").build());
            container.addEndpoint(ServerEndpointConfig.Builder.create(PongMessageEndpoint.class,"/pong").build());
        }
        catch (DeploymentException e)
        {
            throw new RuntimeException("Unable to add endpoint via config file",e);
        }
View Full Code Here

    }

    @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);
        }
View Full Code Here

    }

    @Override
    public void contextInitialized(ServletContextEvent sce)
    {
        ServerContainer container = (ServerContainer)sce.getServletContext().getAttribute(ServerContainer.class.getName());
        if (container==null)
            throw new IllegalStateException("No Websocket ServerContainer in "+sce.getServletContext());
       
        // Build up a configuration with a specific path
        String path = "/echo";
        ServerEndpointConfig.Builder builder = ServerEndpointConfig.Builder.create(BasicEchoEndpoint.class,path);
        try
        {
            container.addEndpoint(builder.build());
        }
        catch (DeploymentException e)
        {
            throw new RuntimeException("Unable to add endpoint via config file",e);
        }
View Full Code Here

@WebListener
public class WsConfigListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        ServerContainer sc =
                (ServerContainer) sce.getServletContext().getAttribute(
                        "javax.websocket.server.ServerContainer");
        try {
            sc.addEndpoint(ServerEndpointConfig.Builder.create(
                    EchoEndpoint.class, "/websocket/echoProgrammatic").build());
        } catch (DeploymentException e) {
            throw new IllegalStateException(e);
        }
    }
View Full Code Here

   * @see WebsocketBehaviorEndpoint
   */
  @Override
  public void init(Application application){       
    WebApplication webApp = (WebApplication)application;
    ServerContainer serverContainer =  (ServerContainer) webApp.getServletContext()
                      .getAttribute("javax.websocket.server.ServerContainer");
   
    ServerEndpointConfig configs = ServerEndpointConfig.Builder.create(WebsocketBehaviorEndpoint.class,
        "/" + WebsocketBehavior.WEBSOCKET_CREATOR_URL).build();
   
    //add the current application as user property for the endpoint
    configs.getUserProperties().put("currentApplication", application);
    //define the WebsocketBehaviorsManager that will be used to pass the WebsocketBehaviorS to the endpoint
    application.setMetaData(WebsocketBehavior.WEBSOCKET_BEHAVIOR_MAP_KEY, new WebsocketBehaviorsManager());
   
    try {
      serverContainer.addEndpoint(configs);
    } catch (DeploymentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
View Full Code Here

TOP

Related Classes of javax.websocket.server.ServerContainer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.