@Override public void onHandshakeResponse(UpgradeResponse response) { resp.setStatus(response.getStatusCode()); for (String header : response.getHeaderNames()) { switch (header.toLowerCase()) { case "connection": case "date": case "sec-websocket-accept": case "upgrade": continue; } for (String value : response.getHeaders(header)) { resp.addHeader(header, value); } } try { wsFactory.acceptWebSocket(req, resp); } catch (IOException e) { throw new RuntimeException(e); } async.complete(); } });
if (wsFactory.acceptWebSocket(req, resp) || resp.isCommitted()) { return;
private void acceptWebSocket( final HttpServletRequest req, final HttpServletResponse res, final WebSocketConfig config ) throws IOException { final WebSocketCreator creator = new WebSocketHandler( this.handler, config ); this.webSocketServletFactory.acceptWebSocket( creator, req, res ); }
/** * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (factory.isUpgradeRequest(request,response)) { // We have an upgrade request if (factory.acceptWebSocket(request,response)) { // We have a socket instance created return; } // If we reach this point, it means we had an incoming request to upgrade // but it was either not a proper websocket upgrade, or it was possibly rejected // due to incoming request constraints (controlled by WebSocketCreator) if (response.isCommitted()) { // not much we can do at this point. return; } } // All other processing super.service(request,response); } }
/** * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (factory.isUpgradeRequest(request,response)) { // We have an upgrade request if (factory.acceptWebSocket(request,response)) { // We have a socket instance created return; } // If we reach this point, it means we had an incoming request to upgrade // but it was either not a proper websocket upgrade, or it was possibly rejected // due to incoming request constraints (controlled by WebSocketCreator) if (response.isCommitted()) { // not much we can do at this point. return; } } // All other processing super.service(request,response); } }
/** * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (factory.isUpgradeRequest(request,response)) { // We have an upgrade request if (factory.acceptWebSocket(request,response)) { // We have a socket instance created return; } // If we reach this point, it means we had an incoming request to upgrade // but it was either not a proper websocket upgrade, or it was possibly rejected // due to incoming request constraints (controlled by WebSocketCreator) if (response.isCommitted()) { // not much we can do at this point. return; } } // All other processing super.service(request,response); } }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (webSocketFactory.isUpgradeRequest(request, response) && webSocketFactory.acceptWebSocket(request, response)) { baseRequest.setHandled(true); return; } super.handle(target, baseRequest, request, response); }
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HTTPMethod method = HTTPMethod.valueOf(request.getMethod().toUpperCase()); boolean upgradeRequest = webSocketServletFactory.isUpgradeRequest(request, response); if ( upgradeRequest ) { method = HTTPMethod.WEBSOCKET; } GenericMatchedRoute<GenericRequestHandler> route = routeMatcher.match(method, request.getRequestURI()); if ( null == route ) { throw new IllegalStateException("route matcher not configured with a default route!"); } request.setAttribute(MATCHED_ROUTE, route); if ( upgradeRequest ) { request.setAttribute(GenericRequestHandler.class.getName(), route.getValue()); webSocketServletFactory.acceptWebSocket(request, response); } else { route.getValue().service(request, response); } }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (webSocketFactory.isUpgradeRequest(request, response) && webSocketFactory.acceptWebSocket(request, response)) { baseRequest.setHandled(true); return; } super.handle(target, baseRequest, request, response); }
public void invoke(final ServletConfig config, final ServletContext context, final HttpServletRequest request, final HttpServletResponse response) throws IOException { WebSocketServletFactory wsf = getWebSocketFactory(config, context); if (wsf.isUpgradeRequest(request, response) && wsf.acceptWebSocket(request, response)) { ((Request)request).setHandled(true); return; } super.invoke(config, context, request, response); }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (webSocketFactory.isUpgradeRequest(request,response)) { // We have an upgrade request if (webSocketFactory.acceptWebSocket(request,response)) { // We have a socket instance created baseRequest.setHandled(true); return; } // If we reach this point, it means we had an incoming request to upgrade // but it was either not a proper websocket upgrade, or it was possibly rejected // due to incoming request constraints (controlled by WebSocketCreator) if (response.isCommitted()) { // not much we can do at this point. return; } } super.handle(target,baseRequest,request,response); } }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (webSocketFactory.isUpgradeRequest(request,response)) { // We have an upgrade request if (webSocketFactory.acceptWebSocket(request,response)) { // We have a socket instance created baseRequest.setHandled(true); return; } // If we reach this point, it means we had an incoming request to upgrade // but it was either not a proper websocket upgrade, or it was possibly rejected // due to incoming request constraints (controlled by WebSocketCreator) if (response.isCommitted()) { // not much we can do at this point. return; } } super.handle(target,baseRequest,request,response); } }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (webSocketFactory.isUpgradeRequest(request,response)) { // We have an upgrade request if (webSocketFactory.acceptWebSocket(request,response)) { // We have a socket instance created baseRequest.setHandled(true); return; } // If we reach this point, it means we had an incoming request to upgrade // but it was either not a proper websocket upgrade, or it was possibly rejected // due to incoming request constraints (controlled by WebSocketCreator) if (response.isCommitted()) { // not much we can do at this point. return; } } super.handle(target,baseRequest,request,response); } }
public void invoke(final ServletConfig config, final ServletContext context, final HttpServletRequest request, final HttpServletResponse response) throws IOException { WebSocketServletFactory wsf = getWebSocketFactory(config, context); if (wsf.isUpgradeRequest(request, response) && wsf.acceptWebSocket(request, response)) { ((Request)request).setHandled(true); return; } super.invoke(config, context, request, response); }
public boolean serviceError(Integer code, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String path = ( null == code ) ? "/500" : "/"+code; boolean upgradeRequest = webSocketServletFactory.isUpgradeRequest(request, response); HTTPMethod method = upgradeRequest ? HTTPMethod.WEBSOCKET : HTTPMethod.GET; GenericMatchedRoute<GenericRequestHandler> route = routeMatcher.match(method, path); if ( null == route || route.isDefaultRoute() ) { return false; } if ( upgradeRequest ) { request.setAttribute(GenericRequestHandler.class.getName(), route.getValue()); webSocketServletFactory.acceptWebSocket(request, response); } else { route.getValue().service(request, response); } return true; }
if (factory.acceptWebSocket(creator, httpreq, httpresp))