Search in sources :

Example 1 with ContainerException

use of org.apache.ofbiz.base.container.ContainerException in project ofbiz-framework by apache.

the class CatalinaContainer method prepareChannelSender.

private ReplicationTransmitter prepareChannelSender(Property clusterProp) throws ContainerException {
    ReplicationTransmitter trans = new ReplicationTransmitter();
    try {
        MultiPointSender mps = (MultiPointSender) Class.forName(ContainerConfig.getPropertyValue(clusterProp, "replication-mode", "org.apache.catalina.tribes.transport.bio.PooledMultiSender")).newInstance();
        trans.setTransport(mps);
    } catch (Exception exc) {
        throw new ContainerException("Cluster configuration requires a valid replication-mode property: " + exc.getMessage());
    }
    return trans;
}
Also used : MultiPointSender(org.apache.catalina.tribes.transport.MultiPointSender) ContainerException(org.apache.ofbiz.base.container.ContainerException) ReplicationTransmitter(org.apache.catalina.tribes.transport.ReplicationTransmitter) NamingException(javax.naming.NamingException) LifecycleException(org.apache.catalina.LifecycleException) SAXException(org.xml.sax.SAXException) ContainerException(org.apache.ofbiz.base.container.ContainerException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 2 with ContainerException

use of org.apache.ofbiz.base.container.ContainerException in project ofbiz-framework by apache.

the class CatalinaContainer method isContextDistributable.

private boolean isContextDistributable(ContainerConfig.Configuration configuration, String location) throws ContainerException {
    String webXmlFilePath = new StringBuilder().append("file:///").append(location).append("/WEB-INF/web.xml").toString();
    boolean appIsDistributable = ContainerConfig.getPropertyValue(configuration, "apps-distributable", true);
    try {
        URL webXmlUrl = FlexibleLocation.resolveLocation(webXmlFilePath);
        File webXmlFile = new File(webXmlUrl.getFile());
        if (webXmlFile.exists()) {
            Document webXmlDoc = UtilXml.readXmlDocument(webXmlUrl);
            return appIsDistributable && webXmlDoc.getElementsByTagName("distributable").getLength() > 0;
        }
        Debug.logInfo(webXmlFilePath + " not found.", module);
        return appIsDistributable;
    } catch (SAXException | ParserConfigurationException | IOException e) {
        throw new ContainerException(e);
    }
}
Also used : ContainerException(org.apache.ofbiz.base.container.ContainerException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) File(java.io.File) URL(java.net.URL) SAXException(org.xml.sax.SAXException)

Example 3 with ContainerException

use of org.apache.ofbiz.base.container.ContainerException in project ofbiz-framework by apache.

the class CatalinaContainer method prepareTomcatEngineValves.

private List<Valve> prepareTomcatEngineValves(Property engineConfig) throws ContainerException {
    List<Valve> engineValves = new ArrayList<>();
    // configure the CrossSubdomainSessionValve
    if (ContainerConfig.getPropertyValue(engineConfig, "enable-cross-subdomain-sessions", false)) {
        engineValves.add(new CrossSubdomainSessionValve());
    }
    // configure the SslAcceleratorValve
    String sslAcceleratorPortStr = ContainerConfig.getPropertyValue(engineConfig, "ssl-accelerator-port", null);
    if (UtilValidate.isNotEmpty(sslAcceleratorPortStr)) {
        Integer sslAcceleratorPort = Integer.valueOf(sslAcceleratorPortStr);
        SslAcceleratorValve sslAcceleratorValve = new SslAcceleratorValve();
        sslAcceleratorValve.setSslAcceleratorPort(sslAcceleratorPort);
        engineValves.add(sslAcceleratorValve);
    }
    // configure the AccessLogValve
    String logDir = ContainerConfig.getPropertyValue(engineConfig, "access-log-dir", null);
    if (logDir != null) {
        AccessLogValve accessLogValve = new AccessLogValve();
        logDir = logDir.startsWith("/") ? System.getProperty("ofbiz.home") + "/" + logDir : logDir;
        File logFile = new File(logDir);
        if (!logFile.isDirectory()) {
            throw new ContainerException("Log directory [" + logDir + "] is not available; make sure the directory is created");
        }
        accessLogValve.setDirectory(logFile.getAbsolutePath());
        String accessLogPattern = ContainerConfig.getPropertyValue(engineConfig, "access-log-pattern", null);
        if (UtilValidate.isNotEmpty(accessLogPattern)) {
            accessLogValve.setPattern(accessLogPattern);
        }
        String accessLogPrefix = ContainerConfig.getPropertyValue(engineConfig, "access-log-prefix", null);
        if (UtilValidate.isNotEmpty(accessLogPrefix)) {
            accessLogValve.setPrefix(accessLogPrefix);
        }
        accessLogValve.setRotatable(ContainerConfig.getPropertyValue(engineConfig, "access-log-rotate", false));
        engineValves.add(accessLogValve);
    }
    return engineValves;
}
Also used : ContainerException(org.apache.ofbiz.base.container.ContainerException) ArrayList(java.util.ArrayList) ReplicationValve(org.apache.catalina.ha.tcp.ReplicationValve) Valve(org.apache.catalina.Valve) AccessLogValve(org.apache.catalina.valves.AccessLogValve) File(java.io.File) AccessLogValve(org.apache.catalina.valves.AccessLogValve)

Example 4 with ContainerException

use of org.apache.ofbiz.base.container.ContainerException in project ofbiz-framework by apache.

the class EntityDataLoadContainer method loadData.

private void loadData(Delegator delegator, Delegator baseDelegator, Collection<ComponentConfig> allComponents, GenericHelperInfo helperInfo, Map<String, String> loadDataProps) throws ContainerException {
    // prepare command line properties passed by user
    int txTimeout = getTransactionTimeout(loadDataProps.get(TIMEOUT));
    boolean useDummyFks = isPropertySet(loadDataProps, CREATE_F_KEYS);
    boolean maintainTxs = isPropertySet(loadDataProps, MAINTAIN_TXS);
    boolean tryInserts = isPropertySet(loadDataProps, TRY_INSERTS);
    boolean continueOnFail = isPropertySet(loadDataProps, CONTINUE_ON_FAIL);
    List<URL> urlList = prepareDataUrls(delegator, baseDelegator, allComponents, helperInfo, loadDataProps);
    List<String> infoMessages = new ArrayList<String>();
    List<Object> errorMessages = new ArrayList<Object>();
    int totalRowsChanged = 0;
    logDataLoadingPlan(urlList, delegator.getDelegatorName());
    for (URL dataUrl : urlList) {
        try {
            int rowsChanged = EntityDataLoader.loadData(dataUrl, helperInfo.getHelperBaseName(), delegator, errorMessages, txTimeout, useDummyFks, maintainTxs, tryInserts, continueOnFail);
            totalRowsChanged += rowsChanged;
            infoMessages.add(createDataLoadMessage(dataUrl, rowsChanged, totalRowsChanged));
        } catch (GenericEntityException e) {
            if (continueOnFail) {
                Debug.logError(e, "Error loading data file: " + dataUrl.toExternalForm(), module);
            } else {
                throw new ContainerException(e);
            }
        }
    }
    logDataLoadingResults(infoMessages, errorMessages, totalRowsChanged);
}
Also used : ContainerException(org.apache.ofbiz.base.container.ContainerException) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) ArrayList(java.util.ArrayList) URL(java.net.URL) UtilURL(org.apache.ofbiz.base.util.UtilURL)

