Search in sources :

Example 6 with Deployments

use of org.apache.openejb.config.sys.Deployments in project tomee by apache.

the class ConfigurationFactory method getDeclaredApps.

private List<File> getDeclaredApps() {
    // make a copy of the list because we update it
    final List<Deployments> deployments = new ArrayList<Deployments>();
    if (openejb != null) {
        deployments.addAll(openejb.getDeployments());
    }
    Collection<Deployments> additionalDeploymentsList = Collections.emptyList();
    try {
        final File additionalDeploymentFile = SystemInstance.get().getBase().getFile(ADDITIONAL_DEPLOYMENTS, false);
        if (additionalDeploymentFile.exists()) {
            InputStream fis = null;
            try {
                fis = IO.read(additionalDeploymentFile);
                final AdditionalDeployments additionalDeployments = JaxbOpenejb.unmarshal(AdditionalDeployments.class, fis);
                additionalDeploymentsList = additionalDeployments.getDeployments();
            } catch (final Exception e) {
                logger.error("can't read " + ADDITIONAL_DEPLOYMENTS, e);
            } finally {
                IO.close(fis);
            }
        }
    } catch (final Exception e) {
        logger.info("No additional deployments found: " + e);
    }
    // resolve jar locations //////////////////////////////////////  BEGIN  ///////
    final FileUtils base = SystemInstance.get().getBase();
    final List<Deployments> autoDeploy = new ArrayList<Deployments>();
    final List<File> declaredAppsUrls = new ArrayList<File>();
    for (final Deployments deployment : deployments) {
        try {
            DeploymentsResolver.loadFrom(deployment, base, declaredAppsUrls);
            if (deployment.isAutoDeploy()) {
                autoDeploy.add(deployment);
            }
        } catch (final SecurityException se) {
            logger.warning("Security check failed on deployment: " + deployment.getFile(), se);
        }
    }
    for (final Deployments additionalDep : additionalDeploymentsList) {
        if (additionalDep.getFile() != null) {
            declaredAppsUrls.add(Files.path(base.getDirectory().getAbsoluteFile(), additionalDep.getFile()));
        } else if (additionalDep.getDir() != null) {
            declaredAppsUrls.add(Files.path(base.getDirectory().getAbsoluteFile(), additionalDep.getDir()));
        }
        if (additionalDep.isAutoDeploy()) {
            autoDeploy.add(additionalDep);
        }
    }
    if (autoDeploy.size() > 0) {
        final AutoDeployer autoDeployer = new AutoDeployer(this, autoDeploy);
        SystemInstance.get().setComponent(AutoDeployer.class, autoDeployer);
        SystemInstance.get().addObserver(autoDeployer);
    }
    return declaredAppsUrls;
}
Also used : FileUtils(org.apache.openejb.loader.FileUtils) InputStream(java.io.InputStream) AdditionalDeployments(org.apache.openejb.config.sys.AdditionalDeployments) Deployments(org.apache.openejb.config.sys.Deployments) ArrayList(java.util.ArrayList) AdditionalDeployments(org.apache.openejb.config.sys.AdditionalDeployments) File(java.io.File) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) OpenEJBException(org.apache.openejb.OpenEJBException) MalformedURLException(java.net.MalformedURLException)

Example 7 with Deployments

use of org.apache.openejb.config.sys.Deployments 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 8 with Deployments

use of org.apache.openejb.config.sys.Deployments in project tomee by apache.

the class DeployerEjbTest method removeDeploymentsLogic.

@Test
public void removeDeploymentsLogic() throws Exception {
    final File dir1 = Files.mkdirs(new File("target/DeployerEjbTest/removeDeploymentsLogic/app1/"));
    final File file = SystemInstance.get().getBase().getFile(ADDITIONAL_DEPLOYMENTS, false);
    final Method save = DeployerEjb.class.getDeclaredMethod("saveDeployment", File.class, boolean.class);
    save.setAccessible(true);
    {
        final AdditionalDeployments deployments = new AdditionalDeployments();
        final Deployments d1 = new Deployments();
        d1.setDir(dir1.getCanonicalPath());
        deployments.getDeployments().add(d1);
        final Deployments d12 = new Deployments();
        d12.setDir(dir1.getCanonicalPath());
        deployments.getDeployments().add(d12);
        final Deployments d2 = new Deployments();
        d2.setFile(new File(File.listRoots()[0], "/foo/bar/app.war").getAbsolutePath());
        deployments.getDeployments().add(d2);
        try (final FileOutputStream fos = new FileOutputStream(file)) {
            JaxbOpenejb.marshal(AdditionalDeployments.class, deployments, fos);
        }
        assertDeployementsSize(file, 3);
    }
    {
        save.invoke(new DeployerEjb(), dir1, false);
        assertDeployementsSize(file, 2);
    }
    {
        save.invoke(new DeployerEjb(), new File(dir1.getParentFile(), dir1.getName() + ".war"), false);
        assertDeployementsSize(file, 1);
    }
    {
        save.invoke(new DeployerEjb(), new File(File.listRoots()[0], "/foo/bar/app.war"), false);
        assertDeployementsSize(file, 0);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) Deployments(org.apache.openejb.config.sys.Deployments) AdditionalDeployments(org.apache.openejb.config.sys.AdditionalDeployments) Method(java.lang.reflect.Method) AdditionalDeployments(org.apache.openejb.config.sys.AdditionalDeployments) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)8 Deployments (org.apache.openejb.config.sys.Deployments)8 OpenEJBException (org.apache.openejb.OpenEJBException)5 AdditionalDeployments (org.apache.openejb.config.sys.AdditionalDeployments)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)3 InputStream (java.io.InputStream)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)2 AbstractService (org.apache.openejb.config.sys.AbstractService)2 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1 OutputStream (java.io.OutputStream)1 Method (java.lang.reflect.Method)1 URI (java.net.URI)1 URLClassLoader (java.net.URLClassLoader)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1