Java Code Examples for javax.servlet.http.HttpServletResponse#SC_PRECONDITION_FAILED
The following examples show how to use
javax.servlet.http.HttpServletResponse#SC_PRECONDITION_FAILED .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoadCommon.java From tds with BSD 3-Clause "New" or "Revised" License | 6 votes |
static String loadForm(File form) throws IOException { if (form == null) throw new SendError(HttpServletResponse.SC_PRECONDITION_FAILED, "No form path specified"); if (!form.exists()) throw new SendError(HttpServletResponse.SC_PRECONDITION_FAILED, "HTML form does not exist: " + form.getName()); if (!form.canRead()) throw new SendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "HTML form not readable: " + form.getName()); try { FileInputStream fis = new FileInputStream(form); String content = HTTPUtil.readtextfile(fis); fis.close(); return content; } catch (IOException e) { logServerStartup.warn("Cannot read HTML form file: " + form.getName()); throw e; } }
Example 2
Source File: ArchivaDavResource.java From archiva with Apache License 2.0 | 6 votes |
@Override public void unlock( String lockToken ) throws DavException { ActiveLock lock = getLock( Type.WRITE, Scope.EXCLUSIVE ); if ( lock == null ) { throw new DavException( HttpServletResponse.SC_PRECONDITION_FAILED ); } else if ( lock.isLockedByToken( lockToken ) ) { lockManager.releaseLock( lockToken, this ); } else { throw new DavException( DavServletResponse.SC_LOCKED ); } }
Example 3
Source File: LockMethod.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * Parse the request body * * @exception WebDAVServerException */ protected void parseRequestBody() throws WebDAVServerException { if (m_request.getContentLength() == -1) { return; } Document body = getRequestBodyAsDocument(); if (body != null) { OUTER: for (Node currentNode = body.getDocumentElement().getFirstChild(); currentNode != null; currentNode = currentNode.getNextSibling()) { if (currentNode instanceof Element && WebDAV.DEFAULT_NAMESPACE_URI.equals(((Element) currentNode).getNamespaceURI()) && WebDAV.XML_LOCK_SCOPE.equals(((Element) currentNode).getLocalName())) { for (Node propertiesNode = currentNode.getFirstChild(); propertiesNode != null; propertiesNode = propertiesNode.getNextSibling()) { if (propertiesNode instanceof Element && WebDAV.DEFAULT_NAMESPACE_URI.equals(((Element) propertiesNode).getNamespaceURI())) { this.createExclusive = WebDAV.XML_EXCLUSIVE.equals(propertiesNode.getLocalName()); break OUTER; } } break OUTER; } } if (!createExclusive) { // We do not support shared locks - return 412 (section 8.10.7 of RFC 2518) throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED); } } }
Example 4
Source File: LockMethod.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * Create a new lock * * @param lockNode NodeRef * @param userName String * @exception WebDAVServerException */ protected final void createLock(FileInfo lockNode, String userName) throws WebDAVServerException { // Create Lock token lockToken = WebDAV.makeLockToken(lockNode.getNodeRef(), userName); if (createExclusive) { // Lock the node lockInfo.setTimeoutSeconds(getLockTimeout()); lockInfo.setExclusiveLockToken(lockToken); } else { // Shared lock creation should already have been prohibited when parsing the request body throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED); } // Store lock depth lockInfo.setDepth(WebDAV.getDepthName(m_depth)); // Store lock scope (shared/exclusive) String scope = createExclusive ? WebDAV.XML_EXCLUSIVE : WebDAV.XML_SHARED; lockInfo.setScope(scope); // Store the owner of this lock lockInfo.setOwner(userName); // Lock the node getDAVLockService().lock(lockNode.getNodeRef(), lockInfo); if (logger.isDebugEnabled()) { logger.debug("Locked node " + lockNode + ": " + lockInfo); } }
Example 5
Source File: WebDAVMethod.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * Parses "If" header of the request. * Stores conditions that should be checked. * Parses both No-tag-list and Tagged-list formats * See "10.4.2 Syntax" paragraph of the WebDAV specification for "If" header format. * */ protected void parseIfHeader() throws WebDAVServerException { //String strLockToken = null; String strIf = m_request.getHeader(WebDAV.HEADER_IF); if (logger.isDebugEnabled()) logger.debug("Parsing If header: " + strIf); if (strIf != null && strIf.length() > 0) { if (strIf.startsWith("<")) { m_resourceTag = strIf.substring(1, strIf.indexOf(">")); strIf = strIf.substring(m_resourceTag.length() + 3); } m_conditions = new LinkedList<Condition>(); String[] parts = strIf.split("\\) \\("); for (int i = 0; i < parts.length; i++) { String partString = parts[i].replaceAll("\\(", "").replaceAll("\\)", ""); Condition c = new Condition(); String[] conditions = partString.split(" "); for (int j = 0; j < conditions.length; j++) { boolean fNot = false; String eTag = null; String lockToken = null; if (WebDAV.HEADER_KEY_NOT.equals(conditions[j])) { // Check if Not keyword followed by State-token or entity-tag if (j == (conditions.length - 1)) { throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED); } fNot = true; j++; } // read State-token int index = conditions[j].indexOf('<'); if (index != -1) { try { String s = conditions[j].substring(index + 1, conditions[j].indexOf(">")); if (!s.startsWith(WebDAV.OPAQUE_LOCK_TOKEN)) { if(!fNot) { throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED); } } else { lockToken = s; c.addLockTocken(lockToken, fNot); } } catch (IndexOutOfBoundsException e) { throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED); } } // read entity-tag index = conditions[j].indexOf("[\""); if (index != -1) { // TODO: implement parsing of weak ETags: W/"123..". int index2 = conditions[j].indexOf("]"); if (index2 == -1) { logger.warn("No closing ']': "+conditions[j]); index2 = conditions[j].length(); } eTag = conditions[j].substring(index + 1, index2); c.addETag(eTag, fNot); } } m_conditions.add(c); } } }
Example 6
Source File: WebDAVMethod.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * Checks If header conditions. Throws WebDAVServerException with 412(Precondition failed) * if none of the conditions success. * * @param nodeLockToken - node's lock token * @param nodeETag - node's ETag * @throws WebDAVServerException if conditions fail */ private void checkConditions(String nodeLockToken, String nodeETag) throws WebDAVServerException { // Checks If header conditions. // Each condition can contain check of ETag and check of Lock token. if (m_conditions == null) { // No conditions were provided with "If" request header, so check successful return; } // Check the list of "If" header's conditions. // If any condition conforms then check is successful for (Condition condition : m_conditions) { // Flag for ETag conditions boolean fMatchETag = true; // Flag for Lock token conditions boolean fMatchLockToken = true; // Check ETags that should match if (condition.getETagsMatch() != null) { fMatchETag = condition.getETagsMatch().contains(nodeETag) ? true : false; } // Check ETags that shouldn't match if (condition.getETagsNotMatch() != null) { fMatchETag = condition.getETagsNotMatch().contains(nodeETag) ? false : true; } // Check lock tokens that should match if (condition.getLockTokensMatch() != null) { fMatchLockToken = nodeLockToken == null || condition.getLockTokensMatch().contains(nodeLockToken); } // Check lock tokens that shouldn't match if (condition.getLockTokensNotMatch() != null) { fMatchLockToken = nodeLockToken == null || !condition.getLockTokensNotMatch().contains(nodeLockToken); } if (fMatchETag && fMatchLockToken) { // Condition conforms return; } } // None of the conditions successful throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED); }
Example 7
Source File: InvalidTusResumableException.java From tus-java-server with MIT License | 4 votes |
public InvalidTusResumableException(String message) { super(HttpServletResponse.SC_PRECONDITION_FAILED, message); }
Example 8
Source File: InvalidPartialUploadIdException.java From tus-java-server with MIT License | 4 votes |
public InvalidPartialUploadIdException(String message) { super(HttpServletResponse.SC_PRECONDITION_FAILED, message); }