Search in sources :

Example 11 with ServiceInfo

use of org.apache.openejb.assembler.classic.ServiceInfo in project tomee by apache.

the class ConfigurationFactory method getOpenEjbConfiguration.

public OpenEjbConfiguration getOpenEjbConfiguration(final Openejb providedConf) throws OpenEJBException {
    if (sys != null) {
        return sys;
    }
    if (providedConf != null) {
        openejb = providedConf;
    } else if (configLocation != null) {
        openejb = JaxbOpenejb.readConfig(configLocation);
    } else {
        openejb = JaxbOpenejb.createOpenejb();
    }
    for (final SystemProperty sp : openejb.getSystemProperties()) {
        final String name = sp.getName();
        final String value = sp.getValue();
        SystemInstance.get().setProperty(name, value);
        JavaSecurityManagers.setSystemProperty(name, value);
    }
    loadPropertiesDeclaredConfiguration(openejb);
    sys = new OpenEjbConfiguration();
    sys.containerSystem = new ContainerSystemInfo();
    sys.facilities = new FacilitiesInfo();
    // listener + some config can be defined as service
    for (final Service service : openejb.getServices()) {
        final ServiceInfo info = configureService(service, ServiceInfo.class);
        sys.facilities.services.add(info);
    }
    for (final JndiProvider provider : openejb.getJndiProvider()) {
        final JndiContextInfo info = configureService(provider, JndiContextInfo.class);
        sys.facilities.remoteJndiContexts.add(info);
    }
    sys.facilities.securityService = configureService(openejb.getSecurityService(), SecurityServiceInfo.class);
    sys.facilities.transactionService = configureService(openejb.getTransactionManager(), TransactionServiceInfo.class);
    List<ResourceInfo> resources = new ArrayList<>();
    for (final Resource resource : openejb.getResource()) {
        final ResourceInfo resourceInfo = configureService(resource, ResourceInfo.class);
        resources.add(resourceInfo);
    }
    resources = sort(resources, null);
    sys.facilities.resources.addAll(resources);
    if (openejb.getProxyFactory() != null) {
        sys.facilities.intraVmServer = configureService(openejb.getProxyFactory(), ProxyFactoryInfo.class);
    }
    for (final Container declaration : openejb.getContainer()) {
        final ContainerInfo info = createContainerInfo(declaration);
        sys.containerSystem.containers.add(info);
    }
    final List<File> declaredApps = getDeclaredApps();
    for (final File jarFile : declaredApps) {
        try {
            final AppInfo appInfo = configureApplication(jarFile);
            sys.containerSystem.applications.add(appInfo);
        } catch (final OpenEJBException alreadyHandled) {
            final DeploymentExceptionManager exceptionManager = SystemInstance.get().getComponent(DeploymentExceptionManager.class);
            if (exceptionManager != null) {
                exceptionManager.pushDelpoymentException(alreadyHandled);
            }
        }
    }
    final boolean embedded = SystemInstance.get().hasProperty(EJBContainer.class.getName());
    final Options options = SystemInstance.get().getOptions();
    if (options.get("openejb.system.apps", false)) {
        try {
            final boolean extended = SystemApps.isExtended();
            final AppInfo appInfo;
            if (!extended) {
                // do it manually, we know what we need and can skip a bunch of processing
                appInfo = SystemAppInfo.preComputedInfo(this);
            } else {
                appInfo = configureApplication(new AppModule(SystemApps.getSystemModule()));
            }
            // they doesn't use CDI so no need to activate it
            // 1) will be faster
            // 2) will let embedded containers (tomee-embedded mainly) not be noised by it in our singleton service
            appInfo.properties.put("openejb.cdi.activated", "false");
            sys.containerSystem.applications.add(appInfo);
        } catch (final OpenEJBException e) {
            logger.error("Unable to load the system applications.", e);
        }
    } else if (options.get(DEPLOYMENTS_CLASSPATH_PROPERTY, !embedded)) {
        final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        final ArrayList<File> jarFiles = getModulesFromClassPath(declaredApps, classLoader);
        final String appId = "classpath.ear";
        final boolean classpathAsEar = options.get(CLASSPATH_AS_EAR, true);
        try {
            if (classpathAsEar && !jarFiles.isEmpty()) {
                final AppInfo appInfo = configureApplication(classLoader, appId, jarFiles);
                sys.containerSystem.applications.add(appInfo);
            } else {
                for (final File jarFile : jarFiles) {
                    final AppInfo appInfo = configureApplication(jarFile);
                    sys.containerSystem.applications.add(appInfo);
                }
            }
            if (jarFiles.size() == 0) {
                logger.warning("config.noModulesFoundToDeploy");
            }
        } catch (final OpenEJBException alreadyHandled) {
            logger.debug("config.alreadyHandled");
        }
    }
    for (final Deployments deployments : openejb.getDeployments()) {
        if (deployments.isAutoDeploy()) {
            if (deployments.getDir() != null) {
                sys.containerSystem.autoDeploy.add(deployments.getDir());
            }
        }
    }
    final OpenEjbConfiguration finished = sys;
    sys = null;
    openejb = null;
    return finished;
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) Options(org.apache.openejb.loader.Options) ArrayList(java.util.ArrayList) AdditionalDeployments(org.apache.openejb.config.sys.AdditionalDeployments) Deployments(org.apache.openejb.config.sys.Deployments) OpenEjbConfiguration(org.apache.openejb.assembler.classic.OpenEjbConfiguration) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) ServiceInfo(org.apache.openejb.assembler.classic.ServiceInfo) EJBContainer(javax.ejb.embeddable.EJBContainer) Container(org.apache.openejb.config.sys.Container) JndiContextInfo(org.apache.openejb.assembler.classic.JndiContextInfo) EJBContainer(javax.ejb.embeddable.EJBContainer) ContainerSystemInfo(org.apache.openejb.assembler.classic.ContainerSystemInfo) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) DeploymentExceptionManager(org.apache.openejb.assembler.classic.DeploymentExceptionManager) ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) JndiProvider(org.apache.openejb.config.sys.JndiProvider) Resource(org.apache.openejb.config.sys.Resource) AbstractService(org.apache.openejb.config.sys.AbstractService) SecurityService(org.apache.openejb.config.sys.SecurityService) Service(org.apache.openejb.config.sys.Service) AppInfo(org.apache.openejb.assembler.classic.AppInfo) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) FacilitiesInfo(org.apache.openejb.assembler.classic.FacilitiesInfo) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ManagedContainerInfo(org.apache.openejb.assembler.classic.ManagedContainerInfo) BmpEntityContainerInfo(org.apache.openejb.assembler.classic.BmpEntityContainerInfo) StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) CmpEntityContainerInfo(org.apache.openejb.assembler.classic.CmpEntityContainerInfo) StatefulSessionContainerInfo(org.apache.openejb.assembler.classic.StatefulSessionContainerInfo) SingletonSessionContainerInfo(org.apache.openejb.assembler.classic.SingletonSessionContainerInfo) MdbContainerInfo(org.apache.openejb.assembler.classic.MdbContainerInfo) ContainerInfo(org.apache.openejb.assembler.classic.ContainerInfo) File(java.io.File)

