• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jndi context

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
While refering another bean, we have to lookup its remote interface in jndi context. Normally we use following construct
Context jndiContext = new InitialContext()
Object objRef = jndiContext.lookup("<bean-jndi-name>")
Here it is assumed that the referenced bean is deployed on the same server. But if we want to refer to a bean which is on a remote server, we have to provide the location of the that server while getting the jndi context. For this we have to hardcode the address of the other server in our bean. But this is a problematic situation. Can anybody suggest a better way to do this ? (for example using properties file)
-Sujit Nene
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You would use a bean reference in the deployment descriptor. At deployment time you give the real JNDI location of the referenced bean. This gives you an additional layer of indirection: the other bean's location is specified at deployment time, you should not have to hardcode it in your EJB.
- Peter

[This message has been edited by Peter den Haan (edited April 30, 2001).]
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter,
Please explain how u will do this in detail.
Thanks in advance
Cherry
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Cherry Mathew:
Please explain how u will do this in detail.


I can only explain in part. Setting up a bean reference in the EJB descriptor is easy.

(See section 14.3.1.2 of the EJB spec v1.1). The link to the actual bean is made at deployment time, and that's where I cannot help you, as deployment varies from application server to application server. You are at the mercy of the server here - if two servers refuse to link up their JNDI trees at this stage then you may well be stuck.
- Peter

[This message has been edited by Peter den Haan (edited May 02, 2001).]
 
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Since you are accessing the EJB deployed in another J2EE machine ( not the same machine as your client), you will have to specify this information when looking you the initial context.
To do that you have 2 choices
-----------------------------
1) Use java.util.Properties object to set the properties of the initial Host for the JNDI ( the machine which has the EJB)
Dorg.omg.CORBA.ORBInitialHost=buzz
here 'buzz' is the name of the machine that has the EJB.
So your code will be something like this
Properties prop = new Properties();
// u will set the properties over here
Context initial = new InitialContext(prop);

2) Specify this property as a system property when you start your client application
you will do it something like this
java -Dorg.omg.CORBA.ORBInitialHost=buzz ClientApplicaton
Here again 'buzz' is the name of the machine that contains the EJB Object that your client is trying to access.
When you are using this method make sure that you use the default InitialContext constructor in your source code i.e Context initial = new InitialContext();
---------------------------------

I have tried the 2nd method on a J2EE server and it work perfectly fine, and I have tried both the methods on a Weblogic5.1 Server and it works fine.
Assumptions made for the above 2 choices
----------------------------------------
1) The JNDI naming service is running on the same machine as the Machine that contains the
deployed EJB ( i.e buzz ) : In a real world you may have JNDI running on Machine A , EJB
deployed in Machine B , and Client in Machine C.In this case you will look up the initial
context on Machine A , which contains the information about where the EJB are deplyed, in
effect you as the client do not need to know on which machine the EJB is deployed -- this is
on the same lines as location Transperency in distributed applications.
2) The J2EE server uses the default port no: The J2EE server that contains your deplyed EJB
uses the default port number, if it were listening on a different port number then you can
sepciffy that in the Properties, in either of the above mentioned methods.
You can more information about this stuff in the J2EE docs
'Developer's Guide' Chapter 8 - Clients

Vivek Viswanathan
P.S I still have to learn to spell.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This solution does work a treat with refrence j2ee version 1.2, and i had been using it for a while.
However, try with 1.3 and it doesnt work.
 
Vivek Viswanathan
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx , I too tried it with 1.2, I should b trying it with 1.3 as soon as possible
Vivek
 
Vivek Viswanathan
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have verified the program using J2ee 1.3 and it works perfectly fine.
I have used JDK 1.3 for the client , I faced a problem when using JDK 1.2
I can send you the code, along with the client , if u want??
Vivek
 
If you are using a rototiller, you are doing it wrong. Even on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic