Search in sources :

Example 36 with EjbJarInfo

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

the class RESTService method getRestEjbs.

protected Map<String, EJBRestServiceInfo> getRestEjbs(final AppInfo appInfo, final String webapp) {
    final Map<String, BeanContext> beanContexts = new HashMap<>();
    for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
        if (ejbJar.webapp && webapp != null && !ejbJar.moduleId.equals(webapp)) {
            continue;
        }
        for (final EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
            if (bean.restService) {
                final BeanContext beanContext = containerSystem.getBeanContext(bean.ejbDeploymentId);
                if (beanContext == null) {
                    continue;
                }
                beanContexts.put(bean.ejbClass, beanContext);
            }
        }
    }
    final Map<String, EJBRestServiceInfo> restEjbs = new HashMap<>();
    for (final WebAppInfo webApp : appInfo.webApps) {
        for (final String ejb : webApp.ejbRestServices) {
            if (beanContexts.containsKey(ejb)) {
                restEjbs.put(ejb, new EJBRestServiceInfo(webApp.contextRoot, beanContexts.get(ejb)));
            }
        // else ear probably
        }
    }
    for (final Map.Entry<String, BeanContext> ejbs : beanContexts.entrySet()) {
        final String clazz = ejbs.getKey();
        if (!restEjbs.containsKey(clazz)) {
            // null is important, it means there is no webroot path in standalone
            String context = null;
            if (!OLD_WEBSERVICE_DEPLOYMENT) {
                if (appInfo.appId != null && !appInfo.appId.isEmpty()) {
                    context = appInfo.appId;
                } else {
                    context = ejbs.getValue().getModuleName();
                }
            }
            restEjbs.put(clazz, new EJBRestServiceInfo(context, beanContexts.get(clazz)));
        }
    }
    beanContexts.clear();
    return restEjbs;
}
Also used : EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) BeanContext(org.apache.openejb.BeanContext) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) HashMap(java.util.HashMap) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Example 37 with EjbJarInfo

use of org.apache.openejb.assembler.classic.EjbJarInfo 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)

Example 38 with EjbJarInfo

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

the class RESTService method quickCheckIfOldDeploymentShouldBeUsedFromEjbConfig.

private void quickCheckIfOldDeploymentShouldBeUsedFromEjbConfig(final AppInfo appInfo) {
    // if forced don't update anything
    if (appInfo.properties.getProperty(OPENEJB_USE_APPLICATION_PROPERTY) != null) {
        return;
    }
    for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
        for (final EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
            if (bean.restService) {
                final BeanContext beanContext = containerSystem.getBeanContext(bean.ejbDeploymentId);
                if (beanContext == null) {
                    // ear
                    continue;
                }
                if (containsJaxRsConfiguration(beanContext.getProperties())) {
                    appInfo.properties.setProperty(OPENEJB_USE_APPLICATION_PROPERTY, "false");
                    logOldDeploymentUsage(bean.ejbClass);
                    // no need to look further
                    return;
                }
            }
        }
    }
}
Also used : EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) BeanContext(org.apache.openejb.BeanContext) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo)

Example 39 with EjbJarInfo

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

the class AppInfoBuilderTest method testShouldIgnorePortInfoThatDontMatchTheEjb.