Example 12 with ServiceInfo

use of org.apache.openejb.assembler.classic.ServiceInfo in project tomee by apache.

the class ServiceManager method initServer.

protected ServerService initServer(final String serviceName, final Properties serviceProperties) throws IOException {
    final DiscoveryRegistry registry = SystemInstance.get().getComponent(DiscoveryRegistry.class);
    final OpenEjbConfiguration conf = SystemInstance.get().getComponent(OpenEjbConfiguration.class);
    logger.debug("Processing ServerService(id=" + serviceName + ")");
    overrideProperties(serviceName, serviceProperties);
    serviceProperties.setProperty("name", serviceName);
    if (conf != null && conf.facilities != null) {
        final ServiceInfo info = new ServiceInfo();
        info.className = ((Class) serviceProperties.get(ServerService.class)).getName();
        info.service = "ServerService";
        info.id = serviceName;
        info.properties = serviceProperties;
        conf.facilities.services.add(info);
    }
    final boolean enabled = isEnabled(serviceProperties);
    logger.debug("Found ServerService(id=" + serviceName + ", disabled=" + (!enabled) + ")");
    if (enabled) {
        final Class serviceClass = (Class) serviceProperties.get(ServerService.class);
        logger.info("Creating ServerService(id=" + serviceName + ")");
        // log all properties on debug
        if (logger.isDebugEnabled()) {
            for (final Map.Entry<Object, Object> entry : serviceProperties.entrySet()) {
                logger.debug(entry.getKey() + " = " + entry.getValue());
            }
        }
        try {
            // Create Service
            ServerService service;
            ObjectRecipe recipe = new ObjectRecipe(serviceClass);
            try {
                // Do not import.  This class is not available in xbean-reflect-3.3
                final ReflectionUtil.StaticFactory factory = ReflectionUtil.findStaticFactory(serviceClass, "createServerService", null, null, serviceProperties.stringPropertyNames(), Collections.singleton(Option.NAMED_PARAMETERS));
                if (factory != null) {
                    // can throw an exception so call it before next line
                    recipe.setConstructorArgNames(factory.getParameterNames());
                    recipe.setFactoryMethod("createServerService");
                } else if (ReflectionUtil.findStaticFactory(serviceClass, "createServerService", null, null) != null) {
                    // old behavior, remove when sure previous check is ok
                    recipe.setFactoryMethod("createServerService");
                }
            } catch (final Throwable e) {
            //Ignore
            }
            recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
            recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
            service = (ServerService) recipe.create(serviceClass.getClassLoader());
            if (!(service instanceof SelfManaging)) {
                service = manage(serviceName, serviceProperties, service);
            }
            service.init(serviceProperties);
            if (service instanceof DiscoveryAgent) {
                final DiscoveryAgent agent = (DiscoveryAgent) service;
                registry.addDiscoveryAgent(agent);
            }
            if (LocalMBeanServer.isJMXActive()) {
                final MBeanServer server = LocalMBeanServer.get();
                register(serviceName, service, server);
            }
            return service;
        } catch (Throwable t) {
            t.printStackTrace();
            logger.error("service.instantiation.err", t, serviceClass.getName(), t.getClass().getName(), t.getMessage());
        }
    }
    return null;
}
Also used : ReflectionUtil(org.apache.xbean.recipe.ReflectionUtil) OpenEjbConfiguration(org.apache.openejb.assembler.classic.OpenEjbConfiguration) ServiceInfo(org.apache.openejb.assembler.classic.ServiceInfo) ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) Map(java.util.Map) MBeanServer(javax.management.MBeanServer) LocalMBeanServer(org.apache.openejb.monitoring.LocalMBeanServer)

Aggregations

ServiceInfo (org.apache.openejb.assembler.classic.ServiceInfo)12 ArrayList (java.util.ArrayList)4 Properties (java.util.Properties)4 OpenEjbConfiguration (org.apache.openejb.assembler.classic.OpenEjbConfiguration)4 DataBinding (org.apache.cxf.databinding.DataBinding)2 Feature (org.apache.cxf.feature.Feature)2 OpenEJBException (org.apache.openejb.OpenEJBException)2 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)2 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)2 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)2 Service (org.apache.openejb.config.sys.Service)2 File (java.io.File)1 IOException (java.io.IOException)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 EJBContainer (javax.ejb.embeddable.EJBContainer)1 MBeanServer (javax.management.MBeanServer)1 ServletException (javax.servlet.ServletException)1