Search in sources :

Example 1 with IdPropertiesInfo

use of org.apache.openejb.assembler.classic.IdPropertiesInfo 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.buildAppContainers(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);
        }
    }
    for (final ContainerInfo containerInfo : appInfo.containers) {
        containerIds.add(containerInfo.id);
    }
    // 
    // EJB Jars
    // 
    final Map<EjbModule, EjbJarInfo> ejbJarInfos = new HashMap<>();
    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 ContainerInfo containerInfo : appInfo.containers) {
                        if (containerInfo.id.endsWith("/" + d.getContainerId())) {
                            d.setContainerId(containerInfo.id);
                            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<>();
    // 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<>(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) ContainerInfo(org.apache.openejb.assembler.classic.ContainerInfo) MdbContainerInfo(org.apache.openejb.assembler.classic.MdbContainerInfo) 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 2 with IdPropertiesInfo

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

the class WsService method afterApplicationCreated.

public void afterApplicationCreated(final AppInfo appInfo, final WebAppInfo webApp) {
    final WebContext webContext = containerSystem.getWebContextByHost(webApp.moduleId, webApp.host != null ? webApp.host : virtualHost);
    if (webContext == null)
        return;
    // if already deployed skip this webapp
    if (!deployedWebApps.add(webApp))
        return;
    final Map<String, PortInfo> ports = new TreeMap<>();
    for (final PortInfo port : webApp.portInfos) {
        ports.put(port.serviceLink, port);
    }
    URL moduleBaseUrl = null;
    try {
        moduleBaseUrl = new File(webApp.path).toURI().toURL();
    } catch (final MalformedURLException e) {
        LOGGER.error("Invalid ejb jar location " + webApp.path, e);
    }
    // lazy init
    Collection<IdPropertiesInfo> pojoConfiguration = null;
    for (final ServletInfo servlet : webApp.servlets) {
        if (servlet.servletName == null) {
            continue;
        }
        final PortInfo portInfo = ports.get(servlet.servletName);
        if (portInfo == null) {
            continue;
        }
        final ClassLoader old = Thread.currentThread().getContextClassLoader();
        final ClassLoader classLoader = webContext.getClassLoader();
        Thread.currentThread().setContextClassLoader(classLoader);
        try {
            final Collection<Injection> injections = webContext.getInjections();
            final Context context = webContext.getJndiEnc();
            final Class target = classLoader.loadClass(servlet.servletClass);
            final Map<String, Object> bindings = webContext.getBindings();
            final PortData port = WsBuilder.toPortData(portInfo, injections, moduleBaseUrl, classLoader);
            pojoConfiguration = PojoUtil.findPojoConfig(pojoConfiguration, appInfo, webApp);
            final HttpListener container = createPojoWsContainer(classLoader, moduleBaseUrl, port, portInfo.serviceLink, target, context, webApp.contextRoot, bindings, new ServiceConfiguration(PojoUtil.findConfiguration(pojoConfiguration, target.getName()), appInfo.services));
            if (wsRegistry != null) {
                String auth = authMethod;
                String realm = realmName;
                String transport = transportGuarantee;
                if ("BASIC".equals(portInfo.authMethod) || "DIGEST".equals(portInfo.authMethod) || "CLIENT-CERT".equals(portInfo.authMethod)) {
                    auth = portInfo.authMethod;
                    realm = portInfo.realmName;
                    transport = portInfo.transportGuarantee;
                }
                // give servlet a reference to the webservice container
                final List<String> addresses = wsRegistry.setWsContainer(container, classLoader, webApp.contextRoot, host(webApp), servlet, realm, transport, auth, webApp.moduleId);
                // one of the registered addresses to be the connonical address
                final String address = HttpUtil.selectSingleAddress(addresses);
                if (address != null) {
                    // add address to global registry
                    portAddressRegistry.addPort(portInfo.serviceId, portInfo.wsdlService, portInfo.portId, portInfo.wsdlPort, portInfo.seiInterfaceName, address);
                    setWsdl(container, address);
                    LOGGER.info("Webservice(wsdl=" + address + ", qname=" + port.getWsdlService() + ") --> Pojo(id=" + portInfo.portId + ")");
                    /*
                        In POJO webservices it is very common to have the same JAW-WS endpoint published under different URLs
                        using url-pattern for the servlet. We only deploy one instance of the WsServlet and keep the same
                        set of url-pattern the user defined. At the moment we can't add additional ports, with different
                        addresses. So at least we should list other URLs so the user knows they are successfully deployed
                        and is aware of the different URLs
                         */
                    for (String urlAddress : addresses) {
                        if (address.equals(urlAddress)) {
                            continue;
                        }
                        LOGGER.info("Webservice(wsdl=" + urlAddress + ", qname=" + port.getWsdlService() + ") --> Pojo(id=" + portInfo.portId + ")");
                    }
                    servletAddresses.put(webApp.moduleId + "." + servlet.servletName, address);
                    addressesForApp(webApp.moduleId).add(new EndpointInfo(address, port.getWsdlService(), target.getName()));
                }
            }
        } catch (final Throwable e) {
            LOGGER.error("Error deploying CXF webservice for servlet " + portInfo.serviceLink, e);
        } finally {
            Thread.currentThread().setContextClassLoader(old);
        }
    }
}
Also used : WebContext(org.apache.openejb.core.WebContext) AppContext(org.apache.openejb.AppContext) BeanContext(org.apache.openejb.BeanContext) Context(javax.naming.Context) MalformedURLException(java.net.MalformedURLException) WebContext(org.apache.openejb.core.WebContext) Injection(org.apache.openejb.Injection) TreeMap(java.util.TreeMap) URL(java.net.URL) PortInfo(org.apache.openejb.assembler.classic.PortInfo) ServletInfo(org.apache.openejb.assembler.classic.ServletInfo) ServiceConfiguration(org.apache.openejb.assembler.classic.util.ServiceConfiguration) PortData(org.apache.openejb.core.webservices.PortData) IdPropertiesInfo(org.apache.openejb.assembler.classic.IdPropertiesInfo) HttpListener(org.apache.openejb.server.httpd.HttpListener) File(java.io.File)

Example 3 with IdPropertiesInfo

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

the class RESTService method fullServletDeployment.

private void fullServletDeployment(final AppInfo appInfo, final WebAppInfo webApp, final WebContext webContext, final Map<String, EJBRestServiceInfo> restEjbs, final ClassLoader classLoader, final Collection<Injection> injections, final WebBeansContext owbCtx, final Context context, final Collection<Object> additionalProviders, final Collection<IdPropertiesInfo> initPojoConfigurations) {
    // The spec says:
    // 
    // "The resources and providers that make up a JAX-RS application are configured via an application-supplied
    // subclass of Application. An implementation MAY provide alternate mechanisms for locating resource
    // classes and providers (e.g. runtime class scanning) but use of Application is the only portable means of
    // configuration."
    // 
    // The choice here is to deploy using the Application if it exists or to use the scanned classes
    // if there is no Application.
    // 
    // Like this providing an Application subclass user can totally control deployed services.
    Collection<IdPropertiesInfo> pojoConfigurations = null;
    boolean useApp = false;
    String appPrefix = webApp.contextRoot;
    for (final String app : webApp.restApplications) {
        // if multiple application classes reinit it
        appPrefix = webApp.contextRoot;
        if (!appPrefix.endsWith("/")) {
            appPrefix += "/";
        }
        final Application appInstance;
        final Class<?> appClazz;
        try {
            appClazz = classLoader.loadClass(app);
            appInstance = Application.class.cast(appClazz.newInstance());
            if (owbCtx.getBeanManagerImpl().isInUse()) {
                try {
                    webContext.inject(appInstance);
                } catch (final Exception e) {
                // not important since not required by the spec
                }
            }
        } catch (final Exception e) {
            throw new OpenEJBRestRuntimeException("can't create class " + app, e);
        }
        final String path = appPrefix(webApp, appClazz);
        if (path != null) {
            appPrefix += path;
        }
        final Set<Class<?>> classes = appInstance.getClasses();
        final Set<Object> singletons = appInstance.getSingletons();
        // look for providers
        for (final Class<?> clazz : classes) {
            if (isProvider(clazz)) {
                additionalProviders.add(clazz);
            }
        }
        for (final Object obj : singletons) {
            if (obj != null && isProvider(obj.getClass())) {
                additionalProviders.add(obj);
            }
        }
        for (final Object o : singletons) {
            if (o == null || additionalProviders.contains(o)) {
                continue;
            }
            if (hasEjbAndIsNotAManagedBean(restEjbs, o.getClass().getName())) {
                // no more a singleton if the ejb is not a singleton...but it is a weird case
                deployEJB(appInfo.appId, webApp.contextRoot, appPrefix, restEjbs.get(o.getClass().getName()).context, additionalProviders, appInfo.services);
            } else {
                pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
                deploySingleton(appInfo.appId, webApp.contextRoot, appPrefix, o, appInstance, classLoader, additionalProviders, new ServiceConfiguration(PojoUtil.findConfiguration(pojoConfigurations, o.getClass().getName()), appInfo.services));
            }
        }
        for (final Class<?> clazz : classes) {
            if (additionalProviders.contains(clazz)) {
                continue;
            }
            if (hasEjbAndIsNotAManagedBean(restEjbs, clazz.getName())) {
                deployEJB(appInfo.appId, webApp.contextRoot, appPrefix, restEjbs.get(clazz.getName()).context, additionalProviders, appInfo.services);
            } else {
                pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
                deployPojo(appInfo.appId, webApp.contextRoot, appPrefix, clazz, appInstance, classLoader, injections, context, owbCtx, additionalProviders, new ServiceConfiguration(PojoUtil.findConfiguration(pojoConfigurations, clazz.getName()), appInfo.services));
            }
        }
        useApp = useApp || classes.size() + singletons.size() > 0;
        LOGGER.info("REST application deployed: " + app);
    }
    if (!useApp) {
        if (webApp.restApplications.isEmpty() || webApp.restApplications.size() > 1) {
            appPrefix = webApp.contextRoot;
        }
        // else keep application prefix
        final Set<String> restClasses = new HashSet<>(webApp.restClass);
        restClasses.addAll(webApp.ejbRestServices);
        for (final String clazz : restClasses) {
            if (restEjbs.containsKey(clazz)) {
                final BeanContext ctx = restEjbs.get(clazz).context;
                if (hasEjbAndIsNotAManagedBean(restEjbs, clazz)) {
                    deployEJB(appInfo.appId, webApp.contextRoot, appPrefix, restEjbs.get(clazz).context, additionalProviders, appInfo.services);
                } else {
                    deployPojo(appInfo.appId, webApp.contextRoot, appPrefix, ctx.getBeanClass(), null, ctx.getClassLoader(), ctx.getInjections(), context, owbCtx, additionalProviders, new ServiceConfiguration(ctx.getProperties(), appInfo.services));
                }
            } else {
                try {
                    final Class<?> loadedClazz = classLoader.loadClass(clazz);
                    pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
                    deployPojo(appInfo.appId, webApp.contextRoot, appPrefix, loadedClazz, null, classLoader, injections, context, owbCtx, additionalProviders, new ServiceConfiguration(PojoUtil.findConfiguration(pojoConfigurations, loadedClazz.getName()), appInfo.services));
                } catch (final ClassNotFoundException e) {
                    throw new OpenEJBRestRuntimeException("can't find class " + clazz, e);
                }
            }
        }
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) UncheckedIOException(java.io.UncheckedIOException) ServiceException(org.apache.openejb.server.ServiceException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) BeanContext(org.apache.openejb.BeanContext) ServiceConfiguration(org.apache.openejb.assembler.classic.util.ServiceConfiguration) IdPropertiesInfo(org.apache.openejb.assembler.classic.IdPropertiesInfo) MetaAnnotatedClass(org.apache.xbean.finder.MetaAnnotatedClass) Application(javax.ws.rs.core.Application) HashSet(java.util.HashSet)

Example 4 with IdPropertiesInfo

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

the class RESTService method afterApplicationCreated.

/**
 * Deployment of JAX-RS services starts in response to a AfterApplicationCreated event
 * after normal deployment is done
 * @param appInfo the ear (real or auto-created) in which the webapp is contained
 * @param webApp the webapp containing EJB or Pojo rest services to deploy
 */
public void afterApplicationCreated(final AppInfo appInfo, final WebAppInfo webApp) {
    if ("false".equalsIgnoreCase(appInfo.properties.getProperty("openejb.jaxrs.on", "true"))) {
        return;
    }
    final WebContext webContext = containerSystem.getWebContextByHost(webApp.moduleId, webApp.host != null ? webApp.host : virtualHost);
    if (webContext == null) {
        return;
    }
    if (!deployedWebApps.add(webApp)) {
        return;
    }
    final Map<String, EJBRestServiceInfo> restEjbs = getRestEjbs(appInfo, webApp.moduleId);
    final ClassLoader classLoader = getClassLoader(webContext.getClassLoader());
    final Collection<Injection> injections = webContext.getInjections();
    final WebBeansContext owbCtx;
    if (webContext.getWebbeansContext() != null) {
        owbCtx = webContext.getWebbeansContext();
    } else {
        owbCtx = webContext.getAppContext().getWebBeansContext();
    }
    Context context = webContext.getJndiEnc();
    if (context == null) {
        // usually true since it is set in org.apache.tomee.catalina.TomcatWebAppBuilder.afterStart() and lookup(comp) fails
        context = webContext.getAppContext().getAppJndiContext();
    }
    final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(classLoader);
    final Collection<Object> additionalProviders = new HashSet<>();
    addAppProvidersIfNeeded(appInfo, webApp, classLoader, additionalProviders);
    // done lazily
    Collection<IdPropertiesInfo> pojoConfigurations = null;
    try {
        boolean deploymentWithApplication = "true".equalsIgnoreCase(appInfo.properties.getProperty(OPENEJB_USE_APPLICATION_PROPERTY, APPLICATION_DEPLOYMENT));
        if (deploymentWithApplication) {
            Class<?> appClazz;
            for (final String app : webApp.restApplications) {
                Application application;
                boolean appSkipped = false;
                String prefix = "/";
                try {
                    appClazz = classLoader.loadClass(app);
                    application = Application.class.cast(appClazz.newInstance());
                    if (owbCtx != null && owbCtx.getBeanManagerImpl().isInUse()) {
                        try {
                            webContext.inject(application);
                        } catch (final Exception e) {
                        // not important since not required by the spec
                        }
                    }
                } catch (final Exception e) {
                    throw new OpenEJBRestRuntimeException("can't create class " + app, e);
                }
                application = wrapApplication(appInfo, application);
                final Set<Class<?>> classes = new HashSet<>(application.getClasses());
                final Set<Object> singletons = application.getSingletons();
                if (classes.size() + singletons.size() == 0) {
                    appSkipped = true;
                } else {
                    for (final Class<?> clazz : classes) {
                        if (isProvider(clazz)) {
                            additionalProviders.add(clazz);
                        } else if (!hasEjbAndIsNotAManagedBean(restEjbs, clazz.getName())) {
                            pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
                            if (PojoUtil.findConfiguration(pojoConfigurations, clazz.getName()) != null) {
                                deploymentWithApplication = false;
                                logOldDeploymentUsage(clazz.getName());
                            }
                        }
                    }
                    if (deploymentWithApplication) {
                        // don't do it if we detected we should use old deployment
                        for (final Object o : singletons) {
                            final Class<?> clazz = o.getClass();
                            if (isProvider(clazz)) {
                                additionalProviders.add(o);
                            } else if (!hasEjbAndIsNotAManagedBean(restEjbs, clazz.getName())) {
                                pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
                                if (PojoUtil.findConfiguration(pojoConfigurations, clazz.getName()) != null) {
                                    deploymentWithApplication = false;
                                    logOldDeploymentUsage(clazz.getName());
                                }
                            }
                        }
                    }
                }
                if (deploymentWithApplication) {
                    // don't do it if we detected we should use old deployment
                    final String path = appPrefix(webApp, appClazz);
                    if (path != null) {
                        prefix += path + wildcard;
                    } else {
                        prefix += wildcard;
                    }
                }
                if (deploymentWithApplication) {
                    // don't do it if we detected we should use old deployment
                    if (appSkipped || application == null) {
                        application = !InternalApplication.class.isInstance(application) ? new InternalApplication(application) : application;
                        for (final String clazz : webApp.restClass) {
                            try {
                                final Class<?> loaded = classLoader.loadClass(clazz);
                                if (!isProvider(loaded)) {
                                    pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
                                    if (PojoUtil.findConfiguration(pojoConfigurations, loaded.getName()) != null) {
                                        deploymentWithApplication = false;
                                        logOldDeploymentUsage(loaded.getName());
                                        break;
                                    }
                                    application.getClasses().add(loaded);
                                } else {
                                    additionalProviders.add(loaded);
                                }
                            } catch (final Exception e) {
                                throw new OpenEJBRestRuntimeException("can't load class " + clazz, e);
                            }
                        }
                        if (deploymentWithApplication) {
                            addEjbToApplication(application, restEjbs);
                            if (!prefix.endsWith(wildcard)) {
                                prefix += wildcard;
                            }
                        }
                    }
                    if (!application.getClasses().isEmpty() || !application.getSingletons().isEmpty()) {
                        pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
                        deployApplication(appInfo, webApp.contextRoot, restEjbs, classLoader, injections, owbCtx, context, additionalProviders, pojoConfigurations, application, prefix);
                    }
                }
                if (!deploymentWithApplication) {
                    fullServletDeployment(appInfo, webApp, webContext, restEjbs, classLoader, injections, owbCtx, context, additionalProviders, pojoConfigurations);
                }
            }
            if (webApp.restApplications.isEmpty()) {
                final Application application = new InternalApplication(null);
                for (final String clazz : webApp.restClass) {
                    try {
                        final Class<?> loaded = classLoader.loadClass(clazz);
                        if (!isProvider(loaded)) {
                            pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
                            if (PojoUtil.findConfiguration(pojoConfigurations, loaded.getName()) != null) {
                                deploymentWithApplication = false;
                                logOldDeploymentUsage(loaded.getName());
                                break;
                            }
                            application.getClasses().add(loaded);
                        } else {
                            additionalProviders.add(loaded);
                        }
                    } catch (final Exception e) {
                        throw new OpenEJBRestRuntimeException("can't load class " + clazz, e);
                    }
                }
                addEjbToApplication(application, restEjbs);
                if (deploymentWithApplication) {
                    if (!application.getClasses().isEmpty() || !application.getSingletons().isEmpty()) {
                        final String path = appPrefix(webApp, application.getClass());
                        final String prefix;
                        if (path != null) {
                            prefix = "/" + path + wildcard;
                        } else {
                            prefix = "/" + wildcard;
                        }
                        pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
                        deployApplication(appInfo, webApp.contextRoot, restEjbs, classLoader, injections, owbCtx, context, additionalProviders, pojoConfigurations, application, prefix);
                    }
                } else {
                    fullServletDeployment(appInfo, webApp, webContext, restEjbs, classLoader, injections, owbCtx, context, additionalProviders, pojoConfigurations);
                }
            }
        } else {
            fullServletDeployment(appInfo, webApp, webContext, restEjbs, classLoader, injections, owbCtx, context, additionalProviders, pojoConfigurations);
        }
    } finally {
        Thread.currentThread().setContextClassLoader(oldLoader);
    }
}
Also used : WebContext(org.apache.openejb.core.WebContext) WebBeansContext(org.apache.webbeans.config.WebBeansContext) AppContext(org.apache.openejb.AppContext) BeanContext(org.apache.openejb.BeanContext) Context(javax.naming.Context) WebContext(org.apache.openejb.core.WebContext) Injection(org.apache.openejb.Injection) URISyntaxException(java.net.URISyntaxException) UncheckedIOException(java.io.UncheckedIOException) ServiceException(org.apache.openejb.server.ServiceException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) WebBeansContext(org.apache.webbeans.config.WebBeansContext) IdPropertiesInfo(org.apache.openejb.assembler.classic.IdPropertiesInfo) MetaAnnotatedClass(org.apache.xbean.finder.MetaAnnotatedClass) Application(javax.ws.rs.core.Application) HashSet(java.util.HashSet)

Example 5 with IdPropertiesInfo

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

the class AppInfoBuilder method buildPojoConfiguration.

private void buildPojoConfiguration(final AppModule appModule, final AppInfo appInfo) {
    for (final Map.Entry<String, PojoConfiguration> config : appModule.getPojoConfigurations().entrySet()) {
        final IdPropertiesInfo info = new IdPropertiesInfo();
        info.id = config.getKey();
        info.properties.putAll(config.getValue().getProperties());
        appInfo.pojoConfigurations.add(info);
    }
}
Also used : IdPropertiesInfo(org.apache.openejb.assembler.classic.IdPropertiesInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

IdPropertiesInfo (org.apache.openejb.assembler.classic.IdPropertiesInfo)6 BeanContext (org.apache.openejb.BeanContext)4 IOException (java.io.IOException)3 MalformedURLException (java.net.MalformedURLException)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Application (javax.ws.rs.core.Application)3 ServiceConfiguration (org.apache.openejb.assembler.classic.util.ServiceConfiguration)3 File (java.io.File)2 UncheckedIOException (java.io.UncheckedIOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Context (javax.naming.Context)2 AppContext (org.apache.openejb.AppContext)2 Injection (org.apache.openejb.Injection)2 AppInfo (org.apache.openejb.assembler.classic.AppInfo)2 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)2