@Override public void upgradeInternal(ServerHttpRequest request, ServerHttpResponse response, @Nullable String selectedProtocol, List<Extension> selectedExtensions, Endpoint endpoint) throws HandshakeFailureException { HttpServletRequest servletRequest = getHttpServletRequest(request); HttpServletResponse servletResponse = getHttpServletResponse(response); StringBuffer requestUrl = servletRequest.getRequestURL(); String path = servletRequest.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 { getContainer(servletRequest).doUpgrade(servletRequest, servletResponse, endpointConfig, pathParams); } catch (ServletException ex) { throw new HandshakeFailureException( "Servlet request failed to upgrade to WebSocket: " + requestUrl, ex); } catch (IOException ex) { throw new HandshakeFailureException( "Response update failed during upgrade to WebSocket: " + requestUrl, ex); } }
if (!sc.areEndpointsRegistered() || !UpgradeUtil.isWebSocketUpgradeRequest(request, response)) { chain.doFilter(request, response); path = req.getServletPath() + pathInfo; WsMappingResult mappingResult = sc.findMapping(path);
validateEncoders(annotation.encoders()); build(); addEndpoint(sec);
public WsRemoteEndpointImplServer(AbstractServletOutputStream sos, WsServerContainer serverContainer) { this.sos = sos; this.wsWriteTimeout = serverContainer.getTimeout(); this.executorService = serverContainer.getExecutorService(); }
@Override public void contextDestroyed(ServletContextEvent sce) { ServletContext sc = sce.getServletContext(); Object obj = sc.getAttribute(Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE); if (obj instanceof WsServerContainer) { ((WsServerContainer) obj).shutdownExecutor(); ((WsServerContainer) obj).destroy(); } } }
@Override public void sessionDestroyed(HttpSessionEvent se) { wsServerContainer.closeAuthenticatedSession(se.getSession().getId()); } }
static WsServerContainer init(ServletContext servletContext, boolean initBySciMechanism) { WsServerContainer sc = new WsServerContainer(servletContext); servletContext.setAttribute( Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE, sc); servletContext.addListener(new WsSessionListener(sc)); // Can't register the ContextListener again if the ContextListener is // calling this method if (initBySciMechanism) { servletContext.addListener(new WsContextListener()); } return sc; } }
/** * {@inheritDoc} * * Overridden to make it visible to other classes in this package. */ @Override protected void registerSession(Endpoint endpoint, WsSession wsSession) { super.registerSession(endpoint, wsSession); if (wsSession.isOpen() && wsSession.getUserPrincipal() != null && wsSession.getHttpSessionId() != null) { registerAuthenticatedSession(wsSession, wsSession.getHttpSessionId()); } }
webSocketContainer.registerSession(ep, wsSession); } catch (DeploymentException e) { throw new IllegalArgumentException(e);
sc.addEndpoint(config); sc.addEndpoint(clazz);
@Override public void contextDestroyed(ServletContextEvent sce) { ServletContext sc = sce.getServletContext(); Object obj = sc.getAttribute(Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE); if (obj instanceof WsServerContainer) { ((WsServerContainer) obj).destroy(); } } }
public WsRemoteEndpointImplServer(SocketWrapperBase<?> socketWrapper, WsServerContainer serverContainer) { this.socketWrapper = socketWrapper; this.wsWriteTimeout = serverContainer.getTimeout(); }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // This filter only needs to handle WebSocket upgrade requests if (!sc.areEndpointsRegistered() || !UpgradeUtil.isWebSocketUpgradeRequest(request, response)) { chain.doFilter(request, response); return; } // HTTP request with an upgrade header for WebSocket present HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; // Check to see if this WebSocket implementation has a matching mapping String path; String pathInfo = req.getPathInfo(); if (pathInfo == null) { path = req.getServletPath(); } else { path = req.getServletPath() + pathInfo; } WsMappingResult mappingResult = sc.findMapping(path); if (mappingResult == null) { // No endpoint registered for the requested path. Let the // application handle it (it might redirect or forward for example) chain.doFilter(request, response); return; } UpgradeUtil.doUpgrade(sc, req, resp, mappingResult.getConfig(), mappingResult.getPathParams()); }
validateEncoders(annotation.encoders()); build(); addEndpoint(sec);
public WsRemoteEndpointImplServer(ServletOutputStream sos, WsServerContainer serverContainer) { this.sos = sos; this.wsWriteTimeout = serverContainer.getTimeout(); this.executorService = serverContainer.getExecutorService(); }
@Override public void sessionDestroyed(HttpSessionEvent se) { wsServerContainer.closeAuthenticatedSession(se.getSession().getId()); } }
static WsServerContainer init(ServletContext servletContext, boolean initBySciMechanism) { WsServerContainer sc = new WsServerContainer(servletContext); servletContext.setAttribute( Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE, sc); servletContext.addListener(new WsSessionListener(sc)); // Can't register the ContextListener again if the ContextListener is // calling this method if (initBySciMechanism) { servletContext.addListener(new WsContextListener()); } return sc; }
/** * {@inheritDoc} * * Overridden to make it visible to other classes in this package. */ @Override protected void registerSession(Endpoint endpoint, WsSession wsSession) { super.registerSession(endpoint, wsSession); if (wsSession.isOpen() && wsSession.getUserPrincipal() != null && wsSession.getHttpSessionId() != null) { registerAuthenticatedSession(wsSession, wsSession.getHttpSessionId()); } }
webSocketContainer.registerSession(ep, wsSession); } catch (DeploymentException e) { throw new IllegalArgumentException(e);
sc.addEndpoint(config); sc.addEndpoint(clazz);