Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access EJB deployed in external machine.

 
Gurumurthy Ramamurthy
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic