@Override protected void handshake(final Runnable handler) throws Exception { /** Infinite timeout because the continuation is never resumed but only completed on close. */ req.getAsyncContext().setTimeout(0L); /** Server sent events headers. */ rsp.setStatus(HttpServletResponse.SC_OK); rsp.setHeader("Connection", "Close"); rsp.setContentType("text/event-stream; charset=utf-8"); rsp.flushBuffer(); HttpChannel channel = rsp.getHttpChannel(); Connector connector = channel.getConnector(); Executor executor = connector.getExecutor(); executor.execute(handler); }
@Override public void failure(final Throwable error) { try { if (!response.isCommitted()) { try { if (configSetStatusOverSendError) { response.reset(); //noinspection deprecation response.setStatus(INTERNAL_SERVER_ERROR, "Request failed."); } else { response.sendError(INTERNAL_SERVER_ERROR, "Request failed."); } } catch (final IllegalStateException ex) { // a race condition externally committing the response can still occur... LOGGER.log(Level.FINER, "Unable to reset failed response.", ex); } catch (final IOException ex) { throw new ContainerException(LocalizationMessages.EXCEPTION_SENDING_ERROR_RESPONSE(INTERNAL_SERVER_ERROR, "Request failed."), ex); } } } finally { LOGGER.log(Level.FINEST, "failure(...) called"); commit(); rethrow(error); } }
public void setStatus(int sc) { setStatus(sc,null); }
public void setStatus(int sc) { setStatus(sc,null); }
public void setStatus(int sc) { setStatus(sc,null); }
public void setStatus(int sc) { setStatus(sc,null); }
public void setStatus(int sc) { setStatus(sc,null); }
@Override public void malformedResponseChunk() { try { response.setStatus(200); response.flushBuffer(); socket.getChannel().write(BufferUtil.toBuffer(GARBAGE)); socket.close(); } catch (IOException e) { throwUnchecked(e); } }
@Override public void malformedResponseChunk() { try { response.setStatus(200); response.flushBuffer(); writeGarbageThenCloseSocket(); } catch (IOException e) { throwUnchecked(e); } }
response.setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED); return Filter.STOP;
private void minimalErrorResponse(Throwable failure) { try { int code = 500; Integer status=(Integer)_request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); if (status!=null) code = status.intValue(); else { Throwable cause = unwrap(failure,BadMessageException.class); if (cause instanceof BadMessageException) code = ((BadMessageException)cause).getCode(); } _response.reset(true); _response.setStatus(code); _response.flushBuffer(); } catch (Throwable x) { if (x != failure) failure.addSuppressed(x); abort(failure); } }
setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); complete();
setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); complete();
setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); complete();
setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); complete();
setStatus(code); closeOutput();
@Override protected void handshake(final Runnable handler) throws Exception { /** Infinite timeout because the continuation is never resumed but only completed on close. */ req.getAsyncContext().setTimeout(0L); /** Server sent events headers. */ rsp.setStatus(HttpServletResponse.SC_OK); rsp.setHeader("Connection", "Close"); rsp.setContentType("text/event-stream; charset=utf-8"); rsp.flushBuffer(); HttpChannel channel = rsp.getHttpChannel(); Connector connector = channel.getConnector(); Executor executor = connector.getExecutor(); executor.execute(handler); }
protected void handleOptions(Request request,Response response) throws IOException { if (!HttpMethod.OPTIONS.is(request.getMethod())) response.sendError(HttpStatus.BAD_REQUEST_400); request.setHandled(true); response.setStatus(200); response.getHttpFields().put(HttpHeader.ALLOW,"GET,POST,HEAD,OPTIONS"); response.setContentLength(0); response.complete(); }
protected void handleOptions(Request request,Response response) throws IOException { if (!HttpMethod.OPTIONS.is(request.getMethod())) response.sendError(HttpStatus.BAD_REQUEST_400); request.setHandled(true); response.setStatus(200); response.getHttpFields().put(HttpHeader.ALLOW,"GET,POST,HEAD,OPTIONS"); response.setContentLength(0); response.complete(); }
@Override public void sendResponse(Response response) throws IOException { // Add call headers Parameter header; for (final Iterator<Parameter> iter = getResponseHeaders().iterator(); iter .hasNext();) { header = iter.next(); getConnection().getResponse().addHeader(header.getName(), header.getValue()); } // Set the status code in the response. We do this after adding the // headers because when we have to rely on the 'sendError' method, // the Servlet containers are expected to commit their response. if (Status.isError(getStatusCode()) && (response.getEntity() == null)) { try { getConnection().getResponse().sendError(getStatusCode(), getReasonPhrase()); } catch (IOException ioe) { getLogger().log(Level.WARNING, "Unable to set the response error status", ioe); } } else { // Send the response entity getConnection().getResponse().setStatus(getStatusCode()); super.sendResponse(response); } } }