本文整理匯總了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);
}
示例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()");
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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());
}
}
示例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);
}
}
示例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());
}
}