当前位置: 首页>>代码示例>>Java>>正文


Java HttpServletResponse.SC_PRECONDITION_FAILED属性代码示例

本文整理汇总了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);
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:38,代码来源:LockMethod.java

示例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);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:39,代码来源:LockMethod.java

示例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);
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:59,代码来源:WebDAVMethod.java


注:本文中的javax.servlet.http.HttpServletResponse.SC_PRECONDITION_FAILED属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。