Search in sources :

Example 41 with AppInfo

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

the class AutoConfigPersistenceUnitsTest method testFromWebAppContextNonJta.

/**
     * Existing data source "orange-web", non-jta managed
     * <p/>
     * Application contains a web module with root context path as "orange-web"
     * <p/>
     * Persistence xml like so:
     * <p/>
     * <persistence-unit name="orange-unit" />
     * <p/>
     * The orange-unit app should automatically use orange-web data source and create a new non-JtaManaged datasource
     *
     * @throws Exception
     */
public void testFromWebAppContextNonJta() throws Exception {
    final ResourceInfo supplied = addDataSource("orange-web", OrangeDriver.class, "jdbc:orange-web:some:stuff", false);
    assertSame(supplied, resources.get(0));
    final PersistenceUnit persistenceUnit = new PersistenceUnit("orange-unit");
    final ClassLoader cl = this.getClass().getClassLoader();
    final AppModule app = new AppModule(cl, "orange-app");
    app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
    final WebApp webApp = new WebApp();
    webApp.setMetadataComplete(true);
    app.getWebModules().add(new WebModule(webApp, "orange-web", cl, "war", "orange-web"));
    // Create app
    final AppInfo appInfo = config.configureApplication(app);
    assembler.createApplication(appInfo);
    // Check results
    final ResourceInfo generated = resources.get(1);
    assertEquals(supplied.id + "Jta", generated.id);
    assertEquals(supplied.service, generated.service);
    assertEquals(supplied.className, generated.className);
    assertEquals(supplied.properties.get("JdbcDriver"), generated.properties.get("JdbcDriver"));
    assertEquals(supplied.properties.get("JdbcUrl"), generated.properties.get("JdbcUrl"));
    assertEquals("true", generated.properties.get("JtaManaged"));
}
Also used : Persistence(org.apache.openejb.jee.jpa.unit.Persistence) ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) WebApp(org.apache.openejb.jee.WebApp) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 42 with AppInfo

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

the class ClusterObserver method deploy.

public void deploy(@Observes final AfterEvent<AssemblerAfterApplicationCreated> app) {
    if (!ClUSTER_DEPLOYMENT) {
        return;
    }
    final AppInfo appInfo = app.getEvent().getApp();
    send(new DeployMessage(appInfo.path), appInfo);
}
Also used : AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 43 with AppInfo

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

the class OpenEJBContextConfig method addAddedJAXWsServices.

private void addAddedJAXWsServices() {
    final WebAppInfo webAppInfo = info.get();
    final AppInfo appInfo = info.app();
    if (webAppInfo == null || appInfo == null || "false".equalsIgnoreCase(appInfo.properties.getProperty("openejb.jaxws.add-missing-servlets", "true"))) {
        return;
    }
    try {
        // if no jaxws classes are here don't try anything
        OpenEJBContextConfig.class.getClassLoader().loadClass("org.apache.openejb.server.webservices.WsServlet");
    } catch (final ClassNotFoundException | NoClassDefFoundError e) {
        return;
    }
    for (final ServletInfo servlet : webAppInfo.servlets) {
        if (!servlet.mappings.iterator().hasNext()) {
            // no need to do anything
            continue;
        }
        for (final ParamValueInfo pv : servlet.initParams) {
            if ("openejb-internal".equals(pv.name) && "true".equals(pv.value)) {
                if (context.findChild(servlet.servletName) == null) {
                    final Wrapper wrapper = context.createWrapper();
                    wrapper.setName(servlet.servletName);
                    wrapper.setServletClass("org.apache.openejb.server.webservices.WsServlet");
                    // add servlet to context
                    context.addChild(wrapper);
                    context.addServletMappingDecoded(servlet.mappings.iterator().next(), wrapper.getName());
                }
                break;
            }
        }
    }
}
Also used : ServletInfo(org.apache.openejb.assembler.classic.ServletInfo) Wrapper(org.apache.catalina.Wrapper) StandardWrapper(org.apache.catalina.core.StandardWrapper) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) ParamValueInfo(org.apache.openejb.assembler.classic.ParamValueInfo) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 44 with AppInfo

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

the class ClusterObserver method undeploy.

