Search in sources :

Example 1 with PojoDeployment

use of org.apache.openejb.jee.oejb3.PojoDeployment in project tomee by apache.

the class ApplicationComposers method addWebApp.

private void addWebApp(final AppModule appModule, final ManagedBean testBean, final Map<String, URL> additionalDescriptors, final Descriptors descriptors, final JaxrsProviders providers, final WebApp webapp, final Jars globalJarsAnnotation, final Jars jarsAnnotation, final Class<?>[] cdiClasses, final String[] excludes, final Class<?>[] cdiInterceptors, final Class<?>[] cdiAlternatives, final Class<?>[] cdiDecorators, final Class<?>[] cdiStereotypes, final boolean cdi, final boolean innerClassesAsBean, final boolean autoConfig) throws OpenEJBException {
    String root = webapp.getContextRoot();
    if (root == null) {
        root = "/openejb";
    }
    testBean.getEnvEntry().addAll(webapp.getEnvEntry());
    final WebModule webModule = new WebModule(webapp, root, Thread.currentThread().getContextClassLoader(), "", root);
    final File thisJar;
    if (autoConfig) {
        thisJar = jarLocation(testClass);
        try {
            webModule.getAltDDs().putAll(DeploymentLoader.mapDescriptors(new ResourceFinder("", webModule.getClassLoader(), thisJar.toURI().toURL())));
            webModule.getAltDDs().putAll(DeploymentLoader.getWebDescriptors(new File(thisJar.getParentFile().getParentFile(), "src/main/webapp")));
        } catch (final IOException e) {
            throw new IllegalStateException(e);
        }
    } else {
        thisJar = null;
    }
    webModule.getAltDDs().putAll(additionalDescriptors);
    for (final Descriptors d : asList(testClass.getAnnotation(Descriptors.class), descriptors)) {
        if (d != null) {
            webModule.getAltDDs().putAll(descriptorsToMap(d));
        }
    }
    final EjbModule ejbModule = DeploymentLoader.addWebModule(webModule, appModule);
    ejbModule.getProperties().put(CdiScanner.OPENEJB_CDI_FILTER_CLASSLOADER, "false");
    if (isCdi(cdi, cdiInterceptors, cdiAlternatives, cdiStereotypes, cdiDecorators)) {
        ejbModule.setBeans(beans(new Beans(), cdiDecorators, cdiInterceptors, cdiAlternatives, cdiStereotypes));
    }
    Class<?>[] classes = cdiClasses;
    final Class<?>[] providersClasses = providers == null ? null : providers.value();
    for (final JaxrsProviders p : asList(testClass.getAnnotation(JaxrsProviders.class), providers)) {
        if (p != null) {
            if (classes == null) {
                classes = p.value();
            } else {
                final Collection<Class<?>> newClasses = new ArrayList<>(asList(classes));
                newClasses.addAll(asList(p.value()));
                classes = newClasses.toArray(new Class<?>[newClasses.size()]);
            }
        }
    }
    if (innerClassesAsBean) {
        final Collection<Class<?>> inners = new LinkedList<>();
        for (final Class<?> clazz : testClass.getClasses()) {
            final int modifiers = clazz.getModifiers();
            try {
                if (Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && clazz.getConstructor() != null) {
                    inners.add(clazz);
                }
            } catch (final NoSuchMethodException nsme) {
            // no-op, skip it
            }
        }
        if (!inners.isEmpty()) {
            final Collection<Class<?>> newClasses = new ArrayList<>(asList(classes));
            newClasses.addAll(inners);
            classes = newClasses.toArray(new Class<?>[newClasses.size()]);
        }
    }
    Collection<File> libs = null;
    for (final Jars jars : asList(jarsAnnotation, globalJarsAnnotation)) {
        final Collection<File> files = findFiles(jars);
        if (files != null) {
            if (libs == null) {
                libs = new LinkedList<>();
            }
            libs.addAll(files);
        }
    }
    if (autoConfig) {
        if (libs == null) {
            libs = new LinkedList<>();
        }
        libs.add(thisJar);
        if ("test-classes".equals(thisJar.getName()) && "target".equals(thisJar.getParentFile().getName())) {
            // mvn
            final File mainClasses = new File(thisJar.getParentFile(), "classes");
            if (mainClasses.exists()) {
                libs.add(mainClasses);
            }
        } else if ("test".equals(thisJar.getName()) && "classes".equals(thisJar.getParentFile().getName())) {
            // gradle
            final File mainClasses = new File(thisJar.getParentFile(), "main");
            if (mainClasses.exists()) {
                libs.add(mainClasses);
            }
        }
    }
    final IAnnotationFinder finder = finderFromClasses(webModule, classes, libs, excludes);
    webModule.setFinder(finder);
    ejbModule.setFinder(webModule.getFinder());
    if (providersClasses != null) {
        OpenejbJar openejbJar = ejbModule.getOpenejbJar();
        if (openejbJar == null) {
            openejbJar = new OpenejbJar();
            ejbModule.setOpenejbJar(openejbJar);
        }
        final PojoDeployment pojoDeployment = new PojoDeployment();
        pojoDeployment.setClassName(providers.applicationName());
        pojoDeployment.getProperties().setProperty("cxf.jaxrs.providers", Join.join(",", providersClasses).replace("class ", ""));
        // it is specified so skip scanning otherwise we'll get them twice
        pojoDeployment.getProperties().setProperty("cxf.jaxrs.skip-provider-scanning", "true");
        openejbJar.getPojoDeployment().add(pojoDeployment);
    }
}
Also used : ResourceFinder(org.apache.xbean.finder.ResourceFinder) RESTResourceFinder(org.apache.openejb.rest.RESTResourceFinder) IAnnotationFinder(org.apache.xbean.finder.IAnnotationFinder) EjbModule(org.apache.openejb.config.EjbModule) ArrayList(java.util.ArrayList) PojoDeployment(org.apache.openejb.jee.oejb3.PojoDeployment) WebModule(org.apache.openejb.config.WebModule) IOException(java.io.IOException) LinkedList(java.util.LinkedList) Beans(org.apache.openejb.jee.Beans) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) File(java.io.File)