Example 5 with ContainerException

use of org.apache.ofbiz.base.container.ContainerException in project ofbiz-framework by apache.

the class EntityDataLoadContainer method init.

@Override
public void init(List<StartupCommand> ofbizCommands, String name, String configFile) throws ContainerException {
    this.name = name;
    // get the data-load properties passed by the user in the command line
    Map<String, String> loadDataProps = ofbizCommands.stream().filter(command -> command.getName().equals(StartupCommandUtil.StartupOption.LOAD_DATA.getName())).map(command -> command.getProperties()).findFirst().get();
    /* disable job scheduler, JMS listener and startup services
         * FIXME: This is not thread-safe. */
    ServiceDispatcher.enableJM(false);
    ServiceDispatcher.enableJMS(false);
    ServiceDispatcher.enableSvcs(false);
    Configuration configuration = ContainerConfig.getConfiguration(name, configFile);
    Property delegatorNameProp = configuration.getProperty("delegator-name");
    String overrideDelegator = loadDataProps.get(DELEGATOR_NAME);
    if ("all-tenants".equals(overrideDelegator)) {
        // load data for all tenants
        for (GenericValue tenant : getTenantList(delegatorNameProp)) {
            String tenantDelegator = delegatorNameProp.value + "#" + tenant.getString("tenantId");
            loadDataForDelegator(loadDataProps, configuration, delegatorNameProp, tenantDelegator);
        }
    } else {
        // load data for a single delegator
        loadDataForDelegator(loadDataProps, configuration, delegatorNameProp, overrideDelegator);
    }
}
Also used : EntityCondition(org.apache.ofbiz.entity.condition.EntityCondition) Arrays(java.util.Arrays) ComponentConfig(org.apache.ofbiz.base.component.ComponentConfig) EntityDataLoader(org.apache.ofbiz.entity.util.EntityDataLoader) URL(java.net.URL) EntityQuery(org.apache.ofbiz.entity.util.EntityQuery) UtilURL(org.apache.ofbiz.base.util.UtilURL) ContainerException(org.apache.ofbiz.base.container.ContainerException) UtilValidate(org.apache.ofbiz.base.util.UtilValidate) EntityExpr(org.apache.ofbiz.entity.condition.EntityExpr) DelegatorFactory(org.apache.ofbiz.entity.DelegatorFactory) NumberFormat(java.text.NumberFormat) TreeSet(java.util.TreeSet) StartupCommandUtil(org.apache.ofbiz.base.start.StartupCommandUtil) ArrayList(java.util.ArrayList) ContainerConfig(org.apache.ofbiz.base.container.ContainerConfig) EntityOperator(org.apache.ofbiz.entity.condition.EntityOperator) Locale(java.util.Locale) Map(java.util.Map) ServiceDispatcher(org.apache.ofbiz.service.ServiceDispatcher) Property(org.apache.ofbiz.base.container.ContainerConfig.Configuration.Property) Delegator(org.apache.ofbiz.entity.Delegator) Configuration(org.apache.ofbiz.base.container.ContainerConfig.Configuration) EntityUtil(org.apache.ofbiz.entity.util.EntityUtil) DatabaseUtil(org.apache.ofbiz.entity.jdbc.DatabaseUtil) StartupCommand(org.apache.ofbiz.base.start.StartupCommand) GenericValue(org.apache.ofbiz.entity.GenericValue) GenericHelperInfo(org.apache.ofbiz.entity.datasource.GenericHelperInfo) Collection(java.util.Collection) StringUtil(org.apache.ofbiz.base.util.StringUtil) ModelEntity(org.apache.ofbiz.entity.model.ModelEntity) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) Debug(org.apache.ofbiz.base.util.Debug) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) Optional(java.util.Optional) Container(org.apache.ofbiz.base.container.Container) GenericValue(org.apache.ofbiz.entity.GenericValue) Configuration(org.apache.ofbiz.base.container.ContainerConfig.Configuration) 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