Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Access EJB deployed in external machine.

 
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic