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


Java ServerContainer類代碼示例

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


ServerContainer類屬於javax.websocket.server包,在下文中一共展示了ServerContainer類的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: configureEndpoint

import javax.websocket.server.ServerContainer; //導入依賴的package包/類
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()");
}
 
開發者ID:isapir,項目名稱:lucee-websocket,代碼行數:22,代碼來源:Configurator.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);

    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

示例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(
            TesterEchoServer.Basic.class, "/{param}").build();

    try {
        sc.addEndpoint(sec);
    } catch (DeploymentException e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:18,代碼來源:TestWsServerContainer.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);

    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:liaokailin,項目名稱:tomcat7,代碼行數:19,代碼來源:TestWsRemoteEndpointImplServer.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(
            getEndpointClass(), PATH).build();

    try {
        sc.addEndpoint(sec);
    } catch (DeploymentException e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:19,代碼來源:TestClose.java

示例8: 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:liaokailin,項目名稱:tomcat7,代碼行數:17,代碼來源:TestWsWebSocketContainer.java

示例9: 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

示例10: 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

示例11: upgradeInternal

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

示例12: 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

示例13: 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

示例14: 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

示例15: WebsocketContainer

import javax.websocket.server.ServerContainer; //導入依賴的package包/類
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());
    }
}
 
開發者ID:TomCools,項目名稱:dropwizard-websocket-jee7-bundle,代碼行數:21,代碼來源:WebsocketContainer.java


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