throw new ServletException("Unable to create RMI repository. jcr-rmi.jar might be missing.", e);
}
try {
System.setProperty("java.rmi.server.useCodebaseOnly", "true");
Registry reg = null;
// first try to create the registry, which will fail if another
// application is already running on the configured host/port
// or if the rmiHost is not local
try {
// find the server socket factory: use the default if the
// rmiHost is not configured
RMIServerSocketFactory sf;
if (rmiHost.length() > 0) {
log.debug("Creating RMIServerSocketFactory for host " + rmiHost);
InetAddress hostAddress = InetAddress.getByName(rmiHost);
sf = getRMIServerSocketFactory(hostAddress);
} else {
// have the RMI implementation decide which factory is the
// default actually
log.debug("Using default RMIServerSocketFactory");
sf = null;
}
// create a registry using the default client socket factory
// and the server socket factory retrieved above. This also
// binds to the server socket to the rmiHost:rmiPort.
reg = LocateRegistry.createRegistry(rmiPort, null, sf);
} catch (UnknownHostException uhe) {
// thrown if the rmiHost cannot be resolved into an IP-Address
// by getRMIServerSocketFactory
log.info("Cannot create Registry", uhe);
} catch (RemoteException e) {
// thrown by createRegistry if binding to the rmiHost:rmiPort
// fails, for example due to rmiHost being remote or another
// application already being bound to the port
log.info("Cannot create Registry", e);
}
// if creation of the registry failed, we try to access an
// potentially active registry. We do not check yet, whether the
// registry is actually accessible.
if (reg == null) {
log.debug("Trying to access existing registry at " + rmiHost
+ ":"+ rmiPort);
try {
reg = LocateRegistry.getRegistry(rmiHost, rmiPort);
} catch (RemoteException re) {
log.error("Cannot create the reference to the registry at "
+ rmiHost + ":" + rmiPort, re);
}
}
// if we finally have a registry, register the repository with the
// rmiName
if (reg != null) {
log.debug("Registering repository as " + rmiName
+ " to registry " + reg);
reg.bind(rmiName, remote);
// when successfull, keep references
this.rmiURI = rmiURI;
this.rmiRepository = remote;
log.info("Repository bound via RMI with name: " + rmiURI);