ContainerConfig.Container.Property clientProp = cfg.getProperty("client-factory");
ContainerConfig.Container.Property serverProp = cfg.getProperty("server-factory");
// check the required lookup-name property
if (lookupNameProp == null || lookupNameProp.value == null || lookupNameProp.value.length() == 0) {
throw new ContainerException("Invalid lookup-name defined in container configuration");
} else {
this.name = lookupNameProp.value;
}
// check the required delegator-name property
if (delegatorProp == null || delegatorProp.value == null || delegatorProp.value.length() == 0) {
throw new ContainerException("Invalid delegator-name defined in container configuration");
}
String useCtx = initialCtxProp == null || initialCtxProp.value == null ? "false" : initialCtxProp.value;
String host = lookupHostProp == null || lookupHostProp.value == null ? "localhost" : lookupHostProp.value;
String port = lookupPortProp == null || lookupPortProp.value == null ? "1099" : lookupPortProp.value;
String keystore = ContainerConfig.getPropertyValue(cfg, "ssl-keystore", null);
String ksType = ContainerConfig.getPropertyValue(cfg, "ssl-keystore-type", "JKS");
String ksPass = ContainerConfig.getPropertyValue(cfg, "ssl-keystore-pass", null);
String ksAlias = ContainerConfig.getPropertyValue(cfg, "ssl-keystore-alias", null);
boolean clientAuth = ContainerConfig.getPropertyValue(cfg, "ssl-client-auth", false);
// setup the factories
RMIClientSocketFactory csf = null;
RMIServerSocketFactory ssf = null;
// get the classloader
ClassLoader loader = Thread.currentThread().getContextClassLoader();
// load the factories
if (clientProp != null && clientProp.value != null && clientProp.value.length() > 0) {
try {
Class<?> c = loader.loadClass(clientProp.value);
csf = (RMIClientSocketFactory) c.newInstance();
} catch (Exception e) {
throw new ContainerException(e);
}
}
if (serverProp != null && serverProp.value != null && serverProp.value.length() > 0) {
try {
Class<?> c = loader.loadClass(serverProp.value);
ssf = (RMIServerSocketFactory) c.newInstance();
} catch (Exception e) {
throw new ContainerException(e);
}
}
// set the client auth flag on our custom SSL socket factory
if (ssf != null && ssf instanceof org.ofbiz.service.rmi.socket.ssl.SSLServerSocketFactory) {
((org.ofbiz.service.rmi.socket.ssl.SSLServerSocketFactory) ssf).setNeedClientAuth(clientAuth);
((org.ofbiz.service.rmi.socket.ssl.SSLServerSocketFactory) ssf).setKeyStoreAlias(ksAlias);
if (keystore != null) {
((org.ofbiz.service.rmi.socket.ssl.SSLServerSocketFactory) ssf).setKeyStore(keystore, ksType, ksPass);
}
}
// get the delegator for this container
GenericDelegator delegator = GenericDelegator.getGenericDelegator(delegatorProp.value);
// create the LocalDispatcher
LocalDispatcher dispatcher = GenericDispatcher.getLocalDispatcher(name, delegator);
// create the RemoteDispatcher
try {
remote = new RemoteDispatcherImpl(dispatcher, csf, ssf);
} catch (RemoteException e) {
throw new ContainerException("Unable to start the RMI dispatcher", e);
}
if (!useCtx.equalsIgnoreCase("true")) {
// bind RMIDispatcher to RMI Naming (Must be JRMP protocol)
try {
Naming.rebind("//" + host + ":" + port + "/" + name, remote);
} catch (RemoteException e) {
throw new ContainerException("Unable to bind RMIDispatcher to RMI on " + "//host[" + host + "]:port[" + port + "]/name[" + name + "] - with remote=" + remote , e);
} catch (java.net.MalformedURLException e) {
throw new ContainerException("Invalid URL for binding", e);
}
} else {
// bind RMIDispatcher to InitialContext (must be RMI protocol not IIOP)
try {
InitialContext ic = new InitialContext();
ic.rebind(name, remote);
} catch (NamingException e) {
throw new ContainerException("Unable to bind RMIDispatcher to JNDI", e);
}
// check JNDI
try {
InitialContext ic = new InitialContext();
Object o = ic.lookup(name);
if (o == null) {
throw new NamingException("Object came back null");
}
} catch (NamingException e) {
throw new ContainerException("Unable to lookup bound objects", e);
}
}
return true;
}