Search in sources :

Example 56 with AppInfo

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

the class TomEEContainer method deploy.

@Override
public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentException {
    try {
        final Dump dump = dumpFile(archive);
        final File file = dump.getFile();
        final String fileName = file.getName();
        if (dump.isCreated() && (fileName.endsWith(".war") || fileName.endsWith(".ear"))) {
            // extracted folder, TODO: openejb work dir is ignored here
            Files.deleteOnExit(new File(file.getParentFile(), fileName.substring(0, fileName.length() - 4)));
        }
        final AppInfo appInfo;
        final String archiveName = archive.getName();
        try {
            if (dump.isCreated() || !configuration.isSingleDeploymentByArchiveName(archiveName)) {
                appInfo = doDeploy(archive, file);
                if (appInfo != null) {
                    moduleIds.put(archiveName, new DeployedApp(appInfo.path, file));
                    // "i" folder
                    Files.deleteOnExit(file);
                }
            } else {
                final String path = moduleIds.get(archiveName).path;
                AppInfo selected = null;
                for (final AppInfo info : getDeployedApps()) {
                    if (path.equals(info.path)) {
                        selected = info;
                        break;
                    }
                }
                appInfo = selected;
            }
            if (appInfo == null) {
                LOGGER.severe("appInfo was not found for " + file.getPath() + ", available are: " + apps());
                throw new OpenEJBException("can't get appInfo");
            }
        } catch (final OpenEJBException re) {
            // clean up in undeploy needs it
            moduleIds.put(archiveName, new DeployedApp(file.getPath(), file));
            throw re;
        }
        if (options.get("tomee.appinfo.output", false)) {
            Info.marshal(appInfo);
        }
        final HTTPContext httpContext = new HTTPContext(configuration.getHost(), configuration.getHttpPort());
        addArquillianServlet(archive, appInfo, archiveName, httpContext);
        addServlets(httpContext, appInfo);
        return new ProtocolMetaData().addContext(httpContext);
    } catch (final Exception e) {
        throw new DeploymentException("Unable to deploy", e);
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) HTTPContext(org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) File(java.io.File) NamingException(javax.naming.NamingException) UndeployException(org.apache.openejb.UndeployException) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) OpenEJBException(org.apache.openejb.OpenEJBException) IOException(java.io.IOException) NoSuchApplicationException(org.apache.openejb.NoSuchApplicationException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 57 with AppInfo

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

the class TomEEContainer method doDeploy.

protected AppInfo doDeploy(final Archive<?> archive, final File file) throws OpenEJBException, NamingException, IOException {
    AppInfo appInfo;
    final Properties deployerProperties = getDeployerProperties();
    if (deployerProperties == null) {
        appInfo = deployer().deploy(file.getAbsolutePath());
    } else {
        final Properties props = new Properties();
        props.putAll(deployerProperties);
        if ("true".equalsIgnoreCase(deployerProperties.getProperty(DeployerEjb.OPENEJB_USE_BINARIES, "false"))) {
            final byte[] slurpBinaries = IO.slurpBytes(file);
            props.put(DeployerEjb.OPENEJB_VALUE_BINARIES, slurpBinaries);
            props.put(DeployerEjb.OPENEJB_PATH_BINARIES, archive.getName());
        }
        appInfo = deployer().deploy(file.getAbsolutePath(), props);
    }
    return appInfo;
}
Also used : Properties(java.util.Properties) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 58 with AppInfo

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

the class EmbeddedTomEEContainer method deploy.

@Override
public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentException {
    try {
        /* don't do it since it should be configurable
            final File tempDir = Files.createTempDir();
            final File file = new File(tempDir, name);
            */
        final String name = archive.getName();
        final Dump dump = this.dumpFile(archive);
        final File file = dump.getFile();
        if (dump.isCreated() || !configuration.isSingleDeploymentByArchiveName(name)) {
            ARCHIVES.put(archive, file);
            final Thread current = Thread.currentThread();
            final ClassLoader loader = current.getContextClassLoader();
            // multiple deployments, don't leak a loader
            current.setContextClassLoader(ParentClassLoaderFinder.Helper.get());
            try {
                this.container.deploy(name, file);
            } finally {
                current.setContextClassLoader(loader);
            }
        }
        final AppInfo info = this.container.getInfo(name);
        final String context = this.getArchiveNameWithoutExtension(archive);
        final HTTPContext httpContext = new HTTPContext(this.configuration.getHost(), this.configuration.getHttpPort());
        httpContext.add(new Servlet("ArquillianServletRunner", "/" + context));
        this.addServlets(httpContext, info);
        // ensure tests can use request/session scopes even if we don't have a request
        startCdiContexts(name);
        TestObserver.ClassLoaders classLoaders = this.classLoader.get();
        if (classLoaders == null) {
            classLoaders = new TestObserver.ClassLoaders();
            this.classLoader.set(classLoaders);
        }
        classLoaders.register(archive.getName(), SystemInstance.get().getComponent(ContainerSystem.class).getAppContext(info.appId).getClassLoader());
        return new ProtocolMetaData().addContext(httpContext);
    } catch (final Exception e) {
        throw new DeploymentException("Unable to deploy", e);
    }
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) HTTPContext(org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext) TestObserver(org.apache.openejb.arquillian.common.TestObserver) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Servlet(org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) File(java.io.File)

Example 59 with AppInfo

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

the class TomcatWebAppBuilder method checkHost.

/**
 * {@inheritDoc}
 */
@Override
public synchronized void checkHost(final StandardHost standardHost) {
    if (noHostCheck) {
        return;
    }
    if (standardHost.getAutoDeploy()) {
        // Undeploy any modified application
        for (final Iterator<Map.Entry<String, DeployedApplication>> iterator = deployedApps.entrySet().iterator(); iterator.hasNext(); ) {
            final Map.Entry<String, DeployedApplication> entry = iterator.next();
            final DeployedApplication deployedApplication = entry.getValue();
            if (deployedApplication.isModified()) {
                // TODO: for war use StandardContext.redeploy()
                if (deployedApplication.appInfo != null) {
                    // can happen with badly formed config
                    try {
                        getAssembler().destroyApplication(deployedApplication.appInfo.path);
                    } catch (final Exception e) {
                        logger.error("Unable to application " + deployedApplication.appInfo.path, e);
                    }
                } else {
                    logger.error("appinfo is null for " + deployedApplication);
                }
                iterator.remove();
            }
        }
        // Deploy new applications
        final File appBase = appBase(standardHost);
        final File[] files = appBase.listFiles();
        if (null != files) {
            for (File file : files) {
                if (file.getName().endsWith(".tmp")) {
                    // tomcat is uploading, see org.apache.catalina.manager.ManagerServlet.deploy(java.io.PrintWriter, org.apache.catalina.util.ContextName, java.lang.String, boolean, javax.servlet.http.HttpServletRequest, org.apache.tomcat.util.res.StringManager)
                    continue;
                }
                final String name = file.getName();
                // ignore war files
                if (name.toLowerCase().endsWith(".war") || isRoot(name) || name.equalsIgnoreCase("META-INF") || name.equalsIgnoreCase("WEB-INF")) {
                    continue;
                }
                // Simple fix for TOMEE-23
                if (name.toLowerCase().equals(".ds_store")) {
                    continue;
                }
                // ignore unpacked web apps
                if (file.isDirectory() && new File(file, "WEB-INF").exists()) {
                    continue;
                }
                // ignore unpacked apps where packed version is present (packed version is owner)
                if (file.isDirectory() && (new File(file.getParent(), file.getName() + ".ear").exists() || new File(file.getParent(), file.getName() + ".war").exists() || new File(file.getParent(), file.getName() + ".rar").exists())) {
                    continue;
                }
                // ignore already deployed apps
                if (isDeployed(file, standardHost)) {
                    continue;
                }
                final AppInfo appInfo;
                try {
                    file = file.getCanonicalFile().getAbsoluteFile();
                    final AppModule appModule = deploymentLoader.load(file, null);
                    // Ignore any standalone web modules - this happens when the app is unpaked and doesn't have a WEB-INF dir
                    if (appModule.getDeploymentModule().size() == 1 && appModule.getWebModules().size() == 1) {
                        final WebModule webModule = appModule.getWebModules().iterator().next();
                        if (file.getAbsolutePath().equals(webModule.getJarLocation())) {
                            continue;
                        }
                    }
                    // tell web modules to deploy using this host
                    for (final WebModule webModule : appModule.getWebModules()) {
                        webModule.setHost(standardHost.getName());
                    }
                    appInfo = configurationFactory.configureApplication(appModule);
                    if (file.isFile() && file.getName().toLowerCase().endsWith(".ear")) {
                        // this is to prevent any WARs inside the EARs being unpacked in a directory where they'll then be deployed again
                        appInfo.properties.setProperty("tomcat.unpackWar", "false");
                    }
                    // if this is an unpacked dir, tomcat will pick it up as a webapp so undeploy it first
                    if (file.isDirectory()) {
                        final ContainerBase context = (ContainerBase) standardHost.findChild("/" + name);
                        if (context != null) {
                            try {
                                standardHost.removeChild(context);
                            } catch (final Throwable t) {
                                logger.warning("Error undeploying wep application from Tomcat  " + name, t);
                            }
                            try {
                                context.destroy();
                            } catch (final Throwable t) {
                                logger.warning("Error destroying Tomcat web context " + name, t);
                            }
                        }
                    }
                    getAssembler().createApplication(appInfo);
                    deployedApps.put(file.getAbsolutePath(), new DeployedApplication(file, appInfo));
                } catch (final Throwable e) {
                    logger.warning("Error deploying application " + file.getAbsolutePath(), e);
                }
            }
        }
    }
}
Also used : ContainerBase(org.apache.catalina.core.ContainerBase) AppModule(org.apache.openejb.config.AppModule) WebModule(org.apache.openejb.config.WebModule) LifecycleException(org.apache.catalina.LifecycleException) NameNotFoundException(javax.naming.NameNotFoundException) IOException(java.io.IOException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) AppInfo(org.apache.openejb.assembler.classic.AppInfo) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) EnvEntry(org.apache.openejb.jee.EnvEntry) JarEntry(java.util.jar.JarEntry) Map(java.util.Map) TreeMap(java.util.TreeMap) FilterMap(org.apache.tomcat.util.descriptor.web.FilterMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) File(java.io.File) JarFile(java.util.jar.JarFile)

