javax.jcr.lock.LockException:前置条件失败

时间:2015-12-29 09:56:55

标签: aem

我在连接到AEM 6.0中的JCR存储库时遇到了一些问题。当我到达关于在repostory上创建会话的时候,我得到了一个

  

javax.jcr.lock.LockException:Precondition Failed。

     

stacktrace:javax.jcr.lock.LockException:Precondition Failed at   org.apache.jackrabbit.spi2dav.ExceptionConverter.generate(ExceptionConverter.java:109)     在   org.apache.jackrabbit.spi2dav.ExceptionConverter.generate(ExceptionConverter.java:51)     在   org.apache.jackrabbit.spi2dav.ExceptionConverter.generate(ExceptionConverter.java:45)     在   org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.obtain(RepositoryServiceImpl.java:809)     在   org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.obtain(RepositoryServiceImpl.java:753)     在   org.apache.jackrabbit.spi2davex.RepositoryServiceImpl.obtain(RepositoryServiceImpl.java:307)     在   org.apache.jackrabbit.jcr2spi.RepositoryImpl.login(RepositoryImpl.java:151)     在   org.apache.jackrabbit.commons.AbstractRepository.login(AbstractRepository.java:123)     在org.test.CallSlingServlet.main(CallSlingServlet.java:63)引起   by:org.apache.jackrabbit.webdav.DavException:Precondition Failed at   org.apache.jackrabbit.webdav.client.methods.DavMethodBase.getResponseException(DavMethodBase.java:162)     在   org.apache.jackrabbit.webdav.client.methods.DavMethodBase.getResponseBodyAsMultiStatus(DavMethodBase.java:91)     在   org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.obtain(RepositoryServiceImpl.java:781)     ... 5更多错误:javax.jcr.lock.LockException:Precondition Failed

我使用的示例代码。

package org.test;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.SimpleCredentials;

import org.apache.jackrabbit.commons.JcrUtils;

import com.google.api.client.repackaged.org.apache.commons.codec.binary.Base64;
import com.google.enterprise.apis.client.GsaClient;
import com.google.enterprise.apis.client.GsaEntry;
import com.google.enterprise.apis.client.GsaFeed;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;


public class CallSlingServlet {


    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub
        try {



            Repository repository = JcrUtils.getRepository("http://localhost:4502/crx/server");
            javax.jcr.Session session = repository.login( new SimpleCredentials("admin", "admin".toCharArray()));
            Node root1 = session.getRootNode();
            Node node = ((Node) root1).getNode("/content/act/GSAEvents"); 
            System.out.println(node.getPath()); 
            System.out.println(node.getProperty("message").getString());
        }           
        catch ( Exception ex ) {
            // a real program would need to handle this exception
            System.out.println( "error: "+ex);
        } 
    }}

1 个答案:

答案 0 :(得分:2)

在JCR存储库中,内容被组织到一个或多个工作空间中,每个工作空间都包含节点和属性的层次结构。所以要创建一个jcr会话&您必须使用凭据传递工作区的访问节点和属性,默认AEM工作区 crx.default

尝试以下代码

    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.util.HashMap;
    import java.util.Map;

    import javax.jcr.Node;
    import javax.jcr.Repository;
    import javax.jcr.SimpleCredentials;
    import org.apache.jackrabbit.commons.JcrUtils;

    public class CallSlingServlet {
        public static void main(String[] args) throws Exception {
            try {
                String WORKSPACE = "crx.default";
                Repository repository = JcrUtils.getRepository("http://localhost:4502/crx/server");
                javax.jcr.Session session = repository.login( new SimpleCredentials("admin", "admin".toCharArray()),WORKSPACE);
                Node root1 = session.getRootNode();
                Node node = ((Node) root1).getNode("/content/act/GSAEvents"); 
                System.out.println(node.getPath()); 
                System.out.println(node.getProperty("message").getString());
            }           
            catch ( Exception ex ) {
                // a real program would need to handle this exception
                System.out.println( "error: "+ex);
            } 
        }}