public void undeploy(@Observes final AssemblerBeforeApplicationDestroyed app) {
    if (!ClUSTER_DEPLOYMENT) {
        return;
    }
    final AppInfo appInfo = app.getApp();
    send(new UndeployMessage(appInfo.path), appInfo);
}
Also used : AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 45 with AppInfo

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

the class TomcatWebappDeployer method deploy.

@Override
public AppInfo deploy(final String host, final String context, final File file) {
    final TomcatWebAppBuilder tomcatWebAppBuilder = (TomcatWebAppBuilder) SystemInstance.get().getComponent(WebAppBuilder.class);
    final Collection<String> alreadyDeployed = tomcatWebAppBuilder.availableApps();
    final AppInfo appInfo = fakeInfo(file, host, context);
    appInfo.properties.setProperty("tomcat.unpackWar", "false");
    try {
        // classloader == null -> standalone war
        tomcatWebAppBuilder.deployWebApps(appInfo, null);
    } catch (final Exception e) {
        // tomcat lost the real exception (only in lifecycle exception string) so try to find it back
        final DeploymentExceptionManager dem = SystemInstance.get().getComponent(DeploymentExceptionManager.class);
        if (dem != null && dem.hasDeploymentFailed()) {
            Throwable lastException = dem.getLastException();
            // TODO: fix it, since we dont use this appInfo clean is ignored. Not a big deal while dem stores few exceptions only.
            dem.clearLastException(appInfo);
            if (TomEERuntimeException.class.isInstance(lastException)) {
                lastException = TomEERuntimeException.class.cast(lastException).getCause();
            }
            throw new OpenEJBRuntimeException(Exception.class.cast(lastException));
        }
        throw new OpenEJBRuntimeException(e);
    }
    TomcatWebAppBuilder.ContextInfo info = contextInfo(file);
    if (info == null) {
        // try another time doing a diff with apps before deployment and apps after
        final Collection<String> deployedNow = tomcatWebAppBuilder.availableApps();
        final Iterator<String> it = deployedNow.iterator();
        while (it.hasNext()) {
            if (alreadyDeployed.contains(it.next())) {
                it.remove();
            }
        }
        if (deployedNow.size() == 1) {
            info = contextInfo(new File(deployedNow.iterator().next()));
        }
    }
    if (info == null || info.appInfo == null) {
        LOGGER.error("Can't find of appInfo for " + (file != null ? file.getAbsolutePath() : null) + ", availables: " + tomcatWebAppBuilder.availableApps());
    }
    if (info == null) {
        // error
        return null;
    }
    return info.appInfo;
}
Also used : TomcatWebAppBuilder(org.apache.tomee.catalina.TomcatWebAppBuilder) TomcatWebAppBuilder(org.apache.tomee.catalina.TomcatWebAppBuilder) WebAppBuilder(org.apache.openejb.assembler.classic.WebAppBuilder) TomEERuntimeException(org.apache.tomee.catalina.TomEERuntimeException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) TomEERuntimeException(org.apache.tomee.catalina.TomEERuntimeException) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) File(java.io.File) DeploymentExceptionManager(org.apache.openejb.assembler.classic.DeploymentExceptionManager)

Aggregations

AppInfo (org.apache.openejb.assembler.classic.AppInfo)106 File (java.io.File)50 Assembler (org.apache.openejb.assembler.classic.Assembler)46 Test (org.junit.Test)31 HashMap (java.util.HashMap)29 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)25 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)16 OpenEJBException (org.apache.openejb.OpenEJBException)15 AppModule (org.apache.openejb.config.AppModule)14 Map (java.util.Map)13 EjbJar (org.apache.openejb.jee.EjbJar)13 ContainerSystem (org.apache.openejb.spi.ContainerSystem)13 Properties (java.util.Properties)10 EjbModule (org.apache.openejb.config.EjbModule)10 Persistence (org.apache.openejb.jee.jpa.unit.Persistence)10 ArrayList (java.util.ArrayList)9 PersistenceUnit (org.apache.openejb.jee.jpa.unit.PersistenceUnit)9 IOException (java.io.IOException)8 URL (java.net.URL)8 InitialContext (javax.naming.InitialContext)8