Search in sources :

Example 6 with ContainerException

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;
}
Also used : LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) RMIClientSocketFactory(java.rmi.server.RMIClientSocketFactory) ContainerConfig(org.apache.ofbiz.base.container.ContainerConfig) ContainerException(org.apache.ofbiz.base.container.ContainerException) RMIServerSocketFactory(java.rmi.server.RMIServerSocketFactory) NamingException(javax.naming.NamingException) ContainerException(org.apache.ofbiz.base.container.ContainerException) NamingException(javax.naming.NamingException) RemoteException(java.rmi.RemoteException) InitialContext(javax.naming.InitialContext) Delegator(org.apache.ofbiz.entity.Delegator) RemoteException(java.rmi.RemoteException)

Example 7 with ContainerException

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);
}
Also used : OutputStream(java.io.OutputStream) StartupCommand(org.apache.ofbiz.base.start.StartupCommand) Test(junit.framework.Test) Enumeration(java.util.Enumeration) FileOutputStream(java.io.FileOutputStream) TestFailure(junit.framework.TestFailure) HashMap(java.util.HashMap) ContainerException(org.apache.ofbiz.base.container.ContainerException) BuildException(org.apache.tools.ant.BuildException) AssertionFailedError(junit.framework.AssertionFailedError) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) StartupCommandUtil(org.apache.ofbiz.base.start.StartupCommandUtil) TestSuite(junit.framework.TestSuite) List(java.util.List) JUnitTest(org.apache.tools.ant.taskdefs.optional.junit.JUnitTest) Debug(org.apache.ofbiz.base.util.Debug) TestListener(junit.framework.TestListener) Map(java.util.Map) TestResult(junit.framework.TestResult) XMLJUnitResultFormatter(org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter) TestCase(junit.framework.TestCase) Container(org.apache.ofbiz.base.container.Container) File(java.io.File)

Example 8 with ContainerException

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;
}
Also used : JUnitTest(org.apache.tools.ant.taskdefs.optional.junit.JUnitTest) TestSuite(junit.framework.TestSuite) ContainerException(org.apache.ofbiz.base.container.ContainerException) TestResult(junit.framework.TestResult)

Example 9 with ContainerException

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;
}
Also used : NioReceiver(org.apache.catalina.tribes.transport.nio.NioReceiver) ContainerException(org.apache.ofbiz.base.container.ContainerException)

Example 10 with ContainerException

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;
}
Also used : ContainerException(org.apache.ofbiz.base.container.ContainerException) SimpleTcpCluster(org.apache.catalina.ha.tcp.SimpleTcpCluster) GroupChannel(org.apache.catalina.tribes.group.GroupChannel) Property(org.apache.ofbiz.base.container.ContainerConfig.Configuration.Property)

Aggregations

ContainerException (org.apache.ofbiz.base.container.ContainerException)15 File (java.io.File)4 ArrayList (java.util.ArrayList)4 URL (java.net.URL)3 NamingException (javax.naming.NamingException)3 ContainerConfig (org.apache.ofbiz.base.container.ContainerConfig)3 Delegator (org.apache.ofbiz.entity.Delegator)3 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)3 IOException (java.io.IOException)2 List (java.util.List)2 Map (java.util.Map)2 InitialContext (javax.naming.InitialContext)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 TestResult (junit.framework.TestResult)2 TestSuite (junit.framework.TestSuite)2 Container (org.apache.ofbiz.base.container.Container)2 Property (org.apache.ofbiz.base.container.ContainerConfig.Configuration.Property)2 StartupCommand (org.apache.ofbiz.base.start.StartupCommand)2 StartupCommandUtil (org.apache.ofbiz.base.start.StartupCommandUtil)2 Debug (org.apache.ofbiz.base.util.Debug)2