Expand my Community achievements bar.

SOLVED

Remote Repository Session

Avatar

Former Community Member

I want to create a remote session to another repository from within a repository, means I have a servlet running inside a CQ5 author instance. I tried to open a connection to a remote repository with JcrUtils:

Repository repository = JcrUtils.getRepository( "http://myhost:4502/crx/server" );

This causes an error message:

javax.jcr.RepositoryException: Unable to access a repository with the following settings:

org.apache.jackrabbit.repository.uri: http://localhost:4502/crx/server

The following RepositoryFactory classes were consulted:

Perhaps the repository you are trying to access is not available at the moment.

any ideas?

1 Accepted Solution

Avatar

Correct answer by
Level 10

I am not sure that writing an OSGi bundle that contains JCR API app logic to connect to another JCR repository is a supported use case.  

If that was the case -- this Java code would be supported code from within an OSGi bundle:

//Create a connection to the CQ repository running on local host

Repository repository = JcrUtils.getRepository(aemUrl);

 

//Create a Session

Javax.jcr.Session session = repository.login( new SimpleCredentials("readonly", "readonly".toCharArray()));

 

However - this JCR API code is only supported from outside of the CRX layer. For example -- an external Java app such as  a Java Swing app. 

View solution in original post

3 Replies

Avatar

Level 10

You cannot run this code from within an OSGi bundle.  

//Create a connection to the CQ repository running on local host

Repository repository = JcrUtils.getRepository(aemUrl);

 

//Create a Session

Javax.jcr.Session session = repository.login( new SimpleCredentials("readonly", "readonly".toCharArray()));

 

You use this code from a standalone Java app -- such as:

http://scottsdigitalcommunity.blogspot.ca/2013/11/developing-java-swing-application-that.html

To run JCR API code from within an OSGi bundle, see:

http://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html

To create a session from within an OSGI  -- you use this code:

//Invoke the adaptTo method to create a Session used to create a QueryManager

 ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);

session = resourceResolver.adaptTo(Session.class);

And the repository that you use from within an OSGi is localhost.

Hope this helps

Avatar

Former Community Member

I tried already a local connection, this works, of course.

My problem is to connect from within a repository to another one...

Avatar

Correct answer by
Level 10

I am not sure that writing an OSGi bundle that contains JCR API app logic to connect to another JCR repository is a supported use case.  

If that was the case -- this Java code would be supported code from within an OSGi bundle:

//Create a connection to the CQ repository running on local host

Repository repository = JcrUtils.getRepository(aemUrl);

 

//Create a Session

Javax.jcr.Session session = repository.login( new SimpleCredentials("readonly", "readonly".toCharArray()));

 

However - this JCR API code is only supported from outside of the CRX layer. For example -- an external Java app such as  a Java Swing app.