Search in sources :

Example 6 with IdPropertiesInfo

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

the class RESTService method afterApplicationCreated.

public void afterApplicationCreated(@Observes final AssemblerAfterApplicationCreated event) {
    if (!enabled)
        return;
    final AppInfo appInfo = event.getApp();
    if ("false".equalsIgnoreCase(appInfo.properties.getProperty("openejb.jaxrs.on", "true"))) {
        return;
    }
    quickCheckIfOldDeploymentShouldBeUsedFromEjbConfig(appInfo);
    if (deployedApplications.add(appInfo)) {
        if (appInfo.webApps.size() == 0) {
            final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
            final ClassLoader appClassLoader = getClassLoader(containerSystem.getAppContext(appInfo.appId).getClassLoader());
            Thread.currentThread().setContextClassLoader(appClassLoader);
            try {
                final Map<String, EJBRestServiceInfo> restEjbs = getRestEjbs(appInfo, null);
                if (restEjbs.isEmpty()) {
                    return;
                }
                final Collection<Object> providers;
                if (useDiscoveredProviders(appInfo)) {
                    providers = appProviders(appInfo.jaxRsProviders, appClassLoader);
                } else {
                    providers = new ArrayList<>();
                }
                if ("true".equalsIgnoreCase(appInfo.properties.getProperty(OPENEJB_USE_APPLICATION_PROPERTY, APPLICATION_DEPLOYMENT))) {
                    final Application application = new InternalApplication(null);
                    addEjbToApplication(application, restEjbs);
                    // merge configurations at app level since a single deployment is available
                    final List<IdPropertiesInfo> pojoConfigurations = new ArrayList<>();
                    BeanContext comp = null;
                    for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
                        for (final EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
                            if (comp != null) {
                                break;
                            }
                            if (bean.ejbClass.equals(BeanContext.Comp.class.getName())) {
                                comp = containerSystem.getBeanContext(bean.ejbDeploymentId);
                                break;
                            }
                        }
                        if (ejbJar.pojoConfigurations != null) {
                            pojoConfigurations.addAll(ejbJar.pojoConfigurations);
                        }
                    }
                    if (appInfo.pojoConfigurations != null) {
                        pojoConfigurations.addAll(appInfo.pojoConfigurations);
                    }
                    final Map.Entry<String, EJBRestServiceInfo> next = restEjbs.entrySet().iterator().next();
                    if (comp == null) {
                        comp = next.getValue().context;
                    }
                    deployApplication(appInfo, next.getValue().path, restEjbs, comp.getClassLoader(), comp.getInjections(), containerSystem.getAppContext(appInfo.appId).getWebBeansContext(), comp.getJndiContext(), providers, pojoConfigurations, application, wildcard);
                } else {
                    for (final Map.Entry<String, EJBRestServiceInfo> ejb : restEjbs.entrySet()) {
                        final BeanContext ctx = ejb.getValue().context;
                        if (BeanType.MANAGED.equals(ctx.getComponentType())) {
                            deployPojo(appInfo.appId, "", ejb.getValue().path, ctx.getBeanClass(), null, ctx.getClassLoader(), ctx.getInjections(), ctx.getJndiContext(), containerSystem.getAppContext(appInfo.appId).getWebBeansContext(), providers, new ServiceConfiguration(ctx.getProperties(), appInfo.services));
                        } else {
                            deployEJB(appInfo.appId, "", ejb.getValue().path, ctx, providers, appInfo.services);
                        }
                    }
                }
            } finally {
                Thread.currentThread().setContextClassLoader(oldLoader);
            }
        } else {
            for (final WebAppInfo webApp : appInfo.webApps) {
                afterApplicationCreated(appInfo, webApp);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) BeanContext(org.apache.openejb.BeanContext) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) ServiceConfiguration(org.apache.openejb.assembler.classic.util.ServiceConfiguration) IdPropertiesInfo(org.apache.openejb.assembler.classic.IdPropertiesInfo) Application(javax.ws.rs.core.Application) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) 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 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 EnterpriseBeanInfo (org.apache.openejb.assembler.classic.EnterpriseBeanInfo)2 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)2