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