Search in sources :

Example 71 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo 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 72 with AppInfo

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

the class VmDeploymentManager method deploy.

private ProgressObject deploy(final Target[] targetList, final Properties properties) {
    if (targetList == null) {
        return new ProgressObjectImpl(CommandType.DISTRIBUTE, new NullPointerException("targetList is null"));
    }
    if (!containsDefaultTarget(targetList)) {
        return new ProgressObjectImpl(CommandType.DISTRIBUTE, Collections.<TargetModuleID>emptySet());
    }
    try {
        final AppInfo appInfo = getDeployer().deploy(properties);
        final TargetModuleID targetModuleId = toTargetModuleId(appInfo, null);
        return new ProgressObjectImpl(CommandType.DISTRIBUTE, Collections.singleton(targetModuleId));
    } catch (ValidationFailedException e) {
        final String s = JavaSecurityManagers.getSystemProperty(ReportValidationResults.VALIDATION_LEVEL, "3");
        final int level = Integer.parseInt(s);
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final PrintStream out = new PrintStream(baos);
        out.println(e.getMessage());
        print(e.getErrors(), out, level);
        print(e.getFailures(), out, level);
        print(e.getWarnings(), out, level);
        out.close();
        e = new ValidationFailedException(new String(baos.toByteArray()), e);
        return new ProgressObjectImpl(CommandType.DISTRIBUTE, e);
    } catch (final OpenEJBException e) {
        return new ProgressObjectImpl(CommandType.DISTRIBUTE, e);
    }
}
Also used : PrintStream(java.io.PrintStream) OpenEJBException(org.apache.openejb.OpenEJBException) TargetModuleID(javax.enterprise.deploy.spi.TargetModuleID) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 73 with AppInfo

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

the class JMXDeployer method reload.

@ManagedOperation
@Description("Reload the specified application")
public String reload(final String moduleId) {
    try {
        final Collection<AppInfo> apps = deployer().getDeployedApps();
        boolean found = false;
        for (final AppInfo info : apps) {
            if (info.path.equals(moduleId)) {
                found = true;
                break;
            }
        }
        if (found) {
            deployer().reload(moduleId);
            return "OK";
        } else {
            return "NOT FOUND";
        }
    } catch (final Exception e) {
        return "ERR:" + e.getMessage();
    }
}
Also used : NamingException(javax.naming.NamingException) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Description(org.apache.openejb.api.jmx.Description) ManagedOperation(org.apache.openejb.api.jmx.ManagedOperation)

Example 74 with AppInfo

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

the class CdiScanner method init.

