Search in sources :

Example 51 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 52 with EjbJarInfo

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

the class PropertiesPropogationTest method test.

public void test() throws Exception {
    EjbServer ejbServer = new EjbServer();
    Properties initProps = new Properties();
    initProps.setProperty("openejb.deployments.classpath.include", "");
    initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
    OpenEJB.init(initProps, new ServerFederation());
    ejbServer.init(new Properties());
    ServicePool pool = new ServicePool(ejbServer, 10);
    ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
    serviceDaemon.start();
    int port = serviceDaemon.getPort();
    Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    ConfigurationFactory config = new ConfigurationFactory();
    EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
    EjbJar ejbJar = ejbModule.getEjbJar();
    OpenejbJar openejbJar = ejbModule.getOpenejbJar();
    StatelessBean statelessBean = ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
    EjbDeployment deployment = openejbJar.addEjbDeployment(statelessBean);
    deployment.getProperties().put("color", "orange");
    deployment.getProperties().put("openejb.client.color", "red");
    EjbJarInfo ejbJarInfo = config.configureApplication(ejbModule);
    EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
    assertTrue(beanInfo.properties.containsKey("color"));
    assertTrue(beanInfo.properties.containsKey("openejb.client.color"));
    assertEquals("orange", beanInfo.properties.get("color"));
    assertEquals("red", beanInfo.properties.get("openejb.client.color"));
    assembler.createApplication(ejbJarInfo);
    ContainerSystem cs = SystemInstance.get().getComponent(ContainerSystem.class);
    BeanContext info = cs.getBeanContext("WidgetBean");
    assertNotNull(info);
    assertTrue(info.getProperties().containsKey("color"));
    assertTrue(info.getProperties().containsKey("openejb.client.color"));
    assertEquals("orange", info.getProperties().get("color"));
    assertEquals("red", info.getProperties().get("openejb.client.color"));
    Properties props = new Properties();
    props.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
    props.put("java.naming.provider.url", "ejbd://127.0.0.1:" + port);
    Context context = new InitialContext(props);
    Widget remote = (Widget) context.lookup("WidgetBeanRemote");
    InvocationHandler handler = ProxyManager.getInvocationHandler(remote);
    EJBObjectHandler objectHandler = EJBObjectHandler.class.cast(handler);
    Properties properties = objectHandler.getEjb().getProperties();
    // Should only contain "openejb.client.*" properties
    assertFalse(properties.containsKey("color"));
    // The openejb.client.color property should have been propogated
    assertTrue(properties.containsKey("openejb.client.color"));
    assertEquals("red", properties.getProperty("openejb.client.color"));
    serviceDaemon.stop();
    OpenEJB.destroy();
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) InitialContext(javax.naming.InitialContext) BeanContext(org.apache.openejb.BeanContext) Context(javax.naming.Context) ServerFederation(org.apache.openejb.core.ServerFederation) EJBObjectHandler(org.apache.openejb.client.EJBObjectHandler) ServicePool(org.apache.openejb.server.ServicePool) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) InvocationHandler(org.apache.openejb.client.proxy.InvocationHandler) InitialContext(javax.naming.InitialContext) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) BeanContext(org.apache.openejb.BeanContext) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) StatelessBean(org.apache.openejb.jee.StatelessBean) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)52 Assembler (org.apache.openejb.assembler.classic.Assembler)34 EjbJar (org.apache.openejb.jee.EjbJar)26 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)21 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)21 EnterpriseBeanInfo (org.apache.openejb.assembler.classic.EnterpriseBeanInfo)17 AppInfo (org.apache.openejb.assembler.classic.AppInfo)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 Properties (java.util.Properties)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 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)8 Test (org.junit.Test)8