Search in sources :

Example 11 with WebModule

use of org.apache.openejb.config.WebModule in project tomee by apache.

the class MaxChildTest method app.

@Module
public AppModule app() {
    final String jarLocation = "target/" + getClass().getSimpleName();
    return new AppModule(Thread.currentThread().getContextClassLoader(), jarLocation, new Application(), true) {

        {
            getEjbModules().add(new EjbModule(new EjbJar("app"), new OpenejbJar() {

                {
                    getPojoDeployment().add(new PojoDeployment() {

                        {
                            setClassName(SimpleContractImpl.class.getName());
                            getProperties().setProperty("cxf.jaxws.properties", "cxfLargeMsgSize");
                        }
                    });
                }
            }));
            getWebModules().add(new WebModule(new WebApp().contextRoot("app").addServlet("ws", SimpleContractImpl.class.getName(), "/ws"), "app", Thread.currentThread().getContextClassLoader(), jarLocation, "app"));
            getServices().add(new Service() {

                {
                    setId("cxfLargeMsgSize");
                    setClassName(Properties.class.getName());
                    getProperties().setProperty("org.apache.cxf.stax.maxChildElements", "1");
                }
            });
        }
    };
}
Also used : AppModule(org.apache.openejb.config.AppModule) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EjbModule(org.apache.openejb.config.EjbModule) Service(org.apache.openejb.config.sys.Service) WebService(javax.jws.WebService) PojoDeployment(org.apache.openejb.jee.oejb3.PojoDeployment) WebModule(org.apache.openejb.config.WebModule) Application(org.apache.openejb.jee.Application) EjbJar(org.apache.openejb.jee.EjbJar) WebApp(org.apache.openejb.jee.WebApp) WebModule(org.apache.openejb.config.WebModule) EjbModule(org.apache.openejb.config.EjbModule) AppModule(org.apache.openejb.config.AppModule) Module(org.apache.openejb.testing.Module)

Example 12 with WebModule

use of org.apache.openejb.config.WebModule in project tomee by apache.

the class TomcatWebAppBuilder method loadWebModule.

/**
     * Creates a new {@link WebModule} instance from given
     * tomcat context instance.
     *
     * @param standardContext tomcat context instance
     */
private void loadWebModule(final AppModule appModule, final StandardContext standardContext) {
    final List<WebModule> webModules = appModule.getWebModules();
    if (webModules.isEmpty()) {
        final File file = appModule.getFile();
        logger.error("Failed to find a single module in: " + file);
        return;
    }
    final WebModule webModule = webModules.get(0);
    final WebApp webApp = webModule.getWebApp();
    // create the web module
    final String path = standardContext.getPath();
    logger.debug("context path = " + path);
    webModule.setHost(Contexts.getHostname(standardContext));
    // Add all Tomcat env entries to context so they can be overriden by the env.properties file
    final NamingResourcesImpl naming = standardContext.getNamingResources();
    for (final ContextEnvironment environment : naming.findEnvironments()) {
        EnvEntry envEntry = webApp.getEnvEntryMap().get(environment.getName());
        if (envEntry == null) {
            envEntry = new EnvEntry();
            envEntry.setName(environment.getName());
            webApp.getEnvEntry().add(envEntry);
        }
        envEntry.setEnvEntryValue(environment.getValue());
        envEntry.setEnvEntryType(environment.getType());
    }
    // remove all jndi entries where there is a configured Tomcat resource or resource-link
    for (final ContextResource resource : naming.findResources()) {
        final String name = resource.getName();
        removeRef(webApp, name);
    }
    for (final ContextResourceLink resourceLink : naming.findResourceLinks()) {
        final String name = resourceLink.getName();
        removeRef(webApp, name);
    }
    // remove all env entries from the web xml that are not overridable
    for (final ContextEnvironment environment : naming.findEnvironments()) {
        if (!environment.getOverride()) {
            // overrides are not allowed
            webApp.getEnvEntryMap().remove(environment.getName());
        }
    }
}
Also used : ContextEnvironment(org.apache.tomcat.util.descriptor.web.ContextEnvironment) ContextResourceLink(org.apache.tomcat.util.descriptor.web.ContextResourceLink) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) WebModule(org.apache.openejb.config.WebModule) File(java.io.File) JarFile(java.util.jar.JarFile) WebApp(org.apache.openejb.jee.WebApp) EnvEntry(org.apache.openejb.jee.EnvEntry) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource)

