Search in sources :

Example 6 with GenericConfigException

use of org.apache.ofbiz.base.config.GenericConfigException in project ofbiz-framework by apache.

the class GenericEngineFactory method getGenericEngine.

/**
 * Gets the GenericEngine instance that corresponds to given the name
 *@param engineName Name of the engine
 *@return GenericEngine that corresponds to the engineName
 */
public GenericEngine getGenericEngine(String engineName) throws GenericServiceException {
    String className = null;
    try {
        className = ServiceConfigUtil.getServiceEngine().getEngine(engineName).getClassName();
    } catch (GenericConfigException e) {
        throw new GenericServiceException(e);
    }
    GenericEngine engine = engines.get(engineName);
    if (engine == null) {
        synchronized (GenericEngineFactory.class) {
            engine = engines.get(engineName);
            if (engine == null) {
                try {
                    ClassLoader loader = Thread.currentThread().getContextClassLoader();
                    Class<?> c = loader.loadClass(className);
                    Constructor<GenericEngine> cn = UtilGenerics.cast(c.getConstructor(ServiceDispatcher.class));
                    engine = cn.newInstance(dispatcher);
                } catch (Exception e) {
                    throw new GenericServiceException(e.getMessage(), e);
                }
                if (engine != null) {
                    engines.put(engineName, engine);
                }
            }
        }
    }
    return engine;
}
Also used : GenericConfigException(org.apache.ofbiz.base.config.GenericConfigException) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) ServiceDispatcher(org.apache.ofbiz.service.ServiceDispatcher) GenericConfigException(org.apache.ofbiz.base.config.GenericConfigException) GenericServiceException(org.apache.ofbiz.service.GenericServiceException)

Example 7 with GenericConfigException

use of org.apache.ofbiz.base.config.GenericConfigException in project ofbiz-framework by apache.

the class DispatchContext method getGlobalServiceMap.

private Map<String, ModelService> getGlobalServiceMap() {
    Map<String, ModelService> serviceMap = modelServiceMapByModel.get(this.model);
    if (serviceMap == null) {
        serviceMap = new HashMap<>();
        List<Future<Map<String, ModelService>>> futures = new LinkedList<>();
        List<GlobalServices> globalServicesList = null;
        try {
            globalServicesList = ServiceConfigUtil.getServiceEngine().getGlobalServices();
        } catch (GenericConfigException e) {
            // FIXME: Refactor API so exceptions can be thrown and caught.
            Debug.logError(e, module);
            throw new RuntimeException(e.getMessage());
        }
        for (GlobalServices globalServices : globalServicesList) {
            ResourceHandler handler = new MainResourceHandler(ServiceConfigUtil.getServiceEngineXmlFileName(), globalServices.getLoader(), globalServices.getLocation());
            futures.add(ExecutionPool.GLOBAL_FORK_JOIN.submit(createServiceReaderCallable(handler)));
        }
        // get all of the component resource model stuff, ie specified in each ofbiz-component.xml file
        for (ComponentConfig.ServiceResourceInfo componentResourceInfo : ComponentConfig.getAllServiceResourceInfos("model")) {
            futures.add(ExecutionPool.GLOBAL_FORK_JOIN.submit(createServiceReaderCallable(componentResourceInfo.createResourceHandler())));
        }
        for (Map<String, ModelService> servicesMap : ExecutionPool.getAllFutures(futures)) {
            if (servicesMap != null) {
                serviceMap.putAll(servicesMap);
            }
        }
        Map<String, ModelService> cachedServiceMap = modelServiceMapByModel.putIfAbsentAndGet(this.model, serviceMap);
        if (cachedServiceMap == serviceMap) {
            // same object: this means that the object created by this thread was actually added to the cache
            ServiceEcaUtil.reloadConfig();
        }
    }
    return serviceMap;
}
Also used : ResourceHandler(org.apache.ofbiz.base.config.ResourceHandler) MainResourceHandler(org.apache.ofbiz.base.config.MainResourceHandler) LinkedList(java.util.LinkedList) GenericConfigException(org.apache.ofbiz.base.config.GenericConfigException) MainResourceHandler(org.apache.ofbiz.base.config.MainResourceHandler) ComponentConfig(org.apache.ofbiz.base.component.ComponentConfig) Future(java.util.concurrent.Future) GlobalServices(org.apache.ofbiz.service.config.model.GlobalServices)

Example 8 with GenericConfigException

use of org.apache.ofbiz.base.config.GenericConfigException in project ofbiz-framework by apache.

the class ServiceConfigUtil method getServiceConfig.

/**
 * Returns the <code>ServiceConfig</code> instance.
 * @throws GenericConfigException
 */