Example 2 with PojoDeployment

use of org.apache.openejb.jee.oejb3.PojoDeployment in project tomee by apache.

the class AppInfoBuilder method build.

public AppInfo build(final AppModule appModule) throws OpenEJBException {
    // send an event so that it becomes pretty easy at this step to dynamically change the module description
    // before going into the info tree. Pretty easy to hack on portability issues.
    SystemInstance.get().fireEvent(new BeforeAppInfoBuilderEvent(appModule));
    final AppInfo appInfo = new AppInfo();
    appInfo.appId = appModule.getModuleId();
    appInfo.path = appModule.getJarLocation();
    appInfo.standaloneModule = appModule.isStandaloneModule() || appModule.isWebapp();
    appInfo.delegateFirst = appModule.isDelegateFirst();
    appInfo.watchedResources.addAll(appModule.getWatchedResources());
    appInfo.mbeans.addAll(appModule.getAdditionalLibMbeans());
    appInfo.jaxRsProviders.addAll(appModule.getJaxRsProviders());
    appInfo.properties.putAll(appModule.getProperties());
    if (appInfo.appId == null) {
        throw new IllegalArgumentException("AppInfo.appId cannot be null");
    }
    if (appInfo.path == null) {
        appInfo.path = appInfo.appId;
    }
    this.buildPojoConfiguration(appModule, appInfo);
    this.buildAppResources(appModule, appInfo);
    this.buildAppServices(appModule, appInfo);
    //
    //  J2EE Connectors
    //
    this.buildConnectorModules(appModule, appInfo);
    //
    //  Persistence Units
    //
    this.buildPersistenceModules(appModule, appInfo);
    final List<String> containerIds = this.configFactory.getContainerIds();
    for (final ConnectorInfo connectorInfo : appInfo.connectors) {
        for (final MdbContainerInfo containerInfo : connectorInfo.inbound) {
            containerIds.add(containerInfo.id);
        }
    }
    containerIds.addAll(appInfo.containerIds);
    //
    //  EJB Jars
    //
    final Map<EjbModule, EjbJarInfo> ejbJarInfos = new HashMap<EjbModule, EjbJarInfo>();
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        try {
            final EjbJarInfo ejbJarInfo = this.ejbJarInfoBuilder.buildInfo(ejbModule);
            ejbJarInfo.mbeans = ejbModule.getMbeans();
            final Map<String, EjbDeployment> deploymentsByEjbName = ejbModule.getOpenejbJar().getDeploymentsByEjbName();
            for (final EnterpriseBeanInfo bean : ejbJarInfo.enterpriseBeans) {
                final EjbDeployment d = deploymentsByEjbName.get(bean.ejbName);
                if (d.getContainerId() != null && !containerIds.contains(d.getContainerId())) {
                    for (final String cId : appInfo.containerIds) {
                        if (cId.endsWith("/" + d.getContainerId())) {
                            d.setContainerId(cId);
                            break;
                        }
                    }
                }
                /*
                     * JRG - there's probably a better way of handling this, but this code handles the case when:
                     * 
                     * A connector with two or more inbound adapter is registered, causing two containers named with the format:
                     *     <moduleId>-<message listener interface>
                     * 
                     * This code adjusts the container id for the associated MDBs by sticking the message listener interface on the end.
                     * 
                     */
                if (bean instanceof MessageDrivenBeanInfo && !containerIds.contains(d.getContainerId()) && !skipMdb(bean)) {
                    final MessageDrivenBeanInfo mdb = (MessageDrivenBeanInfo) bean;
                    final String newContainerId = d.getContainerId() + "-" + mdb.mdbInterface;
                    if (containerIds.contains(newContainerId)) {
                        d.setContainerId(newContainerId);
                    }
                }
                if (!containerIds.contains(d.getContainerId()) && !skipMdb(bean)) {
                    final String msg = new Messages("org.apache.openejb.util.resources").format("config.noContainerFound", d.getContainerId(), d.getEjbName());
                    logger.fatal(msg);
                    throw new OpenEJBException(msg);
                }
                bean.containerId = d.getContainerId();
            }
            for (final PojoDeployment pojoDeployment : ejbModule.getOpenejbJar().getPojoDeployment()) {
                final IdPropertiesInfo info = new IdPropertiesInfo();
                info.id = pojoDeployment.getClassName();
                info.properties.putAll(pojoDeployment.getProperties());
                ejbJarInfo.pojoConfigurations.add(info);
            }
            ejbJarInfo.validationInfo = ValidatorBuilder.getInfo(ejbModule.getValidationConfig());
            ejbJarInfo.portInfos.addAll(this.configureWebservices(ejbModule.getWebservices()));
            ejbJarInfo.uniqueId = ejbModule.getUniqueId();
            ejbJarInfo.webapp = ejbModule.isWebapp();
            this.configureWebserviceSecurity(ejbJarInfo, ejbModule);
            ejbJarInfos.put(ejbModule, ejbJarInfo);
            appInfo.ejbJars.add(ejbJarInfo);
        } catch (final OpenEJBException e) {
            ConfigUtils.logger.warning("conf.0004", ejbModule.getJarLocation(), e.getMessage());
            throw e;
        }
    }
    // Create the JNDI info builder
    final JndiEncInfoBuilder jndiEncInfoBuilder = new JndiEncInfoBuilder(appInfo);
    if (appModule.getApplication() != null) {
        //TODO figure out how to prevent adding stuff to the module and comp contexts from the application
        //or maybe validate the xml so this won't happen.
        jndiEncInfoBuilder.build(appModule.getApplication(), appInfo.appId, null, appModule.getModuleUri(), new JndiEncInfo(), new JndiEncInfo());
    }
    final List<EnterpriseBeanInfo> beans = new ArrayList<EnterpriseBeanInfo>();
    // Build the JNDI tree for each ejb
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        final EjbJarInfo ejbJar = ejbJarInfos.get(ejbModule);
        final Map<String, EnterpriseBean> beanData = ejbModule.getEjbJar().getEnterpriseBeansByEjbName();
        for (final EnterpriseBeanInfo beanInfo : ejbJar.enterpriseBeans) {
            beans.add(beanInfo);
            // Get the ejb-jar.xml object
            final EnterpriseBean enterpriseBean = beanData.get(beanInfo.ejbName);
            // Build the JNDI info tree for the EJB
            jndiEncInfoBuilder.build(enterpriseBean, beanInfo.ejbName, ejbJar.moduleName, ejbModule.getModuleUri(), ejbJar.moduleJndiEnc, beanInfo.jndiEnc);
            jndiEncInfoBuilder.buildDependsOnRefs(enterpriseBean, beanInfo, ejbJar.moduleName);
        }
    }
    // Check for circular references in Singleton @DependsOn
    try {
        References.sort(beans, new References.Visitor<EnterpriseBeanInfo>() {

            @Override
            public String getName(final EnterpriseBeanInfo bean) {
                return bean.ejbDeploymentId;
            }

            @Override
            public Set<String> getReferences(final EnterpriseBeanInfo bean) {
                return new LinkedHashSet<String>(bean.dependsOn);
            }
        });
    } catch (final CircularReferencesException e) {
    // List<List> circuits = e.getCircuits();
    // TODO Seems we lost circular reference detection, or we do it elsewhere and don't need it here
    }
    //
    //  Application Clients
    //
    this.buildClientModules(appModule, appInfo, jndiEncInfoBuilder);
    //
    //  Webapps
    //
    this.buildWebModules(appModule, jndiEncInfoBuilder, appInfo);
    //
    //  Final AppInfo creation
    //
    final List<URL> additionalLibraries = appModule.getAdditionalLibraries();
    for (final URL url : additionalLibraries) {
        final File file = toFile(url);
        try {
            appInfo.libs.add(file.getCanonicalPath());
        } catch (final IOException e) {
            throw new OpenEJBException("Invalid application lib path " + file.getAbsolutePath());
        }
    }
    if (appModule.getCmpMappings() != null) {
        try {
            appInfo.cmpMappingsXml = JpaJaxbUtil.marshal(EntityMappings.class, appModule.getCmpMappings());
        } catch (final JAXBException e) {
            throw new OpenEJBException("Unable to marshal cmp entity mappings", e);
        }
    }
    final ReportValidationResults reportValidationResults = new ReportValidationResults();
    reportValidationResults.deploy(appModule);
    logger.info("config.appLoaded", appInfo.path);
    appInfo.webAppAlone = appModule.isWebapp();
    return appInfo;
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PojoDeployment(org.apache.openejb.jee.oejb3.PojoDeployment) BeforeAppInfoBuilderEvent(org.apache.openejb.config.event.BeforeAppInfoBuilderEvent) URL(java.net.URL) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) MdbContainerInfo(org.apache.openejb.assembler.classic.MdbContainerInfo) MessageDrivenBeanInfo(org.apache.openejb.assembler.classic.MessageDrivenBeanInfo) IdPropertiesInfo(org.apache.openejb.assembler.classic.IdPropertiesInfo) Messages(org.apache.openejb.util.Messages) ConnectorInfo(org.apache.openejb.assembler.classic.ConnectorInfo) JndiEncInfo(org.apache.openejb.assembler.classic.JndiEncInfo) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo) References(org.apache.openejb.util.References) CircularReferencesException(org.apache.openejb.util.CircularReferencesException) EntityMappings(org.apache.openejb.jee.jpa.EntityMappings) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) URLs.toFile(org.apache.openejb.util.URLs.toFile) File(java.io.File)

