Follow the below steps to access the CQ5 JCR repository (CRX) remotely.
A code snippet for the above can be found below
- Construct the remote URL of your CQ instance.
- e.g. http://localhost:4502/crx/server
- Where localhost is the host where CQ is running & 4502 is port where CQ is listening to the requests.
- Get the repository by using the JCRUtils class which is available in the jackrabbit-jcr-commons.jar library.
- repository = JcrUtils.getRepository("http://localhost:4502/crx/server");
- Create a SimpleCredential object by passing username, password entries.
- SimpleCredentials creds = new SimpleCredentials("admin", "admin".toCharArray());
- Invoke the login method of repository object by passing the credential object & the workspace name.
- Session session = repository.login(creds, "crx.default");
A code snippet for the above can be found below
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RemoteAccess { | |
public static void main(String x[]){ | |
String remoteURL = "http://localhost:4502/crx/server"; | |
Repository repository; | |
Session session = null; | |
try { | |
repository = JcrUtils.getRepository(remoteURL); | |
if( null != repository ){ | |
SimpleCredentials creds = new SimpleCredentials("admin", "admin".toCharArray()); | |
session = repository.login(creds, "crx.default"); | |
if(session.isLive()){ | |
System.out.println("You are connected to the Remote CQ instance"); | |
session.logout(); | |
} | |
} | |
} catch (RepositoryException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
No comments:
Post a Comment