Example 13 with WebModule

use of org.apache.openejb.config.WebModule in project tomee by apache.

the class AddContainerCdiBeansExtension method addCdiExtLib.

public void addCdiExtLib(@Observes final BeforeAppInfoBuilderEvent event) {
    for (final EjbModule ejbModule : event.getAppModule().getEjbModules()) {
        if (ejbModule.getModuleId().startsWith("ear-scoped-cdi-beans")) {
            final Beans beans = ejbModule.getBeans();
            if (CompositeBeans.class.isInstance(beans)) {
                final CompositeBeans cb = CompositeBeans.class.cast(beans);
                cb.getManagedClasses().put(EXT_LIB, new ArrayList<>(BEANS));
            }
            return;
        }
    }
    // else a war
    for (final WebModule webModule : event.getAppModule().getWebModules()) {
        for (final EjbModule ejbModule : event.getAppModule().getEjbModules()) {
            if (ejbModule.getModuleId().equals(webModule.getModuleId())) {
                final Beans beans = ejbModule.getBeans();
                if (CompositeBeans.class.isInstance(beans)) {
                    final CompositeBeans cb = CompositeBeans.class.cast(beans);
                    cb.getManagedClasses().put(EXT_LIB, new ArrayList<>(BEANS));
                }
                return;
            }
        }
    }
}
Also used : CompositeBeans(org.apache.openejb.cdi.CompositeBeans) Beans(org.apache.openejb.jee.Beans) CompositeBeans(org.apache.openejb.cdi.CompositeBeans) EjbModule(org.apache.openejb.config.EjbModule) WebModule(org.apache.openejb.config.WebModule)

Example 14 with WebModule

use of org.apache.openejb.config.WebModule in project tomee by apache.

the class SimplePojoTest method war.

@Module
@Classes(cdi = true, value = { MyFirstRestClass.class })
public WebModule war() {
    final WebModule webModule = new WebModule(new WebApp(), "/foo", Thread.currentThread().getContextClassLoader(), "", "foo");
    webModule.getRestClasses().add(MyFirstRestClass.class.getName());
    return webModule;
}
Also used : MyFirstRestClass(org.apache.openejb.server.cxf.rs.beans.MyFirstRestClass) WebModule(org.apache.openejb.config.WebModule) WebApp(org.apache.openejb.jee.WebApp) WebModule(org.apache.openejb.config.WebModule) Module(org.apache.openejb.testing.Module) Classes(org.apache.openejb.testing.Classes)

Example 15 with WebModule

use of org.apache.openejb.config.WebModule in project tomee by apache.

the class DeployerEjb method deploy.

