For accessing a remote Student EJB, we can use the following JNDI URLs:
URL |
When to use |
java:global/CourseManagement/ CourseManagementEJBs/Student!packt.jee.book.ch6.StudentRemote |
The client can be in the same application or remote. In the case of a remote client, we need to set up proper InitialContext parameters. |
java:global/CourseManagement/CourseManagementEJBs/Student |
The client can be in the same application or remote. We skipped the interface name because the bean implements only one business interface. |
java:app/CourseManagementEJBs/Student Or java:app/CourseManagementEJBs/Student!packt.jee.book.ch6.StudentRemote |
The client can be anywhere in the EAR. We skipped the application name because the JNDI namespace is java:app. |
java:module/Student Or java:module/Student!packt.jee.book.ch6.StudentRemote |
The client must be in the same EAR as the EJB. |
To access EJBs from a remote client, you need to use the JNDI lookup method. Furthermore, you need to set up InitialContext with certain properties; some of them are JEE application server specific. If the remote EJB and the client are both deployed in GlassFish (different instances of GlassFish), then you can look up the remote EJB as follows:
Properties jndiProperties = new Properties(); jndiProperties.setProperty("org.omg.CORBA.ORBInitialHost",
"<remote_host>"); //target ORB port. default is 3700 in GlassFish jndiProperties.setProperty("org.omg.CORBA.ORBInitialPort",
"3700"); InitialContext ctx = new InitialContext(jndiProperties); StudentRemote student =
(StudentRemote)ctx.lookup("java:app/CourseManagementEJBs/Student"); return student.getCourses();