public static ServiceConfig getServiceConfig() throws GenericConfigException {
    ServiceConfig instance = serviceConfigCache.get("instance");
    if (instance == null) {
        Element serviceConfigElement = getXmlDocument().getDocumentElement();
        instance = ServiceConfig.create(serviceConfigElement);
        serviceConfigCache.putIfAbsent("instance", instance);
        instance = serviceConfigCache.get("instance");
        for (ServiceConfigListener listener : configListeners) {
            try {
                listener.onServiceConfigChange(instance);
            } catch (Exception e) {
                Debug.logError(e, "Exception thrown while notifying listener " + listener + ": ", module);
            }
        }
    }
    return instance;
}
Also used : ServiceConfig(org.apache.ofbiz.service.config.model.ServiceConfig) Element(org.w3c.dom.Element) GenericConfigException(org.apache.ofbiz.base.config.GenericConfigException)

Example 9 with GenericConfigException

use of org.apache.ofbiz.base.config.GenericConfigException in project ofbiz-framework by apache.

the class AbstractEngine method createLocationMap.

// creates the location alias map
protected static Map<String, String> createLocationMap() {
    Map<String, String> tmpMap = new HashMap<>();
    List<ServiceLocation> locationsList = null;
    try {
        locationsList = ServiceConfigUtil.getServiceEngine().getServiceLocations();
    } catch (GenericConfigException e) {
        // FIXME: Refactor API so exceptions can be thrown and caught.
        Debug.logError(e, module);
        throw new RuntimeException(e.getMessage());
    }
    for (ServiceLocation e : locationsList) {
        tmpMap.put(e.getName(), e.getLocation());
    }
    Debug.logInfo("Loaded Service Locations: " + tmpMap, module);
    return Collections.unmodifiableMap(tmpMap);
}
Also used : GenericConfigException(org.apache.ofbiz.base.config.GenericConfigException) HashMap(java.util.HashMap) ServiceLocation(org.apache.ofbiz.service.config.model.ServiceLocation)

Example 10 with GenericConfigException

use of org.apache.ofbiz.base.config.GenericConfigException in project ofbiz-framework by apache.

the class JNDITransactionFactory method getJndiConnection.

public static Connection getJndiConnection(String jndiName, String jndiServerName) throws SQLException, GenericEntityException {
    DataSource ds = dsCache.get(jndiName);
    if (ds != null) {
        if (ds instanceof XADataSource) {
            XADataSource xads = (XADataSource) ds;
            return TransactionUtil.enlistConnection(xads.getXAConnection());
        }
        return ds.getConnection();
    }
    try {
        if (Debug.infoOn()) {
            Debug.logInfo("Doing JNDI lookup for name " + jndiName, module);
        }
        InitialContext ic = JNDIContextFactory.getInitialContext(jndiServerName);
        if (ic != null) {
            ds = (DataSource) ic.lookup(jndiName);
        } else {
            Debug.logWarning("Initial Context returned was NULL for server name " + jndiServerName, module);
        }
        if (ds != null) {
            if (Debug.verboseOn()) {
                Debug.logVerbose("Got a Datasource object.", module);
            }
            dsCache.putIfAbsent(jndiName, ds);
            ds = dsCache.get(jndiName);
            Connection con;
            if (ds instanceof XADataSource) {
                if (Debug.infoOn()) {
                    Debug.logInfo("Got XADataSource for name " + jndiName, module);
                }
                XADataSource xads = (XADataSource) ds;
                XAConnection xac = xads.getXAConnection();
                con = TransactionUtil.enlistConnection(xac);
            } else {
                if (Debug.infoOn()) {
                    Debug.logInfo("Got DataSource for name " + jndiName, module);
                }
                con = ds.getConnection();
            }
            return con;
        }
        Debug.logError("Datasource returned was NULL.", module);
    } catch (NamingException ne) {
        Debug.logWarning(ne, "Failed to find DataSource named " + jndiName + " in JNDI server with name " + jndiServerName + ". Trying normal database.", module);
    } catch (GenericConfigException gce) {
        throw new GenericEntityException("Problems with the JNDI configuration.", gce.getNested());
    }
    return null;
}
Also used : XADataSource(javax.sql.XADataSource) GenericConfigException(org.apache.ofbiz.base.config.GenericConfigException) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext) XADataSource(javax.sql.XADataSource) DataSource(javax.sql.DataSource) XAConnection(javax.sql.XAConnection)

Aggregations

GenericConfigException (org.apache.ofbiz.base.config.GenericConfigException)27 Element (org.w3c.dom.Element)9 LinkedList (java.util.LinkedList)7 MainResourceHandler (org.apache.ofbiz.base.config.MainResourceHandler)7 ResourceHandler (org.apache.ofbiz.base.config.ResourceHandler)7 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)7 GenericValue (org.apache.ofbiz.entity.GenericValue)5 ComponentConfig (org.apache.ofbiz.base.component.ComponentConfig)4 UtilTimer (org.apache.ofbiz.base.util.UtilTimer)4 GenericEntityConfException (org.apache.ofbiz.entity.GenericEntityConfException)4 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)4 Document (org.w3c.dom.Document)4 Calendar (com.ibm.icu.util.Calendar)3 Timestamp (java.sql.Timestamp)3 HashMap (java.util.HashMap)3 DelegatorElement (org.apache.ofbiz.entity.config.model.DelegatorElement)3 IOException (java.io.IOException)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2