How do I use RMI to connect to CRX repository from CQ 5.6.x from an external application

Question

How do I use RMI to connect to CRX repository from CQ 5.6.x from an external application?

 

Answer, Resolution

1. By default, the RMI connection listener is not enabled; in order to enable it has to be   configured.

 

Login to a Configuration Tab in OSGI console: http://host:port/system/console/configMgr. Find "Apache Sling JCR Repository RMI Registrar". Default RMI port is 1099. You need to re-save or change the port value in in order to enable RMI listener.

 

2. The following output into a error.log file indicates that RMI is ready:

*INFO* [CM Event Dispatcher (Fire ConfigurationEvent: pid=org.apache.sling.jcr.jackrabbit.server.RmiRegistrationSupport)] org.apache.sling.jcr.registration Using RMI Registry port 1199

*INFO* [CM Event Dispatcher (Fire ConfigurationEvent: pid=org.apache.sling.jcr.jackrabbit.server.RmiRegistrationSupport)] org.apache.sling.jcr.registration Using private RMI Registry at 1199

*INFO* [CM Event Dispatcher (Fire ConfigurationEvent: pid=org.apache.sling.jcr.jackrabbit.server.RmiRegistrationSupport)] org.apache.sling.jcr.registration Repository bound to //server_name:1199/virtual-crx

 

3. Write a java class that connects to CRX through RMI. Below is a very simple example showing how to login to the CRX and get a Crx Session:

 

import org.apache.jackrabbit.rmi.client.ClientRepositoryFactory;

import javax.jcr.Repository;

import javax.jcr.Session;

import javax.jcr.SimpleCredentials;

public class CRXtoRMI {

       public static void main (String[] args){

              System.out.println("RMI to CRX Test Connection:");

              ClientRepositoryFactory factory = new ClientRepositoryFactory();

              Repository repository;

              String crxApplicationName = "virtual-crx";

              String repoUrl = "//localhost:1199/"+crxApplicationName;

              String workspace = "crx.default";

              String username = "admin";

              char [] password = "admin".toCharArray();

              try {

                     repository = factory.getRepository(repoUrl);

                     Session s = repository.login(new SimpleCredentials(username,password), workspace);

                     System.out.println("Workspace: " + s.getWorkspace().getName());

                     System.out.println("userId: "+s.getUserID());

              } catch (Exception e) {

                     e.printStackTrace();

              }

       }

}

 

 Adobe

Gaukite pagalbą greičiau ir lengviau

Naujas vartotojas?

Adobe MAX 2024

Adobe MAX
Kūrybiškumo konferencija

Spalio 14–16 d. Miami Beach ir internetu

Adobe MAX

Kūrybiškumo konferencija

Spalio 14–16 d. Miami Beach ir internetu

Adobe MAX 2024

Adobe MAX
Kūrybiškumo konferencija

Spalio 14–16 d. Miami Beach ir internetu

Adobe MAX

Kūrybiškumo konferencija

Spalio 14–16 d. Miami Beach ir internetu