You've got the right idea.

Definitely make sure you use the WebSphere's InitialContextFactory instead of 
TomEE's.  Think of the `java.naming.factory.initial` like a JDBC driver.  
Connecting to an Oracle DB requires an Oracle driver in TomEE, connecting to 
WebSphere for EJB requires the WebSphere `java.naming.factory.initial` factory.

You also want to change the <JndiProvider id=""> to be something simple.  Note 
this field is not used for the JNDI name of the bean you'd like to lookup.  A 
simple name like "websphere" would work.

    <tomee>
      <JndiProvider id="websphere" type="javax.naming.InitialContext">
  
        java.naming.provider.url = 
corbaname:iiop:<hostName>:<port>/NameServiceServerRoot
        java.naming.factory.initial = 
<websphere-InitialContextFactory-implementation>
      </JndiProvider>
    </tomee>

Then in your application where you want to lookup a bean from WebSphere, you 

    import javax.ejb.EJB;
    import javax.ejb.Singleton;
    
    @Singleton
    public class SomeTomeeBean {
    
    
        @EJB(mappedName = "jndi:ext://websphere/<jndi-name-of-the-remote-bean>")
        private OrangeBean orangeBean;
    
    }

The value of `jndi-name-of-the-remote-bean` must be the JNDI name a plain Java 
client would use to lookup that bean in WebSphere.

To better understand, here are the mechanics TomEE uses which are rather simple:

  - When TomEE goes to inject the OrangeBean, it sees the bean is not provided 
by TomEE because there is "jndi:ext:" in the mappedName
  - TomEE then uses what ever text comes next in the URI 
"jndi:ext:<provider-id>/" to find the `<JndiProvider>` configured in the 
tomee.xml
  - TomEE constructs an InitialFactory(properties) passing in *all* properties 
configured between the `<JndiProvider>` and `</JndiProvider>` tags
  - Now with an InitialContext instance in hand, TomEE uses the 
`jndi-name-of-the-remote-bean` value to do a lookup.
  - The resulting object is injected into the OrangeBean field.

Hope this helps!


-David

On Feb 27, 2014, at 8:21 AM, asingh <abhishek.sing...@yahoo.com> wrote:

> Hi,
> Is their an example out there which demonstrates connecting to the EJB
> deployed on Websphere from TomEE instance?
> 
> I did try to do so by using tomee.xml file but did not help:
> <tomee>
>  <JndiProvider id=&quot;&lt;jndiName>" type="javax.naming.InitialContext">
>    java.naming.provider.url =
> corbaname:iiop:<hostName>:<port>/NameServiceServerRoot
>    java.naming.factory.initial =
> org.apache.openejb.client.RemoteInitialContextFactory
>  </JndiProvider>
> </tomee>
> 
> On run time I see this in my Initial Context:
> {java.naming.factory.initial=org.apache.naming.java.javaURLContextFactory,
> java.naming.factory.url.pkgs=org.apache.naming:org.apache.openejb.core.ivm.naming}
> 
> 
> 
> --
> View this message in context: 
> http://openejb.979440.n4.nabble.com/Connecting-to-EJB-Deployed-on-Websphere-from-TomEE-server-tp4668017.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Reply via email to