Search in sources :

Example 1 with EJBObjectHandler

use of org.apache.openejb.client.EJBObjectHandler in project tomee by apache.

the class ClientObjectFactory method getEJBObject.

@Override
public javax.ejb.EJBObject getEJBObject(final ProxyInfo info) {
    final CallContext call = CallContext.getCallContext();
    final BeanContext beanContext = info.getBeanContext();
    final int idCode = -1;
    Object securityIdentity = null;
    try {
        securityIdentity = call.getEJBRequest().getClientIdentity();
    } catch (Exception e) {
        e.printStackTrace();
    }
    final ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
    final EJBMetaDataImpl eMetaData = buildEjbMetaData(info, beanContext, idCode);
    final Object primKey = info.getPrimaryKey();
    final EJBObjectHandler hanlder = EJBObjectHandler.createEJBObjectHandler(JNDIContext.globalExecutor(), eMetaData, getServerMetaData(), cMetaData, primKey, null);
    return (javax.ejb.EJBObject) hanlder.createEJBObjectProxy();
}
Also used : BeanContext(org.apache.openejb.BeanContext) EJBMetaDataImpl(org.apache.openejb.client.EJBMetaDataImpl) EJBObjectHandler(org.apache.openejb.client.EJBObjectHandler) ClientMetaData(org.apache.openejb.client.ClientMetaData)

Example 2 with EJBObjectHandler

use of org.apache.openejb.client.EJBObjectHandler in project tomee by apache.

the class ClientObjectFactory method getHandle.

@Override
public javax.ejb.Handle getHandle(final ProxyInfo info) {
    final CallContext call = CallContext.getCallContext();
    final BeanContext beanContext = info.getBeanContext();
    final int idCode = -1;
    Object securityIdentity = null;
    try {
        securityIdentity = call.getEJBRequest().getClientIdentity();
    } catch (Exception e) {
    // Ignore
    }
    final ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
    final EJBMetaDataImpl eMetaData = buildEjbMetaData(info, beanContext, idCode);
    final Object primKey = info.getPrimaryKey();
    final EJBObjectHandler handler = EJBObjectHandler.createEJBObjectHandler(JNDIContext.globalExecutor(), eMetaData, getServerMetaData(), cMetaData, primKey, null);
    return new EJBObjectHandle(handler.createEJBObjectProxy());
}
Also used : BeanContext(org.apache.openejb.BeanContext) EJBMetaDataImpl(org.apache.openejb.client.EJBMetaDataImpl) EJBObjectHandler(org.apache.openejb.client.EJBObjectHandler) EJBObjectHandle(org.apache.openejb.client.EJBObjectHandle) ClientMetaData(org.apache.openejb.client.ClientMetaData)

Example 3 with EJBObjectHandler

use of org.apache.openejb.client.EJBObjectHandler in project tomee by apache.

the class ClientObjectFactory method getBusinessObject.

@Override
public Object getBusinessObject(final ProxyInfo info) {
    final CallContext call = CallContext.getCallContext();
    final BeanContext beanContext = info.getBeanContext();
    final int idCode = -1;
    Object securityIdentity = null;
    try {
        securityIdentity = call.getEJBRequest().getClientIdentity();
    } catch (Exception e) {
        e.printStackTrace();
    }
    final ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
    final EJBMetaDataImpl eMetaData = new EJBMetaDataImpl(null, null, beanContext.getPrimaryKeyClass(), beanContext.getComponentType().toString(), beanContext.getDeploymentID().toString(), idCode, convert(info.getInterfaceType()), info.getInterfaces(), beanContext.getAsynchronousMethodSignatures());
    eMetaData.loadProperties(beanContext.getProperties());
    final Object primKey = info.getPrimaryKey();
    final EJBObjectHandler hanlder = EJBObjectHandler.createEJBObjectHandler(JNDIContext.globalExecutor(), eMetaData, getServerMetaData(), cMetaData, primKey, null);
    return hanlder.createEJBObjectProxy();
}
Also used : BeanContext(org.apache.openejb.BeanContext) EJBMetaDataImpl(org.apache.openejb.client.EJBMetaDataImpl) EJBObjectHandler(org.apache.openejb.client.EJBObjectHandler) ClientMetaData(org.apache.openejb.client.ClientMetaData)

Example 4 with EJBObjectHandler

use of org.apache.openejb.client.EJBObjectHandler 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

BeanContext (org.apache.openejb.BeanContext)4 EJBObjectHandler (org.apache.openejb.client.EJBObjectHandler)4 ClientMetaData (org.apache.openejb.client.ClientMetaData)3 EJBMetaDataImpl (org.apache.openejb.client.EJBMetaDataImpl)3 Properties (java.util.Properties)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 Assembler (org.apache.openejb.assembler.classic.Assembler)1 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)1 EnterpriseBeanInfo (org.apache.openejb.assembler.classic.EnterpriseBeanInfo)1 EJBObjectHandle (org.apache.openejb.client.EJBObjectHandle)1 InvocationHandler (org.apache.openejb.client.proxy.InvocationHandler)1 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)1 EjbModule (org.apache.openejb.config.EjbModule)1 ServerFederation (org.apache.openejb.core.ServerFederation)1 EjbJar (org.apache.openejb.jee.EjbJar)1 StatelessBean (org.apache.openejb.jee.StatelessBean)1 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)1 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)1 ServiceDaemon (org.apache.openejb.server.ServiceDaemon)1