Example 3 with PojoDeployment

use of org.apache.openejb.jee.oejb3.PojoDeployment in project tomee by apache.

the class TomEEConfigurableJohnzonTest method service.

@Module
public static EjbModule service() throws Exception {
    final EjbModule module = new EjbModule(new EjbJar(), new OpenejbJar());
    final EnterpriseBean bean = new SingletonBean(Endpoint.class).localBean();
    module.getEjbJar().addEnterpriseBean(bean);
    final Resources resources = new Resources();
    final Service sorter = new Service("testSorter", null);
    sorter.setClassName(Sorter.class.getName());
    resources.getService().add(sorter);
    final Service converter = new Service("customerConverter", null);
    converter.setClassName(MyConverter.class.getName());
    resources.getService().add(converter);
    final Service johnzon = new Service("johnzon", null);
    johnzon.setClassName(TomEEConfigurableJohnzon.class.getName());
    johnzon.getProperties().put("datePattern", "yyyy");
    // johnzon.getProperties().put("converter", "$customerConverter"); // or the collection syntax
    johnzon.getProperties().put("converters", "collection:$customerConverter,$customerConverter");
    johnzon.getProperties().put("attributeOrder", "$testSorter");
    resources.getService().add(johnzon);
    module.initResources(resources);
    final PojoDeployment e = new PojoDeployment();
    e.setClassName("jaxrs-application");
    e.getProperties().setProperty("cxf.jaxrs.providers", "johnzon");
    module.getOpenejbJar().getPojoDeployment().add(e);
    return module;
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) EjbModule(org.apache.openejb.config.EjbModule) Service(org.apache.openejb.config.sys.Service) PojoDeployment(org.apache.openejb.jee.oejb3.PojoDeployment) Resources(org.apache.openejb.config.sys.Resources) EjbJar(org.apache.openejb.jee.EjbJar) EjbModule(org.apache.openejb.config.EjbModule) Module(org.apache.openejb.testing.Module)

