/** * Set the HTTP status and message to be returned with this response. * * @param status The new HTTP status * @param message The associated text message * */ public void setStatus(int status, String message) { if (isCommitted()) return; // Ignore any call from an included servlet if (included) return; response.setStatus(status); response.setMessage(message); }
/** * Check if the if-unmodified-since condition is satisfied. * * @return boolean true if the resource meets the specified condition, * and false if the condition is not satisfied, in which case request * processing is stopped */ protected boolean checkIfUnmodifiedSince(Request request, FileCacheEntry entry) throws IOException { try { Response response = request.getResponse(); long lastModified = Long.parseLong(entry.lastModified); String h = request.getHeader("If-Unmodified-Since"); long headerValue = (h == null? -1: Long.parseLong(h)); if (headerValue != -1) { if ( lastModified >= (headerValue + 1000)) { // The entity has not been modified since the date // specified by the client. This is not an error case. response.setStatus(SC_PRECONDITION_FAILED); return false; } } } catch(IllegalArgumentException illegalArgument) { return true; } return true; }
/** * Based on the {@link Request} URI, try to map the file from the rootFolder, and send it synchronously using send file. * @param req the {@link Request} * @param res the {@link Response} * @throws Exception */ public void service(Request req, final Response res) throws Exception { String uri = req.requestURI().toString(); if (uri.contains("..") || !uri.startsWith(resourcesContextPath)) { res.setStatus(404); if (commitErrorResponse) { customizedErrorPage(req, res); } return; } // We map only file that take the form of name.extension if (uri.contains(".")) { uri = uri.substring(resourcesContextPath.length()); } service(uri, req, res); }
response.setStatus (SC_PRECONDITION_FAILED); return false;
public void service(Request req, final Response res) throws Exception { String uri = req.requestURI().toString(); if (uri.indexOf("..") >= 0) { res.setStatus(404); customizedErrorPage(req,res); return; } service(uri, req, res); }
public void service(Request req, final Response res) throws Exception { MessageBytes mb = req.requestURI(); ByteChunk requestURI = mb.getByteChunk(); String uri = req.requestURI().toString(); if (uri.indexOf("..") >= 0) { res.setStatus(404); return; } service(uri, req, res); }
/** * Based on the {@link Request} URI, try to map the file from the * {@link StaticResourcesAdapter#rootFolder}, and send it synchronously using send file. * @param req the {@link Request} * @param res the {@link Response} * @throws java.lang.Exception */ public void service(Request req, final Response res) throws Exception { String uri = req.requestURI().toString(); if (uri.indexOf("..") >= 0) { res.setStatus(404); customizedErrorPage(req,res); return; } service(uri, req, res); }
/** * Set the HTTP status and message to be returned with this response. * * @param status The new HTTP status * @param message The associated text message * */ public void setStatus(int status, String message) { checkResponse(); if (isCommitted()) return; // Ignore any call from an included servlet if (included) return; response.setStatus(status); response.setMessage(message); }
/** * Set the HTTP status and message to be returned with this response. * * @param status The new HTTP status * @param message The associated text message * */ public void setStatus(int status, String message) { checkResponse(); if (isCommitted()) return; // Ignore any call from an included servlet if (included) return; response.setStatus(status); response.setMessage(message); }
res.setStatus(404); ByteBuffer bb = HtmlHelper.getErrorPage("Not Found", "HTTP/1.1 404 Not Found\r\n", "Grizzly"); res.setContentLength(bb.limit());
response.setStatus(500); error = true;
response.setStatus(SC_NOT_MODIFIED); response.setHeader("ETag", getETag(entry)); return false;
private static void handleUnsupportedVersion(final Response response) throws IOException { response.setStatus(400); response.setMessage("Bad Request"); response.addHeader(WebSocketEngine.SEC_WS_VERSION, Version.getSupportedWireProtocolVersions()); response.sendHeaders(); response.flush(); }
/** * Invoke the {@link Adapter}, which usualy invoke the Servlet * Container. */ public void invokeAdapter(){ // Process the request in the adapter if (!error) { try { adapter.service(request, response); // Handle when the response was committed before a serious // error occurred. Throwing a ServletException should both // set the status to 500 and set the errorException. // If we fail here, then the response is likely already // committed, so we can't try and set headers. if(keepAlive && !error) { // Avoid checking twice. error = response.getErrorException() != null || statusDropsConnection(response.getStatus()); } } catch (InterruptedIOException e) { error = true; } catch (Throwable t) { logger.log(Level.SEVERE, sm.getString("processorTask.serviceError"), t); // 500 - Internal Server Error response.setStatus(500); error = true; } } }
/** * Send an error response with the specified status and message. * * @param status HTTP status code to send * @param message Corresponding message to send * * @exception IllegalStateException if this response has * already been committed * @exception IOException if an input/output error occurs */ public void sendError(int status, String message) throws IOException { if (isCommitted()) throw new IllegalStateException (sm.getString("response.sendError.ise")); // Ignore any call from an included servlet if (included) return; setError(); response.setStatus(status); response.setMessage(message); // Clear any data content that has been buffered resetBuffer(); // Cause the response to be finished (from the application perspective) setSuspended(true); }
/** * Send an error response with the specified status and message. * * @param status HTTP status code to send * @param message Corresponding message to send * * @exception IllegalStateException if this response has * already been committed * @exception IOException if an input/output error occurs */ public void sendError(int status, String message) throws IOException { checkResponse(); if (isCommitted()) throw new IllegalStateException (sm.getString("response.sendError.ise")); // Ignore any call from an included servlet if (included) return; setError(); response.setStatus(status); response.setMessage(message); // Clear any data content that has been buffered resetBuffer(); // Cause the response to be finished (from the application perspective) setSuspended(true); }
/** * Send an error response with the specified status and message. * * @param status HTTP status code to send * @param message Corresponding message to send * * @exception IllegalStateException if this response has * already been committed * @exception IOException if an input/output error occurs */ public void sendError(int status, String message) throws IOException { checkResponse(); if (isCommitted()) throw new IllegalStateException (sm.getString("response.sendError.ise")); // Ignore any call from an included servlet if (included) return; setError(); response.setStatus(status); response.setMessage(message); // Clear any data content that has been buffered resetBuffer(); // Cause the response to be finished (from the application perspective) setSuspended(true); }
public void respond(WebSocketApplication application, Response response) { response.setStatus(101); response.setMessage("Web Socket Protocol Handshake"); response.setHeader("Upgrade", "websocket"); response.setHeader("Connection", "Upgrade"); setHeaders(response); if (!getSubProtocol().isEmpty()) { response.setHeader(WebSocketEngine.SEC_WS_PROTOCOL_HEADER, join(application.getSupportedProtocols(getSubProtocol()))); } try { response.sendHeaders(); response.flush(); } catch (IOException e) { throw new HandshakeException(e.getMessage(), e); } }