container.addEndpoint( ServerEndpointConfig.Builder .create(
@Override public void addEndpoint(Class<?> endpointClass) throws DeploymentException { if (isStarted() || isStarting()) { ServerEndpointMetadata metadata = getServerEndpointMetadata(endpointClass,null); addEndpoint(metadata); } else { if (deferredEndpointClasses == null) { deferredEndpointClasses = new ArrayList<Class<?>>(); } deferredEndpointClasses.add(endpointClass); } }
configureContext.getWebSocketServerFactory().getExtensionFactory().unregister("permessage-deflate"); configureContext.addEndpoint(Jsr356Impl.class); } catch (ServletException e) { e.printStackTrace();
@Override public void onSessionOpened(WebSocketSession session) { getWebSocketServerFactory().onSessionOpened(session); }
public static ServerContainer configureContext(final MutableServletContextHandler context, final MetricRegistry metrics) throws ServletException { WebSocketUpgradeFilter filter = WebSocketUpgradeFilter.configureContext(context); NativeWebSocketConfiguration wsConfig = filter.getConfiguration(); ServerContainer wsContainer = new ServerContainer(wsConfig, context.getServer().getThreadPool()); EventDriverFactory edf = wsConfig.getFactory().getEventDriverFactory(); edf.clearImplementations(); edf.addImplementation(new InstJsrServerEndpointImpl(metrics)); edf.addImplementation(new InstJsrServerExtendsEndpointImpl(metrics)); context.addBean(wsContainer); context.setAttribute(javax.websocket.server.ServerContainer.class.getName(), wsContainer); context.setAttribute(WebSocketUpgradeFilter.class.getName(), filter); return wsContainer; } }
public EndpointInstance newClientEndpointInstance(Object endpoint, ServerEndpointConfig config, String path) { EndpointMetadata metadata = getClientEndpointMetadata(endpoint.getClass(),config); ServerEndpointConfig cec = config; if (config == null) { if (metadata instanceof AnnotatedServerEndpointMetadata) { cec = ((AnnotatedServerEndpointMetadata)metadata).getConfig(); } else { cec = new BasicServerEndpointConfig(this,endpoint.getClass(),path); } } return new EndpointInstance(endpoint,cec,metadata); }
/** * * @param configuration the {@link NativeWebSocketConfiguration} to use * @param httpClient the {@link HttpClient} instance to use */ public ServerContainer(NativeWebSocketConfiguration configuration, HttpClient httpClient) { super(configuration.getFactory(), httpClient); this.configuration = configuration; EventDriverFactory eventDriverFactory = this.configuration.getFactory().getEventDriverFactory(); eventDriverFactory.addImplementation(new JsrServerEndpointImpl()); eventDriverFactory.addImplementation(new JsrServerExtendsEndpointImpl()); this.configuration.getFactory().addSessionFactory(new JsrSessionFactory(this)); addBean(this.configuration); }
@Override public void addEndpoint(ServerEndpointConfig config) throws DeploymentException { if (isStarted() || isStarting()) { if (LOG.isDebugEnabled()) { LOG.debug("addEndpoint({}) path={} endpoint={}",config,config.getPath(),config.getEndpointClass()); } ServerEndpointMetadata metadata = getServerEndpointMetadata(config.getEndpointClass(),config); addEndpoint(metadata); } else { if (deferredEndpointConfigs == null) { deferredEndpointConfigs = new ArrayList<ServerEndpointConfig>(); } deferredEndpointConfigs.add(config); } }
@Override public Set<Session> getOpenSessions() { return new HashSet<>(getWebSocketServerFactory().getBeans(Session.class)); } }
public static ServerContainer configureContext(final MutableServletContextHandler context, final MetricRegistry metrics) throws ServletException { WebSocketUpgradeFilter filter = WebSocketUpgradeFilter.configureContext(context); NativeWebSocketConfiguration wsConfig = filter.getConfiguration(); ServerContainer wsContainer = new ServerContainer(wsConfig, context.getServer().getThreadPool()); EventDriverFactory edf = wsConfig.getFactory().getEventDriverFactory(); edf.clearImplementations(); edf.addImplementation(new InstJsrServerEndpointImpl(metrics)); edf.addImplementation(new InstJsrServerExtendsEndpointImpl(metrics)); context.addBean(wsContainer); context.setAttribute(javax.websocket.server.ServerContainer.class.getName(), wsContainer); context.setAttribute(WebSocketUpgradeFilter.class.getName(), filter); return wsContainer; } }
/** * Add a Web socket endpoint. */ public void addEndpoint(ServerEndpointConfig endpointConfig) throws DeploymentException { if (serverContainer == null) { webSocketEndpoints.add(endpointConfig); } else { serverContainer.addEndpoint(endpointConfig); } }
@Override public void onSessionClosed(WebSocketSession session) { getWebSocketServerFactory().onSessionClosed(session); }
ServerContainer jettyContainer = new ServerContainer(nativeWebSocketConfiguration, httpClient); context.addBean(jettyContainer);
@Override protected void doStart() throws Exception { // Proceed with Normal Startup super.doStart(); // Process Deferred Endpoints if (deferredEndpointClasses != null) { for (Class<?> endpointClass : deferredEndpointClasses) { addEndpoint(endpointClass); } deferredEndpointClasses.clear(); } if (deferredEndpointConfigs != null) { for (ServerEndpointConfig config : deferredEndpointConfigs) { addEndpoint(config); } deferredEndpointConfigs.clear(); } }
private void addEndpoint(ServerContainer wsContainer, ServerEndpointConfig conf, StringBuilder sb) throws DeploymentException { wsContainer.addEndpoint(conf); sb.append(String.format(" WS %s (%s)", conf.getPath(), conf.getEndpointClass().getName())).append(System.lineSeparator()); } });
private void addEndpoint(ServerContainer wsContainer, ServerEndpointConfig conf, StringBuilder sb) throws DeploymentException { wsContainer.addEndpoint(conf); sb.append(String.format(" WS %s (%s)", conf.getPath(), conf.getEndpointClass().getName())).append(System.lineSeparator()); } });
container.addEndpoint(JsrBrowserSocket.class);
protected void initServer() { server = new Server(httpPort); attachServerLifecycleListeners(); server.setHandler(wrapHandlers()); if (isWebSocketInClassPath()) { setupForWebSocket(); try { for (ServerEndpointConfig endpoint : webSocketEndpoints) { log().debug("add WebSocket endpoint " + endpoint); serverContainer.addEndpoint(endpoint); } } catch (DeploymentException e) { throw new IllegalStateException("Failed to add webSocket endpoint", e); } } }
jettyContainer.addEndpoint(config); jettyContainer.addEndpoint(annotatedClass);
serverContainer.addEndpoint(serverEndpointConfig);