本文介绍了javax.jcr.lock.LockException:前提条件失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在连接到AEM 6.0中的JCR存储库时遇到一些问题。当我到达在笔迹上创建会话的地步时,我得到了

我使用的示例代码。

 包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;

进口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;


公共类CallSlingServlet {


public static void main(String [] args)抛出异常{
// TODO Auto-生成的方法存根
尝试{



存储库= JcrUtils.getRepository( http:// localhost:4502 / crx / server);
javax.jcr.Session会话= repository.login(new SimpleCredentials( admin, admin .toCharArray()));
节点root1 = session.getRootNode();
Node node =((Node)root1).getNode( / content / act / GSAEvents);
System.out.println(node.getPath());
System.out.println(node.getProperty( message)。getString());
}
catch(例外ex){
//一个真正的程序需要处理该异常
System.out.println( error: + ex);
}
}}


解决方案

在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;

公共类CallSlingServlet {
public static void main(String [] args)引发异常{
try {
String WORKSPACE = crx.default;
信息库= JcrUtils.getRepository( http:// localhost:4502 / crx / server);
javax.jcr.Session会话= repository.login(new SimpleCredentials( admin, admin .toCharArray()),WORKSPACE);
节点root1 = session.getRootNode();
Node node =((Node)root1).getNode( / content / act / GSAEvents);
System.out.println(node.getPath());
System.out.println(node.getProperty( message)。getString());
}
catch(例外ex){
//一个真正的程序需要处理该异常
System.out.println( error: + ex);
}
}}


I am having some issues connecting to the JCR repository within AEM 6.0. When I get to the point of creating a session on the repostory I get a

sample code used by me .

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);
        } 
    }}
解决方案

Inside a JCR repository, content is organized into one or more workspaces, each of which holds of a hierarchical structure of nodes and properties. So to create a jcr session & access node and properties you have to pass workspace with credentials, Default AEM workspace is crx.default

Try below code

    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);
            } 
        }}

这篇关于javax.jcr.lock.LockException:前提条件失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 07:51