aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Access EJB deployed in external machine. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Access EJB deployed in external machine." Watch "Access EJB deployed in external machine." New topic
Author

Access EJB deployed in external machine.

Gurumurthy Ramamurthy
Ranch Hand

Joined: Feb 13, 2003
Posts: 272
Hi, I have deployed an EJB with JNDI AccountBean in machine 10.17.24.117:1099, can I call this EJB from another EJB with following entry in DEPLOYMENT DESCRIPTOR?

<ejb-ref>
<jndi-name> jnp://10.17.24.117:1099/AccountBean</jndi-name>;
</ejb-ref>

or atleast from stand-alone client, can I access by just giving as above?

I know one method:
If an application wants to access ejb deployed in machine 10.17.24:117:1099 under AccountBean, what is the way to access/how the client would access.

From client program (stand-alone java, or servlet, or jsp or other EJB):

These need to be put and context need to be intantiated as below:

p.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
p.put("java.naming.provider.url", "jnp://localhost:1099");
p.put("java.naming.factory.url.pkgs", "org.jboss.naming rg.jnp.interfaces");

Context ctx = new InitialContext(p);

Then, you can get the bean reference as below:
/* Get a reference to a bean instance, looked up by class name */
Account cart = (Account) ctx.lookup("AccountBean/remote");

Thanks,
Guru
Sven Meys
Greenhorn

Joined: Feb 13, 2008
Posts: 7
This is how it's done on JBOSS atleast

You need an application-client.xml file in the META-INF directory of your MyClient.jar:

<application-client>
<display-name>MyClient</display-name>
<ejb-ref>
<ejb-ref-name>ejb/MyBean</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>com.example.MyEjbHome</home>
<remote>com.example.MyEjb</remote>
<ejb-link>MyEjb.jar#MyBean</ejb-link>
</ejb-ref>
</application-client>

A jndi.properties file in the root of your MyClient.jar:

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://<ip here>:1099
java.naming.factory.url.pkgs=org.jboss.naming.client ...jboss specific
j2ee.clientName=MyClient ...same as display-name

In your application.xml file you need to add:
<module>
<java>MyClient.jar</java>
</module>


Running your client jar from a remote computer should now work by doing

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
Object objRef = envCtx.lookup("ejb/MyBean");
MyBeanHome mbh = (MyBeanHome)PortableRemoteObject.narrow(objRef,MyBeanHome.class);
MyBean mb = mbh.create();
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Access EJB deployed in external machine.