public void doUpgrade(HttpServletRequest request, HttpServletResponse response, ServerEndpointConfig sec, Map<String,String> pathParams) throws ServletException, IOException { UpgradeUtil.doUpgrade(this, request, response, sec, pathParams); }
/** * Checks to see if this is an HTTP request that includes a valid upgrade * request to web socket. * <p> * Note: RFC 2616 does not limit HTTP upgrade to GET requests but the Java * WebSocket spec 1.0, section 8.2 implies such a limitation and RFC * 6455 section 4.1 requires that a WebSocket Upgrade uses GET. */ public static boolean isWebSocketUpgradeRequest(ServletRequest request, ServletResponse response) { return ((request instanceof HttpServletRequest) && (response instanceof HttpServletResponse) && headerContainsToken((HttpServletRequest) request, Constants.UPGRADE_HEADER_NAME, Constants.UPGRADE_HEADER_VALUE) && "GET".equals(((HttpServletRequest) request).getMethod())); }
if (!headerContainsToken(req, Constants.CONNECTION_HEADER_NAME, Constants.CONNECTION_HEADER_VALUE)) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST); return; if (!headerContainsToken(req, Constants.WS_VERSION_HEADER_NAME, Constants.WS_VERSION_HEADER_VALUE)) { resp.setStatus(426); List<String> subProtocols = getTokensFromHeader(req, Constants.WS_PROTOCOL_HEADER_NAME); subProtocol = sec.getConfigurator().getNegotiatedSubprotocol( List<Transformation> transformations = createTransformations(negotiatedExtensionsPhase1); responseHeaderExtensions.append(','); append(responseHeaderExtensions, t.getExtensionResponse()); if (transformation == null) { transformation = t; Constants.CONNECTION_HEADER_VALUE); resp.setHeader(HandshakeResponse.SEC_WEBSOCKET_ACCEPT, getWebSocketAccept(key)); if (subProtocol != null && subProtocol.length() > 0) {
!UpgradeUtil.isWebSocketUpgradeRequest(request, response)) { chain.doFilter(request, response); return; UpgradeUtil.doUpgrade(sc, req, resp, mappingResult.getConfig(), mappingResult.getPathParams());
String subProtocol = null; List<Extension> extensions = Collections.emptyList(); if (!headerContainsToken(req, Constants.CONNECTION_HEADER_NAME, Constants.CONNECTION_HEADER_VALUE)) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST); return; if (!headerContainsToken(req, Constants.WS_VERSION_HEADER_NAME, Constants.WS_VERSION_HEADER_VALUE)) { resp.setStatus(426); List<String> subProtocols = getTokensFromHeader(req, "Sec-WebSocket-Protocol"); if (!subProtocols.isEmpty()) { Constants.CONNECTION_HEADER_VALUE); resp.setHeader(HandshakeResponse.SEC_WEBSOCKET_ACCEPT, getWebSocketAccept(key)); if (subProtocol != null) { resp.setHeader("Sec-WebSocket-Protocol", subProtocol);
if (!headerContainsToken(req, Constants.CONNECTION_HEADER_NAME, Constants.CONNECTION_HEADER_VALUE)) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST); return; if (!headerContainsToken(req, Constants.WS_VERSION_HEADER_NAME, Constants.WS_VERSION_HEADER_VALUE)) { resp.setStatus(426); List<String> subProtocols = getTokensFromHeader(req, Constants.WS_PROTOCOL_HEADER_NAME); subProtocol = sec.getConfigurator().getNegotiatedSubprotocol( List<Transformation> transformations = createTransformations(negotiatedExtensionsPhase1); responseHeaderExtensions.append(','); append(responseHeaderExtensions, t.getExtensionResponse()); if (transformation == null) { transformation = t; Constants.CONNECTION_HEADER_VALUE); resp.setHeader(HandshakeResponse.SEC_WEBSOCKET_ACCEPT, getWebSocketAccept(key)); if (subProtocol != null && subProtocol.length() > 0) {
@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()); }
if (!headerContainsToken(req, Constants.CONNECTION_HEADER_NAME, Constants.CONNECTION_HEADER_VALUE)) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST); return; if (!headerContainsToken(req, Constants.WS_VERSION_HEADER_NAME, Constants.WS_VERSION_HEADER_VALUE)) { resp.setStatus(426); List<String> subProtocols = getTokensFromHeader(req, Constants.WS_PROTOCOL_HEADER_NAME); subProtocol = sec.getConfigurator().getNegotiatedSubprotocol( List<Transformation> transformations = createTransformations(negotiatedExtensionsPhase1); responseHeaderExtensions.append(','); append(responseHeaderExtensions, t.getExtensionResponse()); if (transformation == null) { transformation = t; Constants.CONNECTION_HEADER_VALUE); resp.setHeader(HandshakeResponse.SEC_WEBSOCKET_ACCEPT, getWebSocketAccept(key)); if (subProtocol != null && subProtocol.length() > 0) {
@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()); }
public void doUpgrade(HttpServletRequest request, HttpServletResponse response, ServerEndpointConfig sec, Map<String,String> pathParams) throws ServletException, IOException { UpgradeUtil.doUpgrade(this, request, response, sec, pathParams); }
/** * Checks to see if this is an HTTP request that includes a valid upgrade * request to web socket. * <p> * Note: RFC 2616 does not limit HTTP upgrade to GET requests but the Java * WebSocket spec 1.0, section 8.2 implies such a limitation and RFC * 6455 section 4.1 requires that a WebSocket Upgrade uses GET. */ public static boolean isWebSocketUpgradeRequest(ServletRequest request, ServletResponse response) { return ((request instanceof HttpServletRequest) && (response instanceof HttpServletResponse) && headerContainsToken((HttpServletRequest) request, Constants.UPGRADE_HEADER_NAME, Constants.UPGRADE_HEADER_VALUE) && "GET".equals(((HttpServletRequest) request).getMethod())); }
if (!headerContainsToken(req, Constants.CONNECTION_HEADER_NAME, Constants.CONNECTION_HEADER_VALUE)) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST); return; if (!headerContainsToken(req, Constants.WS_VERSION_HEADER_NAME, Constants.WS_VERSION_HEADER_VALUE)) { resp.setStatus(426); List<String> subProtocols = getTokensFromHeader(req, Constants.WS_PROTOCOL_HEADER_NAME); subProtocol = sec.getConfigurator().getNegotiatedSubprotocol( List<Transformation> transformations = createTransformations(negotiatedExtensionsPhase1); responseHeaderExtensions.append(','); append(responseHeaderExtensions, t.getExtensionResponse()); if (transformation == null) { transformation = t; Constants.CONNECTION_HEADER_VALUE); resp.setHeader(HandshakeResponse.SEC_WEBSOCKET_ACCEPT, getWebSocketAccept(key)); if (subProtocol != null && subProtocol.length() > 0) {
@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()); }
/** * Until the WebSocket specification provides such a mechanism, this Tomcat * proprietary method is provided to enable applications to programmatically * determine whether or not to upgrade an individual request to WebSocket. * <p> * Note: This method is not used by Tomcat but is used directly by * third-party code and must not be removed. * * @param request The request object to be upgraded * @param response The response object to be populated with the result of * the upgrade * @param sec The server endpoint to use to process the upgrade request * @param pathParams The path parameters associated with the upgrade request * * @throws ServletException If a configuration error prevents the upgrade * from taking place * @throws IOException If an I/O error occurs during the upgrade process */ public void doUpgrade(HttpServletRequest request, HttpServletResponse response, ServerEndpointConfig sec, Map<String,String> pathParams) throws ServletException, IOException { UpgradeUtil.doUpgrade(this, request, response, sec, pathParams); }
/** * Checks to see if this is an HTTP request that includes a valid upgrade * request to web socket. * <p> * Note: RFC 2616 does not limit HTTP upgrade to GET requests but the Java * WebSocket spec 1.0, section 8.2 implies such a limitation and RFC * 6455 section 4.1 requires that a WebSocket Upgrade uses GET. */ public static boolean isWebSocketUpgradeRequest(ServletRequest request, ServletResponse response) { return ((request instanceof HttpServletRequest) && (response instanceof HttpServletResponse) && headerContainsToken((HttpServletRequest) request, Constants.UPGRADE_HEADER_NAME, Constants.UPGRADE_HEADER_VALUE) && "GET".equals(((HttpServletRequest) request).getMethod())); }
!UpgradeUtil.isWebSocketUpgradeRequest(request, response)) { chain.doFilter(request, response); return; UpgradeUtil.doUpgrade(sc, req, resp, mappingResult.getConfig(), mappingResult.getPathParams());
/** * Until the WebSocket specification provides such a mechanism, this Tomcat * proprietary method is provided to enable applications to programmatically * determine whether or not to upgrade an individual request to WebSocket. * <p> * Note: This method is not used by Tomcat but is used directly by * third-party code and must not be removed. * * @param request The request object to be upgraded * @param response The response object to be populated with the result of * the upgrade * @param sec The server endpoint to use to process the upgrade request * @param pathParams The path parameters associated with the upgrade request * * @throws ServletException If a configuration error prevents the upgrade * from taking place * @throws IOException If an I/O error occurs during the upgrade process */ public void doUpgrade(HttpServletRequest request, HttpServletResponse response, ServerEndpointConfig sec, Map<String,String> pathParams) throws ServletException, IOException { UpgradeUtil.doUpgrade(this, request, response, sec, pathParams); }
/** * Checks to see if this is an HTTP request that includes a valid upgrade * request to web socket. * <p> * Note: RFC 2616 does not limit HTTP upgrade to GET requests but the Java * WebSocket spec 1.0, section 8.2 implies such a limitation and RFC * 6455 section 4.1 requires that a WebSocket Upgrade uses GET. * @param request The request to check if it is an HTTP upgrade request for * a WebSocket connection * @param response The response associated with the request * @return <code>true</code> if the request includes a HTTP Upgrade request * for the WebSocket protocol, otherwise <code>false</code> */ public static boolean isWebSocketUpgradeRequest(ServletRequest request, ServletResponse response) { return ((request instanceof HttpServletRequest) && (response instanceof HttpServletResponse) && headerContainsToken((HttpServletRequest) request, Constants.UPGRADE_HEADER_NAME, Constants.UPGRADE_HEADER_VALUE) && "GET".equals(((HttpServletRequest) request).getMethod())); }
/** * Until the WebSocket specification provides such a mechanism, this Tomcat * proprietary method is provided to enable applications to programmatically * determine whether or not to upgrade an individual request to WebSocket. * <p> * Note: This method is not used by Tomcat but is used directly by * third-party code and must not be removed. * * @param request The request object to be upgraded * @param response The response object to be populated with the result of * the upgrade * @param sec The server endpoint to use to process the upgrade request * @param pathParams The path parameters associated with the upgrade request * * @throws ServletException If a configuration error prevents the upgrade * from taking place * @throws IOException If an I/O error occurs during the upgrade process */ public void doUpgrade(HttpServletRequest request, HttpServletResponse response, ServerEndpointConfig sec, Map<String,String> pathParams) throws ServletException, IOException { UpgradeUtil.doUpgrade(this, request, response, sec, pathParams); }
/** * Checks to see if this is an HTTP request that includes a valid upgrade * request to web socket. * <p> * Note: RFC 2616 does not limit HTTP upgrade to GET requests but the Java * WebSocket spec 1.0, section 8.2 implies such a limitation and RFC * 6455 section 4.1 requires that a WebSocket Upgrade uses GET. * @param request The request to check if it is an HTTP upgrade request for * a WebSocket connection * @param response The response associated with the request * @return <code>true</code> if the request includes a HTTP Upgrade request * for the WebSocket protocol, otherwise <code>false</code> */ public static boolean isWebSocketUpgradeRequest(ServletRequest request, ServletResponse response) { return ((request instanceof HttpServletRequest) && (response instanceof HttpServletResponse) && headerContainsToken((HttpServletRequest) request, Constants.UPGRADE_HEADER_NAME, Constants.UPGRADE_HEADER_VALUE) && "GET".equals(((HttpServletRequest) request).getMethod())); }