use of org.apache.ofbiz.base.container.ContainerException in project ofbiz-framework by apache.
the class RmiServiceContainer method start.
public boolean start() throws ContainerException {
// get the container config
ContainerConfig.Configuration cfg = ContainerConfig.getConfiguration(containerName, configFile);
ContainerConfig.Configuration.Property initialCtxProp = cfg.getProperty("use-initial-context");
ContainerConfig.Configuration.Property lookupHostProp = cfg.getProperty("bound-host");
ContainerConfig.Configuration.Property lookupPortProp = cfg.getProperty("bound-port");
ContainerConfig.Configuration.Property lookupNameProp = cfg.getProperty("bound-name");
ContainerConfig.Configuration.Property delegatorProp = cfg.getProperty("delegator-name");
ContainerConfig.Configuration.Property clientProp = cfg.getProperty("client-factory");
ContainerConfig.Configuration.Property serverProp = cfg.getProperty("server-factory");
// check the required lookup-name property
if (lookupNameProp == null || UtilValidate.isEmpty(lookupNameProp.value)) {
throw new ContainerException("Invalid lookup-name defined in container configuration");
} else {
this.name = lookupNameProp.value;
}
// check the required delegator-name property
if (delegatorProp == null || UtilValidate.isEmpty(delegatorProp.value)) {
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;
if (Start.getInstance().getConfig().portOffset != 0) {
Integer portValue = Integer.valueOf(port);
portValue += Start.getInstance().getConfig().portOffset;
port = portValue.toString();
}
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 && UtilValidate.isNotEmpty(clientProp.value)) {
try {
Class<?> c = loader.loadClass(clientProp.value);
csf = (RMIClientSocketFactory) c.newInstance();
} catch (Exception e) {
throw new ContainerException(e);
}
}
if (serverProp != null && UtilValidate.isNotEmpty(serverProp.value)) {
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.apache.ofbiz.service.rmi.socket.ssl.SSLServerSocketFactory) {
((org.apache.ofbiz.service.rmi.socket.ssl.SSLServerSocketFactory) ssf).setNeedClientAuth(clientAuth);
((org.apache.ofbiz.service.rmi.socket.ssl.SSLServerSocketFactory) ssf).setKeyStoreAlias(ksAlias);
if (keystore != null) {
((org.apache.ofbiz.service.rmi.socket.ssl.SSLServerSocketFactory) ssf).setKeyStore(keystore, ksType, ksPass);
}
}
// get the delegator for this container
Delegator delegator = DelegatorFactory.getDelegator(delegatorProp.value);
// create the LocalDispatcher
LocalDispatcher dispatcher = ServiceContainer.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 (!"true".equalsIgnoreCase(useCtx)) {
// 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;
}
use of org.apache.ofbiz.base.container.ContainerException in project ofbiz-framework by apache.
the class TestRunContainer method init.
@Override
public void init(List<StartupCommand> ofbizCommands, String name, String configFile) throws ContainerException {
this.name = name;
new File(logDir).mkdir();
// get the test properties passed by the user in the command line
Map<String, String> testProps = ofbizCommands.stream().filter(command -> command.getName().equals(StartupCommandUtil.StartupOption.TEST.getName())).map(command -> command.getProperties()).findFirst().get();
// set selected log level if passed by user
setLoggerLevel(testProps.get("loglevel"));
this.jsWrapper = prepareJunitSuiteWrapper(testProps);
}
use of org.apache.ofbiz.base.container.ContainerException in project ofbiz-framework by apache.
the class TestRunContainer method start.
public boolean start() throws ContainerException {
boolean failedRun = false;
for (ModelTestSuite modelSuite : jsWrapper.getModelTestSuites()) {
// prepare
TestSuite suite = modelSuite.makeTestSuite();
JUnitTest test = new JUnitTest(suite.getName());
JunitXmlListener xml = createJunitXmlListener(suite, logDir);
TestResult results = new TestResult();
results.addListener(new JunitListener());
results.addListener(xml);
// test
xml.startTestSuite(test);
suite.run(results);
test.setCounts(results.runCount(), results.failureCount(), results.errorCount());
// rollback all entity operations
modelSuite.getDelegator().rollback();
xml.endTestSuite(test);
logTestSuiteResults(suite, results);
failedRun = !results.wasSuccessful() ? true : failedRun;
}
if (failedRun) {
throw new ContainerException("Test run was unsuccessful");
}
return true;
}
use of org.apache.ofbiz.base.container.ContainerException in project ofbiz-framework by apache.
the class CatalinaContainer method prepareChannelReceiver.
private NioReceiver prepareChannelReceiver(Property clusterProp) throws ContainerException {
NioReceiver listener = new NioReceiver();
String tla = ContainerConfig.getPropertyValue(clusterProp, "tcp-listen-host", "auto");
int tlp = ContainerConfig.getPropertyValue(clusterProp, "tcp-listen-port", 4001);
int tlt = ContainerConfig.getPropertyValue(clusterProp, "tcp-sector-timeout", 100);
int tlc = ContainerConfig.getPropertyValue(clusterProp, "tcp-thread-count", 6);
if (tlp == -1) {
throw new ContainerException("Cluster configuration requires tcp-listen-port property");
}
listener.setAddress(tla);
listener.setPort(tlp);
listener.setSelectorTimeout(tlt);
listener.setMaxThreads(tlc);
listener.setMinThreads(tlc);
return listener;
}
use of org.apache.ofbiz.base.container.ContainerException in project ofbiz-framework by apache.
the class CatalinaContainer method prepareTomcatClustering.
private Property prepareTomcatClustering(Host host, Property engineConfig) throws ContainerException {
Property clusterProp = null;
List<Property> clusterProps = engineConfig.getPropertiesWithValue("cluster");
if (clusterProps.size() > 1) {
throw new ContainerException("Only one cluster configuration allowed per engine");
}
if (UtilValidate.isNotEmpty(clusterProps)) {
clusterProp = clusterProps.get(0);
GroupChannel channel = new GroupChannel();
channel.setChannelReceiver(prepareChannelReceiver(clusterProp));
channel.setChannelSender(prepareChannelSender(clusterProp));
channel.setMembershipService(prepareChannelMcastService(clusterProp));
SimpleTcpCluster cluster = new SimpleTcpCluster();
cluster.setClusterName(clusterProp.name);
cluster.setManagerTemplate(prepareClusterManager(clusterProp));
cluster.setChannel(channel);
cluster.addValve(prepareClusterValve(clusterProp));
host.setCluster(cluster);
Debug.logInfo("Catalina Cluster [" + cluster.getClusterName() + "] configured for host - " + host.getName(), module);
}
return clusterProp;
}
Aggregations