本文整理匯總了Java中javax.servlet.http.HttpServletResponse.SC_PRECONDITION_FAILED屬性的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletResponse.SC_PRECONDITION_FAILED屬性的具體用法?Java HttpServletResponse.SC_PRECONDITION_FAILED怎麽用?Java HttpServletResponse.SC_PRECONDITION_FAILED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類javax.servlet.http.HttpServletResponse
的用法示例。
在下文中一共展示了HttpServletResponse.SC_PRECONDITION_FAILED屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parseRequestBody
/**
* 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);
}
}
}
示例2: createLock
/**
* 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);
}
}
示例3: checkConditions
/**
* 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);
}