Example 60 with AppInfo

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

the class AsynchInRoleTest method testClassScopeAsynch.

@Test
public void testClassScopeAsynch() throws Exception {
    // Build the application
    final AppModule app = new AppModule(this.getClass().getClassLoader(), "testclassasynch");
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new SingletonBean(TestBeanA.class));
    app.getEjbModules().add(new EjbModule(ejbJar));
    final AppInfo appInfo = config.configureApplication(app);
    assembler.createApplication(appInfo);
    final Properties env = new Properties();
    env.put(javax.naming.Context.SECURITY_PRINCIPAL, "jonathan");
    env.put(javax.naming.Context.SECURITY_CREDENTIALS, "secret");
    final InitialContext context = new InitialContext(env);
    final TestBean test = (TestBean) context.lookup("TestBeanALocal");
    test.testA(Thread.currentThread().getId());
    Thread.sleep(1000L);
    Assert.assertEquals("testA was never executed", "testA", test.getLastInvokeMethod());
    final Future<String> future = test.testB(Thread.currentThread().getId());
    Thread.sleep(1000L);
    Assert.assertTrue("The task should be done", future.isDone());
    Assert.assertEquals("testB was never executed", "testB", test.getLastInvokeMethod());
    test.testC(Thread.currentThread().getId());
    Assert.assertEquals("testC was never executed", "testC", test.getLastInvokeMethod());
    test.testD(Thread.currentThread().getId());
    Assert.assertEquals("testD was never executed", "testD", test.getLastInvokeMethod());
    context.close();
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) EjbJar(org.apache.openejb.jee.EjbJar) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Test(org.junit.Test)

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