@Override
public void init(final Object object) {
    if (!StartupObject.class.isInstance(object)) {
        return;
    }
    containerLoader = ParentClassLoaderFinder.Helper.get();
    final StartupObject startupObject = StartupObject.class.cast(object);
    final AppInfo appInfo = startupObject.getAppInfo();
    final ClassLoader classLoader = startupObject.getClassLoader();
    final ClassLoaderComparator comparator;
    if (classLoader instanceof ClassLoaderComparator) {
        comparator = (ClassLoaderComparator) classLoader;
    } else {
        comparator = new DefaultClassLoaderComparator(classLoader);
    }
    final WebBeansContext webBeansContext = startupObject.getWebBeansContext();
    final InterceptorsManager interceptorsManager = webBeansContext.getInterceptorsManager();
    // app beans
    for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
        final BeansInfo beans = ejbJar.beans;
        if (beans == null || "false".equalsIgnoreCase(ejbJar.properties.getProperty("openejb.cdi.activated"))) {
            continue;
        }
        if (startupObject.isFromWebApp()) {
            // deploy only the related ejbmodule
            if (!ejbJar.moduleId.equals(startupObject.getWebContext().getId())) {
                continue;
            }
        } else if (ejbJar.webapp && !appInfo.webAppAlone) {
            continue;
        }
        if (appInfo.webAppAlone || !ejbJar.webapp) {
            // "manual" extension to avoid to add it through SPI mecanism
            classes.addAll(asList(TRANSACTIONAL_INTERCEPTORS));
            for (final Class<?> interceptor : TRANSACTIONAL_INTERCEPTORS) {
                interceptorsManager.addEnabledInterceptorClass(interceptor);
            }
        }
        // here for ears we need to skip classes in the parent classloader
        final ClassLoader scl = ClassLoader.getSystemClassLoader();
        final boolean filterByClassLoader = "true".equals(ejbJar.properties.getProperty(OPENEJB_CDI_FILTER_CLASSLOADER, SystemInstance.get().getProperty(OPENEJB_CDI_FILTER_CLASSLOADER, "true")));
        final BeanArchiveService beanArchiveService = webBeansContext.getBeanArchiveService();
        final boolean openejb = OpenEJBBeanInfoService.class.isInstance(beanArchiveService);
        final Map<BeansInfo.BDAInfo, BeanArchiveService.BeanArchiveInformation> infoByBda = new HashMap<>();
        for (final BeansInfo.BDAInfo bda : beans.bdas) {
            if (bda.uri != null) {
                try {
                    beansXml.add(bda.uri.toURL());
                } catch (final MalformedURLException e) {
                // no-op
                }
            }
            infoByBda.put(bda, handleBda(startupObject, classLoader, comparator, beans, scl, filterByClassLoader, beanArchiveService, openejb, bda));
        }
        for (final BeansInfo.BDAInfo bda : beans.noDescriptorBdas) {
            // infoByBda.put() not needed since we know it means annotated
            handleBda(startupObject, classLoader, comparator, beans, scl, filterByClassLoader, beanArchiveService, openejb, bda);
        }
        if (startupObject.getBeanContexts() != null) {
            for (final BeanContext bc : startupObject.getBeanContexts()) {
                final String name = bc.getBeanClass().getName();
                if (BeanContext.Comp.class.getName().equals(name)) {
                    continue;
                }
                boolean cdi = false;
                for (final BeansInfo.BDAInfo bda : beans.bdas) {
                    final BeanArchiveService.BeanArchiveInformation info = infoByBda.get(bda);
                    if (info.getBeanDiscoveryMode() == BeanArchiveService.BeanDiscoveryMode.NONE) {
                        continue;
                    }
                    if (bda.managedClasses.contains(name)) {
                        classes.add(load(name, classLoader));
                        cdi = true;
                        break;
                    }
                }
                if (!cdi) {
                    for (final BeansInfo.BDAInfo bda : beans.noDescriptorBdas) {
                        if (bda.managedClasses.contains(name)) {
                            classes.add(load(name, classLoader));
                            break;
                        }
                    }
                }
            }
        }
        if ("true".equalsIgnoreCase(SystemInstance.get().getProperty("openejb.cdi.debug", "false"))) {
            final Logger logger = Logger.getInstance(LogCategory.OPENEJB, CdiScanner.class.getName());
            logger.info("CDI beans for " + startupObject.getAppInfo().appId + (startupObject.getWebContext() != null ? " webcontext = " + startupObject.getWebContext().getContextRoot() : ""));
            final List<String> names = new ArrayList<>(classes.size());
            for (final Class<?> c : classes) {
                names.add(c.getName());
            }
            Collections.sort(names);
            for (final String c : names) {
                logger.info("    " + c);
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ClassLoaderComparator(org.apache.openejb.util.classloader.ClassLoaderComparator) DefaultClassLoaderComparator(org.apache.openejb.util.classloader.DefaultClassLoaderComparator) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Logger(org.apache.openejb.util.Logger) WebBeansContext(org.apache.webbeans.config.WebBeansContext) BeansInfo(org.apache.openejb.assembler.classic.BeansInfo) DefaultClassLoaderComparator(org.apache.openejb.util.classloader.DefaultClassLoaderComparator) BeanArchiveService(org.apache.webbeans.spi.BeanArchiveService) AppInfo(org.apache.openejb.assembler.classic.AppInfo) BeanContext(org.apache.openejb.BeanContext) InterceptorsManager(org.apache.webbeans.intercept.InterceptorsManager) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo)

Example 75 with AppInfo

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

the class ListEjbMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final Deployer deployer = (Deployer) lookup("openejb/DeployerBusinessRemote");
    final Collection<AppInfo> infos = deployer.getDeployedApps();
    final Lines lines = new Lines();
    lines.add(new Line("Name", "Class", "Interface Type", "Bean Type"));
    for (final AppInfo info : infos) {
        for (final EjbJarInfo ejbJar : info.ejbJars) {
            for (final EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
                lines.add(new Line(bean.ejbDeploymentId, bean.ejbClass, getType(bean), componentType(bean)));
            }
        }
    }
    lines.print(new LogPrinterStream(getLog()));
}
Also used : Line(org.apache.openejb.table.Line) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) Deployer(org.apache.openejb.assembler.Deployer) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Lines(org.apache.openejb.table.Lines)

Aggregations

AppInfo (org.apache.openejb.assembler.classic.AppInfo)109 File (java.io.File)49 Assembler (org.apache.openejb.assembler.classic.Assembler)49 Test (org.junit.Test)31 HashMap (java.util.HashMap)29 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)25 EjbJar (org.apache.openejb.jee.EjbJar)17 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)16 ContainerSystem (org.apache.openejb.spi.ContainerSystem)15 OpenEJBException (org.apache.openejb.OpenEJBException)14 AppModule (org.apache.openejb.config.AppModule)14 Map (java.util.Map)12 EjbModule (org.apache.openejb.config.EjbModule)11 Properties (java.util.Properties)10 Persistence (org.apache.openejb.jee.jpa.unit.Persistence)10 ArrayList (java.util.ArrayList)9 InitialContext (javax.naming.InitialContext)9 StatelessBean (org.apache.openejb.jee.StatelessBean)9 PersistenceUnit (org.apache.openejb.jee.jpa.unit.PersistenceUnit)9 IOException (java.io.IOException)8