EXO-JCR RMI server
This page explains how you can use the Demo RMI server and how you can enable RMI on an existing server.
1 Demo RMI server
1.1 Building/configuration
To build an EXO-JCR RMI server just run
mvn clean install in
exo-jcr/applications/rmi-server. After that RMI
server workspace will be created in the directory
exo-jcr/applications/rmi-server/run. The directory contains:
- subdirectory cb - codebase for the RMI subsystem
- subdirectory lib - the classpath of the JCR repository
- files configuration.xml and exo-jcr-config.xml - configuration of the JCR repository
- file java.policy - a JVM policy file
- file jaas.conf - a JAAS configuration file
- file run.bat - a batch file to run the server
The default port number the server searches RMI registry in is 9999. You can change that editing the parameter
rmiPort of the component
org.exoplatform.services.jcr.rmi.RMIBinder in the file
configuration.xml.
1.2 Starting
To run EXO-JCR RMI server you have to:
- run %JAVAHOME%/bin/rmiregistry.exe 9999 (or other desired value instead of 9999) to run the RMI registry
- run run/run.bat to set up the repository itself and to register it in the RMI registry
2 Enable RMI on an existing server
Before running the server, you need to reserve a port on the system and make exo use this port to enable RMI access.
- run %JAVAHOME%/bin/rmiregistry.exe 9999 (or other desired value instead of 9999) to run the RMI registry
- Add the following component to a configuration file
<component>
<key>org.exoplatform.services.jcr.rmi.api.server.JCRServer</key>
<type>org.exoplatform.services.jcr.rmi.impl.server.JCRServerImpl</type>
<init-params>
<value-param>
<!-- values of rmiPort that are less than 1 mean default value of 1099 -->
<name>rmiPort</name>
<value>9999</value>
</value-param>
<value-param>
<name>autoBind</name>
<value>true</value>
</value-param>
</init-params>
</component>
3 Accessing the EXO-JCR RMI server
What you need to access the EXO-JCR RMI server
At first we need some 'jar's that contain all classes to access a remote repository
- exo-jcr.services.jcr.-n.n.jar - EXO-JCR API interfaces/classes
- exo-jcr.services.jcr.rmi.-n.n.jar - EXO-JCR RMI Client side API and common interfaces/classes
When we have all that stuff we need to write a class that will use the repository and wrap it into...
- someClass.jar - some handmade class having static … main() method we want to access to a repository with
And at last we have a batch file like the following:
@echo off
set CLASSPATH=%CLASSPATH%;exo-jcr.services.jcr.api-1.5.jar;exo-jcr.services.jcr.rmi.api-1.5.jar;exo-jcr.services.jcr.rmi.impl-1.5.jar;someClass.jar
java org.exoplatform.jcr.someClass
4 Sample code to access a remote EXO-JCR repository with RMI
Here's an sample sourcecode of a class that uses a remote repository:
public class someClass {
public static void main(String[] argv) {
try {
ClientRepositoryFactory factory = new ClientRepositoryFactory();
Repository repository = factory.getRepository("//localhost:9999/repository");
Credentials credentials = new SimpleCredentials("admin", "admin".toCharArray());
Session session = repository.login(credentials, "production");
Node node = session.getRootNode();
System.out.println("root node path: " + node.getPath());
} catch (Exception e) {
e.printStackTrace();
}
}
}