File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Websphere and the fly likes Connect Client  to EJB ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "Connect Client  to EJB ???" Watch "Connect Client  to EJB ???" New topic
Author

Connect Client to EJB ???

Bill Dao
Greenhorn

Joined: Nov 14, 2003
Posts: 7
I use IBM WebSphere 5.0 for development.
1) In EJB Modules, I have a SessionBean with simple helloworld method returns String "HelloWorld"). I deployed and RMIC code.
2) In Application Client Module, I have a java class with
public static void main(String [] args){
HashTable env = new HashTable();
String result;
try{
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(javax.naming.Context.PROVIDER_URL, "iiop://127.0.0.1:2809");
InitialContext initialContext = new InitialContext(env);
Object ref = initialContext.lookup("HelloWorld");
HelloWorldHome home = (HelloWorldHome)
javax.rmi.PortableRemoteObject.narrow
(ref,HelloWorldHome.class);
HelloWorld obj = home.create();
result=obj.helloworld();
System.out.print(result);
}catch (java.rmi.RemoteException re){re.printStackTrace();}
catch (javax.naming.NamingException ne){ne.printStackTrace();}
catch (javax.ejb.CreateException ce){ce.printStackTrace();}
catch (javax.ejb.FinderException fe){fe.printStackTrace();}
}
Then I create a testserver in IBM WSAD 5.0, run EJB on this server and run Application Client in Websphere Client Enviroment. I test EJB and Client on one computer and console printed "Hello World". But when I run EJB module on first computer only server with IPAdd : 10.4.100.24 and RMI connector at port 2809 , Application Client on second computer. Both of computer installed IBM WSAD 5.0 . With Client code following :
public static void main(String [] args){
HashTable env = new HashTable();
String result;
try{
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(javax.naming.Context.PROVIDER_URL, "iiop://10.4.100.24:2809");
InitialContext initialContext = new InitialContext(env);
Object ref = initialContext.lookup("HelloWorld");
HelloWorldHome home = (HelloWorldHome)
javax.rmi.PortableRemoteObject.narrow
(ref,HelloWorldHome.class);
HelloWorld obj = home.create();
result=obj.helloworld();
System.out.print(result);
}catch (java.rmi.RemoteException re){re.printStackTrace();}
catch (javax.naming.NamingException ne){ne.printStackTrace();}
catch (javax.ejb.CreateException ce){ce.printStackTrace();}
catch (javax.ejb.FinderException fe){fe.printStackTrace();}
}
I receive from second computer :
javax.naming.CommunicationException :.........."iiop://10.4.100.24:2809"....
I don't understand. Can you help me ?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
"XI_TRUM",
Your display name doesn't comply with our naming policy as it is, so you'll need to change it (both first and last name required, no underscore in between ).
Thanks, and welcome to the JavaRanch!


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Ah. I almost forgot... This question is really better suited for our IBM/WebSphere forum so I'll ask someone to move it there.
Bill Dao
Greenhorn

Joined: Nov 14, 2003
Posts: 7
OK. Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connect Client to EJB ???