• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 403
  • Last Modified:

EJB Example Question

Folling is an EJB example I pulled off from one of the SUN's tutorials. Well it workes fine. But I have a question.???

Here is the question...
No where in the example program shows the IP address of the EJB server. So howcome the Client found the EJBServer????????.

//Here is the code for remote Interface
import javax.ejb.EJBObject;
import java.rmi.RemoteException;

public interface Converter extends EJBObject {
 
   public double dollarToYen(double dollars) throws RemoteException;
   public double yenToEuro(double yen) throws RemoteException;
}
Here is the Home Interface
import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;

public interface ConverterHome extends EJBHome {

    Converter create() throws RemoteException, CreateException; }


Here is the EJB
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;

public class ConverterEJB implements SessionBean {
 
   public double dollarToYen(double dollars) {

      return dollars * 121.6000;
   }

   public double yenToEuro(double yen) {

      return yen * 0.0077;
   }

   public ConverterEJB() {}
   public void ejbCreate() {}
   public void ejbRemove() {}
   public void ejbActivate() {}
   public void ejbPassivate() {}
   public void setSessionContext(SessionContext sc) {}
}


And finally here is the Client
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

import Converter;
import ConverterHome;

public class ConverterClient {

   public static void main(String[] args) {
       try {
           Context initial = new InitialContext();
           Object objref = initial.lookup("MyConverter");

           ConverterHome home =
               (ConverterHome)PortableRemoteObject.narrow(objref,
                                            ConverterHome.class);

           Converter currencyConverter = home.create();

           double amount = currencyConverter.dollarToYen(100.00);
           System.out.println(String.valueOf(amount));
           amount = currencyConverter.yenToEuro(100.00);
           System.out.println(String.valueOf(amount));

           currencyConverter.remove();

       } catch (Exception ex) {
           System.err.println("Caught an unexpected exception!");
           ex.printStackTrace();
       }}}

Your input is very valuable.
-prain
0
prain
Asked:
prain
1 Solution
 
blackCommented:
It get's a new InitialContext which simply uses localhost. For this to work I assume you had the EJB
Server running on the same machine as the client.
0
 
blackCommented:
also check out this link which tells you how to change the default values:
http://java.sun.com/products/jndi/tutorial/beyond/env/source.html#APPRES

basically put a jndi.properties file in the class path with the entries you want.
0
 
TuvokCommented:
This question appears to have been abandoned. In fact, I will include links to ALL your open questions

below:

Your options are:
1.  Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you

wish to do this, and allow for Expert response.
3.  Ask Community Support to help split points between participating experts, or just comment here with

details and we'll respond with the process.
4.  Delete the question. Again, you must tell the other participants why you wish to do this.

For special handling needs, please post a zero point question in the link below, include the question

QID/link.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

Please click this Help Desk link for Member Guidelines, Member Agreement and the Question/Answer process:

Click you Member Profile to view your question history and keep them all current with updates as the

collaboration effort continues.
http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp


PLEASE DO NOT AWARD THE POINTS TO ME.  

------------>  EXPERTS:

Please leave any comments regarding this question here on closing recommendations if this item remains

inactive another three days.

Thank you everyone.

Open Qs:
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11862698
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11874078
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20059847
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20138628
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20158216
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20158215
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20167637
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20167641
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20270929


Tuvok
Moderator @ Experts Exchange

P.S.  For year 2000 question, special attention is needed to ensure the first correct response is awarded,

since they are not in the comment date order, but rather in Member ID order.

0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
blackCommented:
deleting the question would be my suggestion
0
 
TuvokCommented:
black:
Thank you for returning to this question!

I will wait for a couple of days before deletion, in case prain returns to the question.

Tuvok,
Moderator@Experts-Exchange
0
 
CleanupPingCommented:
prain:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
sudhakar_koundinyaCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


[deleted and points not refunded]


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now