Java 类javax.websocket.server.ServerContainer 实例源码

项目:OpenChatAlytics    文件:ServerMain.java   
/**
 *
 * @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);
}
项目:lucee-websocket    文件:Configurator.java   
public static void configureEndpoint(String endpointPath, Class endpointClass, Class handshakeHandlerClass,
        LuceeApp app) throws ClassNotFoundException, IllegalAccessException, InstantiationException,
        DeploymentException, PageException {

    ServerEndpointConfig serverEndpointConfig = ServerEndpointConfig.Builder.create(endpointClass,
            endpointPath).configurator(
                    (ServerEndpointConfig.Configurator) handshakeHandlerClass.newInstance()).build();

    try {

        ServerContainer serverContainer = (ServerContainer) app.getServletContext().getAttribute(
                "javax.websocket.server.ServerContainer");
        serverContainer.addEndpoint(serverEndpointConfig);
    }
    catch (DeploymentException ex) {

        app.log(Log.LEVEL_DEBUG, "Failed to register endpoint " + endpointPath + ": " + ex.getMessage(),
                app.getName(), "websocket");
    }
    // System.out.println(Configurator.class.getName() + " >>> exit configureEndpoint()");
}
项目:tomcat7    文件:TesterEchoServer.java   
@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);
    }
}
项目:tomcat7    文件:TestCloseBug58624.java   
@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);
    }
}
项目:tomcat7    文件:TestWsServerContainer.java   
@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);
    }
}
项目:tomcat7    文件:TestWsRemoteEndpointImplServer.java   
@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);
    }
}
项目:tomcat7    文件:TestClose.java   
@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);
    }
}
项目:tomcat7    文件:TestWsWebSocketContainer.java   
@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);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:TesterEchoServer.java   
@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);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestCloseBug58624.java   
@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);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestWsServerContainer.java   
@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);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestWsRemoteEndpointImplServer.java   
@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);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestClose.java   
@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);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestWsWebSocketContainer.java   
@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);
    }
}
项目:ccow    文件:CCOWContextListener.java   
@Override
public void contextInitialized(final ServletContextEvent servletContextEvent) {
    super.contextInitialized(servletContextEvent);
    final ServerContainer serverContainer = (ServerContainer) servletContextEvent.getServletContext()
            .getAttribute("javax.websocket.server.ServerContainer");

    if (serverContainer != null) {
        try {
            serverContainer.addEndpoint(ServerEndpointConfig.Builder
                    .create(SubscriptionEndpoint.class, "/ContextManager/{" + PATH_NAME + "}").build());
            // serverContainer.addEndpoint(ServerEndpointConfig.Builder
            // .create(ExtendedSubscriptionEndpoint.class,
            // "/ContextManager/{contextParticipantId}")
            // .configurator(new WebSocketsConfigurator()).build());
        } catch (final DeploymentException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}
项目:ccow    文件:WebSocketsModule.java   
protected void addEndpoint(final Class<?> cls) {

    final ServerContainer container = getServerContainer();

    if (container == null) {
      LOG.warn("ServerContainer is null. Skip registration of websocket endpoint {}", cls);
      return;
    }

    try {
      LOG.debug("Register endpoint {}", cls);

      final ServerEndpointConfig config = createEndpointConfig(cls);
      container.addEndpoint(config);

    } catch (final DeploymentException e) {
      addError(e);
    }
  }
项目:spring4-understanding    文件:WebSphereRequestUpgradeStrategy.java   
@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);
    }
}
项目:OpenChatAlytics    文件:ComputeRealtimeServerFactory.java   
/**
 * 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);
}
项目:mdw    文件:StartupListener.java   
@Override
public void contextInitialized(ServletContextEvent contextEvent) {
    ServletContext servletContext = contextEvent.getServletContext();
    mdwMain = new MdwMain();
    String container = NamingProvider.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());
    }
}
项目:proteus-incremental-analytics    文件:WebsocketServer.java   
/**
 * 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);
    }
}
项目:dropwizard-websocket-jee7-bundle    文件:WebsocketContainer.java   
public WebsocketContainer(WebsocketConfiguration configuration, ServerContainer serverContainer) {
    this.serverContainer = serverContainer;

    Optional<Long> longVal = Optional.fromNullable(configuration.getMaxSessionIdleTimeout());
    if (longVal.isPresent()) {
        this.serverContainer.setDefaultMaxSessionIdleTimeout(longVal.get());
    }
    longVal = Optional.fromNullable(configuration.getAsyncSendTimeout());
    if (longVal.isPresent()) {
        this.serverContainer.setAsyncSendTimeout(longVal.get());
    }
    Optional<Integer> intVal = Optional.fromNullable(configuration.getMaxBinaryMessageBufferSize());
    if (intVal.isPresent()) {
        this.serverContainer.setDefaultMaxBinaryMessageBufferSize(intVal.get());
    }
    intVal = Optional.fromNullable(configuration.getMaxTextMessageBufferSize());
    if (intVal.isPresent()) {
        this.serverContainer.setDefaultMaxTextMessageBufferSize(intVal.get());
    }
}
项目:asity    文件:JwaServerWebSocketTest.java   
@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();
}
项目:hopsworks    文件:ApplicationListener.java   
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {

  ServletContext context = servletContextEvent.getServletContext();

  final ServerContainer serverContainer = (ServerContainer) context
          .getAttribute("javax.websocket.server.ServerContainer");

  try {

    context.setAttribute("protocol", new MetadataProtocol());

    //attach the WebSockets Endpoint to the web container
    serverContainer.addEndpoint(WebSocketEndpoint.class);

    logger.log(Level.INFO, "HOPSWORKS DEPLOYED");
  } catch (DeploymentException ex) {
    logger.log(Level.SEVERE, ex.getMessage(), ex);
  }
}
项目:diqube    文件:DiqubeServletContextListener.java   
@Override
public void contextInitialized(ServletContextEvent sce) {
  // initialize DiqubeServletConfig
  WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext());
  ctx.getBean(DiqubeServletConfig.class).initialize(sce.getServletContext());

  // register our Websocket Endpoint
  ServerContainer serverContainer = (ServerContainer) sce.getServletContext().getAttribute(ATTR_SERVER_CONTAINER);

  ServerEndpointConfig sec =
      ServerEndpointConfig.Builder.create(WebSocketEndpoint.class, WebSocketEndpoint.ENDPOINT_URL_MAPPING).build();
  sec.getUserProperties().put(WebSocketEndpoint.PROP_BEAN_CONTEXT, ctx);

  try {
    serverContainer.addEndpoint(sec);
  } catch (DeploymentException e) {
    throw new RuntimeException("DeploymentException when deploying Websocket endpoint", e);
  }
}
项目:sqlexplorer-vaadin    文件:DemoUI.java   
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();
}
项目:class-guard    文件:TestWsServerContainer.java   
@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);
    }
}
项目:class-guard    文件:TestWsWebSocketContainer.java   
@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);
    }
}
项目:activiti-websockets    文件:CustomActivitiServletContextListener.java   
public void addProcessEventsEndpoint(ServletContextEvent ce) {
    log.info("Deploying process-engine-events websockets server endpoint");
    ServletContext sc = ce.getServletContext();

    final ServerContainer server_container
            = (ServerContainer) ce.getServletContext().getAttribute("javax.websocket.server.ServerContainer");

    try {
        ServerEndpointConfig config
                = ServerEndpointConfig.Builder.create(ProcessEngineEventsWebsocket.class,
                        "/process-engine-events").build();
        config.getUserProperties().put("servlet.context", sc);
        server_container.addEndpoint(config);
    } catch (DeploymentException e) {
        throw new RuntimeException(e);
    }
}
项目:vibe-java-platform    文件:JwaServerWebSocketTest.java   
@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();
}
项目:apache-tomcat-7.0.57    文件:TestWsServerContainer.java   
@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);
    }
}
项目:apache-tomcat-7.0.57    文件:TestWsWebSocketContainer.java   
@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);
    }
}
项目:apache-tomcat-7.0.57    文件:TestWsServerContainer.java   
@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);
    }
}
项目:apache-tomcat-7.0.57    文件:TestWsWebSocketContainer.java   
@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);
    }
}
项目:ameba-container-grizzly    文件:GrizzlyContainer.java   
@Override
protected void registerBinder(ResourceConfig configuration) {
    super.registerBinder(configuration);
    if (webSocketEnabled) {
        webSocketServerContainer = new WebSocketServerContainer(getApplication());
        configuration.register(new AbstractBinder() {
            @Override
            protected void configure() {
                bindFactory((Supplier<ServerContainer>) () -> webSocketServerContainer)
                        .to(ServerContainer.class)
                        .to(WebSocketServerContainer.class);
                bind(TyrusWebSocketEndpointProvider.class)
                        .to(WebSocketEndpointProvider.class);
            }
        });
    }
}
项目:teavm    文件:ChromeRDPServer.java   
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);
    }
}
项目:Ka-Websocket    文件:Jsr365Registrator.java   
public void register(Class<?> webSocketPojo) {
    ServerContainer container = (ServerContainer) servletContext.getAttribute("javax.websocket.server.ServerContainer");

    EndpointConfigImpl clientConfig = configurationBuilder.configure(webSocketPojo);
    WebSocketConfig config = (WebSocketConfig) servletContext.getAttribute(WebSocketConfig.class.getName());
    config.registerEndpointConfig(clientConfig);

    WebSocket annotation = webSocketPojo.getAnnotation(WebSocket.class);
    if (annotation == null) {
        throw new WebSocketConfigException(webSocketPojo + " must be annotated with " + WebSocket.class);
    }

    ServerEndpointConfig serverConfig = ServerEndpointConfig.Builder.create(WebSocketClientJsr356.class, annotation.value())
                                                                        .configurator(new EndPointConfigurator(clientConfig))
                                                                        .subprotocols(getSubProtocols(webSocketPojo))
                                                                        .build();
    try {
        container.addEndpoint(serverConfig);
    } catch (DeploymentException e) {
        throw new WebSocketConfigException("Could not add websocket for " + webSocketPojo, e);
    }
}
项目:dagger    文件:WebSocketsFeature.java   
@Override
public void enable(ServletContext servletContext) {
    logger.info("Enabling feature");

    Module module = (Module) servletContext.getAttribute(Module.class.getName());
    ServerContainer serverContainer = (ServerContainer) servletContext.getAttribute(ServerContainer.class.getName());

    ServerEndpointConfig endpointConfig = ServerEndpointConfig.Builder.create(DaggerEndpoint.class, "/{anyPath}")
        .configurator(new DaggerEndpointConfigurator(module))
        .build();

    try {
        serverContainer.addEndpoint(endpointConfig);
    } catch (DeploymentException e) {
        logger.error("Error configuring websocket endpoint", e);
    }
}
项目:tomcat7    文件:TestWsSubprotocols.java   
@Override
public void contextInitialized(ServletContextEvent sce) {
    super.contextInitialized(sce);
    ServerContainer sc = (ServerContainer) sce.getServletContext()
            .getAttribute(Constants.
                    SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);
    try {
        sc.addEndpoint(SubProtocolsEndpoint.class);
    } catch (DeploymentException e) {
        throw new IllegalStateException(e);
    }
}
项目:tomcat7    文件:TesterUtil.java   
@Override
public void contextInitialized(ServletContextEvent sce) {
    super.contextInitialized(sce);
    ServerContainer sc =
            (ServerContainer) sce.getServletContext().getAttribute(
                    Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);
    try {
        sc.addEndpoint(pojoClazz);
    } catch (DeploymentException e) {
        throw new IllegalStateException(e);
    }
}
项目:tomcat7    文件:TestWsWebSocketContainer.java   
@Override
public void contextInitialized(ServletContextEvent sce) {
    super.contextInitialized(sce);
    ServerContainer sc =
            (ServerContainer) sce.getServletContext().getAttribute(
                    Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);
    try {
        // Reset blocking state
        BlockingPojo.resetBlock();
        sc.addEndpoint(BlockingPojo.class);
    } catch (DeploymentException e) {
        throw new IllegalStateException(e);
    }
}