List of usage examples for javax.servlet.http HttpServletResponse SC_PRECONDITION_FAILED
int SC_PRECONDITION_FAILED
To view the source code for javax.servlet.http HttpServletResponse SC_PRECONDITION_FAILED.
Click Source Link
From source file:org.gss_project.gss.server.rest.Webdav.java
/** * Check if the if-none-match condition is satisfied. * * @param request The servlet request we are processing * @param response The servlet response we are creating * @param file the file object/*from w w w. j a v a2 s.c om*/ * @param oldBody the old version of the file, if requested * @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 * @throws IOException */ private boolean checkIfNoneMatch(HttpServletRequest request, HttpServletResponse response, FileHeader file, FileBody oldBody) throws IOException { String eTag = getETag(file, oldBody); String headerValue = request.getHeader("If-None-Match"); if (headerValue != null) { boolean conditionSatisfied = false; if (!headerValue.equals("*")) { StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ","); while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) { String currentToken = commaTokenizer.nextToken(); if (currentToken.trim().equals(eTag)) conditionSatisfied = true; } } else conditionSatisfied = true; if (conditionSatisfied) { // For GET and HEAD, we should respond with 304 Not Modified. // For every other method, 412 Precondition Failed is sent // back. if ("GET".equals(request.getMethod()) || "HEAD".equals(request.getMethod())) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); response.setHeader("ETag", getETag(file, oldBody)); return false; } response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return false; } } return true; }
From source file:org.gss_project.gss.server.rest.Webdav.java
/** * Check if the if-unmodified-since condition is satisfied. * * @param request The servlet request we are processing * @param response The servlet response we are creating * @param file the file object/*from w w w . ja v a 2s . c o m*/ * @param oldBody the old version of the file, if requested * @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 * @throws IOException */ private boolean checkIfUnmodifiedSince(HttpServletRequest request, HttpServletResponse response, FileHeader file, FileBody oldBody) throws IOException { try { long lastModified = oldBody == null ? file.getAuditInfo().getModificationDate().getTime() : oldBody.getAuditInfo().getModificationDate().getTime(); long headerValue = request.getDateHeader("If-Unmodified-Since"); 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.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return false; } } catch (IllegalArgumentException illegalArgument) { return true; } return true; }