Example 4 with PojoDeployment

use of org.apache.openejb.jee.oejb3.PojoDeployment in project tomee by apache.

the class LoggingJAXRSCommons method getEjbModule.

protected EjbModule getEjbModule(String pojoDeploymentClassName, String ejbModuleId) throws Exception {
    final EjbModule module = new EjbModule(new EjbJar(), new OpenejbJar());
    if (ejbModuleId != null) {
        module.setModuleId(ejbModuleId);
    }
    final EnterpriseBean bean = new SingletonBean(LogginTestBean.class).localBean();
    module.getEjbJar().addEnterpriseBean(bean);
    final Resources resources = new Resources();
    final Service feature = new Service("xml", null);
    feature.setClassName(JAXBElementProvider.class.getName());
    feature.getProperties().put("eventHandler", "$handler");
    resources.getService().add(feature);
    module.initResources(resources);
    if (pojoDeploymentClassName != null) {
        final PojoDeployment e = new PojoDeployment();
        e.setClassName(pojoDeploymentClassName);
        e.getProperties().setProperty("cxf.jaxrs.providers", "xml");
        module.getOpenejbJar().getPojoDeployment().add(e);
    }
    return module;
}
Also used : JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) SingletonBean(org.apache.openejb.jee.SingletonBean) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) EjbModule(org.apache.openejb.config.EjbModule) Service(org.apache.openejb.config.sys.Service) RESTService(org.apache.openejb.server.rest.RESTService) PojoDeployment(org.apache.openejb.jee.oejb3.PojoDeployment) Resources(org.apache.openejb.config.sys.Resources) EjbJar(org.apache.openejb.jee.EjbJar)

Example 5 with PojoDeployment

use of org.apache.openejb.jee.oejb3.PojoDeployment 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)

Aggregations

PojoDeployment (org.apache.openejb.jee.oejb3.PojoDeployment)8 EjbModule (org.apache.openejb.config.EjbModule)7 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)7 EjbJar (org.apache.openejb.jee.EjbJar)6 Service (org.apache.openejb.config.sys.Service)5 Module (org.apache.openejb.testing.Module)5 Resources (org.apache.openejb.config.sys.Resources)4 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)4 SingletonBean (org.apache.openejb.jee.SingletonBean)4 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 JAXBElementProvider (org.apache.cxf.jaxrs.provider.JAXBElementProvider)2 WebModule (org.apache.openejb.config.WebModule)2 URL (java.net.URL)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1