Solved

EJB Example Question

Posted on 2001-07-26
7
381 Views
Last Modified: 2013-11-24
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
Comment
Question by:prain
7 Comments
 
LVL 3

Expert Comment

by:black
ID: 6325526
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
 
LVL 3

Accepted Solution

by:
black earned 50 total points
ID: 6325552
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
 

Expert Comment

by:Tuvok
ID: 6828807
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 3

Expert Comment

by:black
ID: 6828835
deleting the question would be my suggestion
0
 

Expert Comment

by:Tuvok
ID: 6828878
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
 

Expert Comment

by:CleanupPing
ID: 9061951
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
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 9208317
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groovy example issue 10 90
HTTPSessionBindingListernter not configured in deployment descriptor 2 40
more than one jdk and one jre 1 34
table example 4 25
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now