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
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).]
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 220.127.116.11 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).]
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.
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