本文整理汇总了Java中javax.websocket.server.ServerEndpointConfig类的典型用法代码示例。如果您正苦于以下问题:Java ServerEndpointConfig类的具体用法?Java ServerEndpointConfig怎么用?Java ServerEndpointConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServerEndpointConfig类属于javax.websocket.server包,在下文中一共展示了ServerEndpointConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onOpen
import javax.websocket.server.ServerEndpointConfig; //导入依赖的package包/类
@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {
ServerEndpointConfig sec = (ServerEndpointConfig) endpointConfig;
Object pojo;
try {
pojo = sec.getConfigurator().getEndpointInstance(sec.getEndpointClass());
} catch (InstantiationException e) {
throw new IllegalArgumentException(
sm.getString("pojoEndpointServer.getPojoInstanceFail", sec.getEndpointClass().getName()), e);
}
setPojo(pojo);
@SuppressWarnings("unchecked")
Map<String, String> pathParameters = (Map<String, String>) sec.getUserProperties().get(POJO_PATH_PARAM_KEY);
setPathParameters(pathParameters);
PojoMethodMapping methodMapping = (PojoMethodMapping) sec.getUserProperties().get(POJO_METHOD_MAPPING_KEY);
setMethodMapping(methodMapping);
doOnOpen(session, endpointConfig);
}
示例2: contextInitialized
import javax.websocket.server.ServerEndpointConfig; //导入依赖的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);
}
}
}
示例3: setWebSocketEndpoints
import javax.websocket.server.ServerEndpointConfig; //导入依赖的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);
}
示例4: configureEndpoint
import javax.websocket.server.ServerEndpointConfig; //导入依赖的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()");
}
示例5: contextInitialized
import javax.websocket.server.ServerEndpointConfig; //导入依赖的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.ServerEndpointConfig; //导入依赖的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);
}
}
示例7: testSpecExample3
import javax.websocket.server.ServerEndpointConfig; //导入依赖的package包/类
@Test
public void testSpecExample3() throws Exception {
WsServerContainer sc =
new WsServerContainer(new TesterServletContext());
ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(
Object.class, "/a/{var}/c").build();
ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(
Object.class, "/a/b/c").build();
ServerEndpointConfig configC = ServerEndpointConfig.Builder.create(
Object.class, "/a/{var1}/{var2}").build();
sc.addEndpoint(configA);
sc.addEndpoint(configB);
sc.addEndpoint(configC);
Assert.assertEquals(configB, sc.findMapping("/a/b/c").getConfig());
Assert.assertEquals(configA, sc.findMapping("/a/d/c").getConfig());
Assert.assertEquals(configC, sc.findMapping("/a/x/y").getConfig());
}
示例8: testDuplicatePaths_04
import javax.websocket.server.ServerEndpointConfig; //导入依赖的package包/类
@Test
public void testDuplicatePaths_04() throws Exception {
WsServerContainer sc =
new WsServerContainer(new TesterServletContext());
ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(
Object.class, "/a/{var1}/{var2}").build();
ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(
Object.class, "/a/b/{var2}").build();
sc.addEndpoint(configA);
sc.addEndpoint(configB);
Assert.assertEquals(configA, sc.findMapping("/a/x/y").getConfig());
Assert.assertEquals(configB, sc.findMapping("/a/b/y").getConfig());
}
示例9: contextInitialized
import javax.websocket.server.ServerEndpointConfig; //导入依赖的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);
}
}
示例10: contextInitialized
import javax.websocket.server.ServerEndpointConfig; //导入依赖的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);
}
}
示例11: contextInitialized
import javax.websocket.server.ServerEndpointConfig; //导入依赖的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);
}
}
示例12: getEndpointConfigs
import javax.websocket.server.ServerEndpointConfig; //导入依赖的package包/类
@Override
public Set<ServerEndpointConfig> getEndpointConfigs(
Set<Class<? extends Endpoint>> scanned) {
Set<ServerEndpointConfig> result = new HashSet<ServerEndpointConfig>();
if (scanned.contains(EchoEndpoint.class)) {
result.add(ServerEndpointConfig.Builder.create(
EchoEndpoint.class,
"/websocket/echoProgrammatic").build());
}
if (scanned.contains(DrawboardEndpoint.class)) {
result.add(ServerEndpointConfig.Builder.create(
DrawboardEndpoint.class,
"/websocket/drawboard").build());
}
return result;
}
示例13: addEndpoint
import javax.websocket.server.ServerEndpointConfig; //导入依赖的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);
}
}
示例14: registerEndpoints
import javax.websocket.server.ServerEndpointConfig; //导入依赖的package包/类
/**
* Actually register the endpoints. Called by {@link #afterSingletonsInstantiated()}.
*/
protected void registerEndpoints() {
Set<Class<?>> endpointClasses = new LinkedHashSet<Class<?>>();
if (this.annotatedEndpointClasses != null) {
endpointClasses.addAll(this.annotatedEndpointClasses);
}
ApplicationContext context = getApplicationContext();
if (context != null) {
String[] endpointBeanNames = context.getBeanNamesForAnnotation(ServerEndpoint.class);
for (String beanName : endpointBeanNames) {
endpointClasses.add(context.getType(beanName));
}
}
for (Class<?> endpointClass : endpointClasses) {
registerEndpoint(endpointClass);
}
if (context != null) {
Map<String, ServerEndpointConfig> endpointConfigMap = context.getBeansOfType(ServerEndpointConfig.class);
for (ServerEndpointConfig endpointConfig : endpointConfigMap.values()) {
registerEndpoint(endpointConfig);
}
}
}
示例15: modifyHandshake
import javax.websocket.server.ServerEndpointConfig; //导入依赖的package包/类
@Override
public void modifyHandshake(ServerEndpointConfig config,
HandshakeRequest request, HandshakeResponse response) {
HttpSession httpSession = (HttpSession) request.getHttpSession();
super.modifyHandshake(config, request, response);
if (httpSession == null) {
LOGGER.info("httpSession == null after modifyHandshake");
httpSession = (HttpSession) request.getHttpSession();
}
if (httpSession == null) {
LOGGER.info("httpSession == null");
return;
}
config.getUserProperties().put("httpSession", httpSession);
httpSession = (HttpSession) request.getHttpSession();
LOGGER.info("modifyHandshake " + httpSession.getId());
}