@Override
public AppInfo deploy(final String inLocation, Properties properties) throws OpenEJBException {
    String rawLocation = inLocation;
    if (rawLocation == null && properties == null) {
        throw new NullPointerException("location and properties are null");
    }
    if (rawLocation == null) {
        rawLocation = properties.getProperty(FILENAME);
    }
    if (properties == null) {
        properties = new Properties();
    }
    AppModule appModule = null;
    final File file;
    if ("true".equalsIgnoreCase(properties.getProperty(OPENEJB_USE_BINARIES, "false"))) {
        file = copyBinaries(properties);
    } else {
        file = new File(realLocation(rawLocation).iterator().next());
    }
    final boolean autoDeploy = Boolean.parseBoolean(properties.getProperty(OPENEJB_APP_AUTODEPLOY, "false"));
    final String host = properties.getProperty(OPENEJB_DEPLOYER_HOST, null);
    if (WebAppDeployer.Helper.isWebApp(file) && !oldWarDeployer) {
        AUTO_DEPLOY.set(autoDeploy);
        try {
            final AppInfo appInfo = SystemInstance.get().getComponent(WebAppDeployer.class).deploy(host, contextRoot(properties, file.getAbsolutePath()), file);
            if (appInfo != null) {
                saveIfNeeded(properties, file, appInfo);
                return appInfo;
            }
            throw new OpenEJBException("can't deploy " + file.getAbsolutePath());
        } finally {
            AUTO_DEPLOY.remove();
        }
    }
    AppInfo appInfo = null;
    try {
        appModule = deploymentLoader.load(file, null);
        // Add any alternate deployment descriptors to the modules
        final Map<String, DeploymentModule> modules = new TreeMap<>();
        for (final DeploymentModule module : appModule.getEjbModules()) {
            modules.put(module.getModuleId(), module);
        }
        for (final DeploymentModule module : appModule.getClientModules()) {
            modules.put(module.getModuleId(), module);
        }
        for (final WebModule module : appModule.getWebModules()) {
            final String contextRoot = contextRoot(properties, module.getJarLocation());
            if (contextRoot != null) {
                module.setContextRoot(contextRoot);
                module.setHost(host);
            }
            modules.put(module.getModuleId(), module);
        }
        for (final DeploymentModule module : appModule.getConnectorModules()) {
            modules.put(module.getModuleId(), module);
        }
        for (final Map.Entry<Object, Object> entry : properties.entrySet()) {
            String name = (String) entry.getKey();
            if (name.startsWith(ALT_DD + "/")) {
                name = name.substring(ALT_DD.length() + 1);
                final DeploymentModule module;
                final int slash = name.indexOf('/');
                if (slash > 0) {
                    final String moduleId = name.substring(0, slash);
                    name = name.substring(slash + 1);
                    module = modules.get(moduleId);
                } else {
                    module = appModule;
                }
                if (module != null) {
                    final String value = (String) entry.getValue();
                    final File dd = new File(value);
                    if (dd.canRead()) {
                        module.getAltDDs().put(name, dd.toURI().toURL());
                    } else {
                        module.getAltDDs().put(name, value);
                    }
                }
            }
        }
        appInfo = configurationFactory.configureApplication(appModule);
        appInfo.autoDeploy = autoDeploy;
        if (properties != null && properties.containsKey(OPENEJB_DEPLOYER_FORCED_APP_ID_PROP)) {
            appInfo.appId = properties.getProperty(OPENEJB_DEPLOYER_FORCED_APP_ID_PROP);
        }
        if (!appInfo.webApps.isEmpty()) {
            appInfo.properties.setProperty("tomcat.unpackWar", "false");
        }
        assembler.createApplication(appInfo);
        saveIfNeeded(properties, file, appInfo);
        return appInfo;
    } catch (final Throwable e) {
        // destroy the class loader for the failed application
        if (appModule != null) {
            ClassLoaderUtil.destroyClassLoader(appModule.getJarLocation());
        }
        if (null != appInfo) {
            ClassLoaderUtil.destroyClassLoader(appInfo.appId, appInfo.path);
        }
        LOGGER.error("Can't deploy " + inLocation, e);
        if (e instanceof ValidationException) {
            throw (ValidationException) e;
        }
        final Throwable ex;
        final DeploymentExceptionManager dem = SystemInstance.get().getComponent(DeploymentExceptionManager.class);
        if (dem != null) {
            if (dem.hasDeploymentFailed()) {
                ex = dem.getLastException();
            } else {
                ex = e;
            }
            if (appInfo != null) {
                dem.clearLastException(appInfo);
            }
        } else {
            ex = e;
        }
        if (ex instanceof OpenEJBException) {
            if (ex.getCause() instanceof ValidationException) {
                throw (ValidationException) ex.getCause();
            }
            throw (OpenEJBException) ex;
        }
        throw new OpenEJBException(ex);
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) AppModule(org.apache.openejb.config.AppModule) ValidationException(javax.validation.ValidationException) WebModule(org.apache.openejb.config.WebModule) Properties(java.util.Properties) TreeMap(java.util.TreeMap) AppInfo(org.apache.openejb.assembler.classic.AppInfo) DeploymentModule(org.apache.openejb.config.DeploymentModule) File(java.io.File) Map(java.util.Map) TreeMap(java.util.TreeMap) DeploymentExceptionManager(org.apache.openejb.assembler.classic.DeploymentExceptionManager)

Aggregations

WebModule (org.apache.openejb.config.WebModule)18 AppModule (org.apache.openejb.config.AppModule)9 EjbModule (org.apache.openejb.config.EjbModule)9 File (java.io.File)7 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 WebApp (org.apache.openejb.jee.WebApp)5 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 EjbJar (org.apache.openejb.jee.EjbJar)4 Module (org.apache.openejb.testing.Module)4 URL (java.net.URL)3 LinkedList (java.util.LinkedList)3 OpenEJBException (org.apache.openejb.OpenEJBException)3 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)3 AppInfo (org.apache.openejb.assembler.classic.AppInfo)3 Beans (org.apache.openejb.jee.Beans)3 EnvEntry (org.apache.openejb.jee.EnvEntry)3 Arrays.asList (java.util.Arrays.asList)2