當前位置: 首頁>>代碼示例>>Java>>正文


Java ServerContainer.addEndpoint方法代碼示例

本文整理匯總了Java中javax.websocket.server.ServerContainer.addEndpoint方法的典型用法代碼示例。如果您正苦於以下問題:Java ServerContainer.addEndpoint方法的具體用法?Java ServerContainer.addEndpoint怎麽用?Java ServerContainer.addEndpoint使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.websocket.server.ServerContainer的用法示例。


在下文中一共展示了ServerContainer.addEndpoint方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setWebSocketEndpoints

import javax.websocket.server.ServerContainer; //導入方法依賴的package包/類
/**
 *
 * @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);
}
 
開發者ID:OpenChatAlytics,項目名稱:OpenChatAlytics,代碼行數:26,代碼來源:ServerMain.java

示例2: contextInitialized

import javax.websocket.server.ServerContainer; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:19,代碼來源:TestWsRemoteEndpointImplServer.java

示例3: contextInitialized

import javax.websocket.server.ServerContainer; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:17,代碼來源:TesterEchoServer.java

示例4: contextInitialized

import javax.websocket.server.ServerContainer; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:17,代碼來源:TestWsWebSocketContainer.java

示例5: contextInitialized

import javax.websocket.server.ServerContainer; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:17,代碼來源:TestCloseBug58624.java

示例6: contextInitialized

import javax.websocket.server.ServerContainer; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:19,代碼來源:TestClose.java

示例7: contextInitialized

import javax.websocket.server.ServerContainer; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:18,代碼來源:TestWsServerContainer.java

示例8: contextInitialized

import javax.websocket.server.ServerContainer; //導入方法依賴的package包/類
@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);
		}
	}
}
 
開發者ID:jkiddo,項目名稱:ccow,代碼行數:20,代碼來源:CCOWContextListener.java

示例9: addEndpoint

import javax.websocket.server.ServerContainer; //導入方法依賴的package包/類
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);
    }
  }
 
開發者ID:jkiddo,項目名稱:ccow,代碼行數:20,代碼來源:WebSocketsModule.java

示例10: createComputeRealtimeServer

import javax.websocket.server.ServerContainer; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:OpenChatAlytics,項目名稱:OpenChatAlytics,代碼行數:27,代碼來源:ComputeRealtimeServerFactory.java

示例11: contextInitialized

import javax.websocket.server.ServerContainer; //導入方法依賴的package包/類
@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());
    }
}
 
開發者ID:CenturyLinkCloud,項目名稱:mdw,代碼行數:20,代碼來源:StartupListener.java

示例12: start

import javax.websocket.server.ServerContainer; //導入方法依賴的package包/類
/**
 * 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);
	}
}
 
開發者ID:proteus-h2020,項目名稱:proteus-incremental-analytics,代碼行數:29,代碼來源:WebsocketServer.java

示例13: startServer

import javax.websocket.server.ServerContainer; //導入方法依賴的package包/類
@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();
}
 
開發者ID:cettia,項目名稱:asity,代碼行數:23,代碼來源:JwaServerWebSocketTest.java

示例14: contextInitialized

import javax.websocket.server.ServerContainer; //導入方法依賴的package包/類
@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);
  }
}
 
開發者ID:hopshadoop,項目名稱:hopsworks,代碼行數:21,代碼來源:ApplicationListener.java

示例15: contextInitialized

import javax.websocket.server.ServerContainer; //導入方法依賴的package包/類
@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);
  }
}
 
開發者ID:diqube,項目名稱:diqube,代碼行數:20,代碼來源:DiqubeServletContextListener.java


注:本文中的javax.websocket.server.ServerContainer.addEndpoint方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。