public void testShouldIgnorePortInfoThatDontMatchTheEjb() throws Exception {
    final EjbJar ejbJar = new EjbJar();
    final SessionBean sessionBean = new SessionBean();
    sessionBean.setEjbName("MySessionBean");
    sessionBean.setEjbClass("org.superbiz.MySessionBean");
    sessionBean.setRemote("org.superbiz.MySession");
    ejbJar.addEnterpriseBean(sessionBean);
    final OpenejbJar openejbJar = new OpenejbJar();
    final EjbDeployment ejbDeployment = new EjbDeployment();
    openejbJar.addEjbDeployment(ejbDeployment);
    ejbDeployment.setEjbName("MySessionBean");
    final EjbModule ejbModule = new EjbModule(ejbJar, openejbJar);
    final EjbJarInfo ejbJarInfo = new EjbJarInfo();
    final PortInfo portInfo = new PortInfo();
    portInfo.authMethod = "DIGEST";
    portInfo.realmName = "";
    portInfo.securityRealmName = "";
    portInfo.transportGuarantee = "CONFIDENTIAL";
    portInfo.serviceLink = "DifferentInfo";
    final Properties props = new Properties();
    props.put("wss4j.in.action", "Timestamp");
    props.put("wss4j.out.action", "Timestamp");
    portInfo.properties = props;
    ejbJarInfo.portInfos.add(portInfo);
    new AppInfoBuilder(null).configureWebserviceSecurity(ejbJarInfo, ejbModule);
    final List<PortInfo> portInfoList = ejbJarInfo.portInfos;
    assertEquals(1, portInfoList.size());
    final PortInfo info = portInfoList.get(0);
    assertEquals("", info.realmName);
    assertEquals("", info.securityRealmName);
    assertEquals("DIGEST", info.authMethod);
    assertEquals("CONFIDENTIAL", info.transportGuarantee);
    assertEquals("Timestamp", portInfo.properties.getProperty("wss4j.in.action"));
    assertEquals("Timestamp", portInfo.properties.getProperty("wss4j.out.action"));
}
Also used : PortInfo(org.apache.openejb.assembler.classic.PortInfo) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) SessionBean(org.apache.openejb.jee.SessionBean) Properties(java.util.Properties) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 40 with EjbJarInfo

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

the class AppInfoBuilderTest method testShouldUseDefaultsIfSettingIsNull.

public void testShouldUseDefaultsIfSettingIsNull() throws Exception {
    final EjbJar ejbJar = new EjbJar();
    final SessionBean sessionBean = new SessionBean();
    sessionBean.setEjbName("MySessionBean");
    sessionBean.setEjbClass("org.superbiz.MySessionBean");
    sessionBean.setRemote("org.superbiz.MySession");
    ejbJar.addEnterpriseBean(sessionBean);
    final OpenejbJar openejbJar = new OpenejbJar();
    final EjbDeployment ejbDeployment = new EjbDeployment();
    openejbJar.addEjbDeployment(ejbDeployment);
    ejbDeployment.setEjbName("MySessionBean");
    final EjbModule ejbModule = new EjbModule(ejbJar, openejbJar);
    final EjbJarInfo ejbJarInfo = new EjbJarInfo();
    final PortInfo portInfo = new PortInfo();
    portInfo.serviceLink = "MySessionBean";
    ejbJarInfo.portInfos.add(portInfo);
    new AppInfoBuilder(null).configureWebserviceSecurity(ejbJarInfo, ejbModule);
    final List<PortInfo> portInfoList = ejbJarInfo.portInfos;
    assertEquals(1, portInfoList.size());
    final PortInfo info = portInfoList.get(0);
    assertEquals(null, info.realmName);
    assertEquals(null, info.securityRealmName);
    assertEquals("NONE", info.authMethod);
    assertEquals("NONE", info.transportGuarantee);
    assertTrue(portInfo.properties.isEmpty());
}
Also used : PortInfo(org.apache.openejb.assembler.classic.PortInfo) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) SessionBean(org.apache.openejb.jee.SessionBean) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)47 Assembler (org.apache.openejb.assembler.classic.Assembler)29 EjbJar (org.apache.openejb.jee.EjbJar)21 EnterpriseBeanInfo (org.apache.openejb.assembler.classic.EnterpriseBeanInfo)17 AppInfo (org.apache.openejb.assembler.classic.AppInfo)16 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)16 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)16 HashMap (java.util.HashMap)14 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)14 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)13 BeanContext (org.apache.openejb.BeanContext)11 File (java.io.File)10 InitialContext (javax.naming.InitialContext)10 StatelessBean (org.apache.openejb.jee.StatelessBean)10 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)9 ArrayList (java.util.ArrayList)8 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)8 Test (org.junit.Test)8 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)7 Properties (java.util.Properties)6