public final static boolean firefoxWebSocketEnabled(HttpServletRequest request) { return webSocketEnabled(request) && request.getHeader(HeaderConfig.X_ATMO_PROTOCOL) != null && request.getHeader(HeaderConfig.X_ATMO_PROTOCOL).equals("true") && request.getHeader("User-Agent") != null && request.getHeader("User-Agent").toLowerCase().indexOf("firefox") != -1; }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest r = HttpServletRequest.class.cast(request); if (Utils.webSocketEnabled(r)) { int draft = r.getIntHeader(WEBSOCKET_VERSION); if (draft < 0) { draft = r.getIntHeader("Sec-WebSocket-Draft"); } if (bannedVersion != null) { for (String s : bannedVersion) { if (Integer.parseInt(s) == draft) { logger.trace("Invalid WebSocket Specification {} with {} ", r.getHeader("Connection"), r.getIntHeader(WEBSOCKET_VERSION)); HttpServletResponse.class.cast(response).addHeader(X_ATMOSPHERE_ERROR, "Websocket protocol not supported"); HttpServletResponse.class.cast(response).sendError(501, "Websocket protocol not supported"); return; } } } } chain.doFilter(request, response); }
@Override public void requestInitialized(ServletRequestEvent sre) { HttpServletRequest r = HttpServletRequest.class.cast(sre.getServletRequest()); AtmosphereConfig config = framework.getAtmosphereConfig(); if (config.isSupportSession() && Utils.webSocketEnabled(r)) { r.getSession(config.getInitParameter(ApplicationConfig.PROPERTY_SESSION_CREATE, true)); } } });
/** * Suspend the connection by invoking {@link AtmosphereRequestImpl#startAsync()} * * @param action The {@link org.atmosphere.runtime.Action} * @param req the {@link AtmosphereRequest} * @param res the {@link AtmosphereResponse} * @throws java.io.IOException * @throws javax.servlet.ServletException */ private void suspend(Action action, AtmosphereRequest req, AtmosphereResponse res) throws IOException, ServletException { if (!req.isAsyncStarted() && !Utils.webSocketEnabled(req)) { AsyncContext asyncContext = req.startAsync(req, res); asyncContext.addListener(new CometListener(this, res.uuid())); // Do nothing except setting the times out if (action.timeout() != -1) { asyncContext.setTimeout(action.timeout()); } else { // Jetty 8 does something really weird if you set it to // Long.MAX_VALUE, which is to resume automatically. asyncContext.setTimeout(Integer.MAX_VALUE); } req.setAttribute(FrameworkConfig.ASYNC_CONTEXT, asyncContext); } }
if (Utils.webSocketEnabled(req) && !supportWebSocket()) { logger.warn("Websocket protocol not supported"); res.setStatus(501);
public static boolean useAtmosphere(HttpServletRequest req) { return Utils.webSocketEnabled(req) || req.getParameter(HeaderConfig.X_ATMOSPHERE_TRANSPORT) != null; } }
public static boolean useAtmosphere(HttpServletRequest req) { return Utils.webSocketEnabled(req) || req.getParameter(HeaderConfig.X_ATMOSPHERE_TRANSPORT) != null; } }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest r = HttpServletRequest.class.cast(request); if (Utils.webSocketEnabled(r)) { String header = r.getHeader(SEC_WEB_SOCKET_PROTOCOL_HEADER); if(header != null && !header.isEmpty()) { if(supportedProtocols.contains(header.toLowerCase())) { HttpServletResponse.class.cast(response).addHeader(SEC_WEB_SOCKET_PROTOCOL_HEADER, URLEncoder.encode(header, URL_ENCODER_ENCODING)); } else { LOG.warn("Invalid websocket protocol [{}] received.", header); HttpServletResponse.class.cast(response).sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "Websocket protocol not supported"); } } } chain.doFilter(request, response); }