File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Client not calling ejb method!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Client not calling ejb method!!!" Watch "Client not calling ejb method!!!" New topic
Author

Client not calling ejb method!!!

sai Narayan
Greenhorn

Joined: Aug 16, 2004
Posts: 21
hi friends,
i have a strange problem.my client code is running but it is not calling my ejb method.Please help.Thanks.
Client code:-

import java.rmi.*;
import javax.ejb.*;
import javax.naming.*;
import java.util.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;


/**
* @author Administrator
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class SessionHelloWorldClient {

public static void main(String[] args) {
try
{

Context initial = new InitialContext();
System.out.println(" initial= "+initial);
Context myEnv = (Context)initial.lookup("java:comp/env");
System.out.println(" myEnv= "+myEnv);
Object objref = myEnv.lookup("ejb/HelloWorld");
SessionHelloWorld.SessionHelloWorldHome home = (SessionHelloWorld.SessionHelloWorldHome)PortableRemoteObject.narrow(objref, SessionHelloWorld.SessionHelloWorldHome.class);
SessionHelloWorld.SessionHelloWorld sayhello = home.create();
System.out.println("Before hello()");
sayhello.Hello();
System.out.println("After hello()");

}catch(Exception e)
{
e.printStackTrace();
System.out.println("Error:- "+e);
}
}
}
Beanclass code:-
package SessionHelloWorld;

import javax.ejb.*;
public class SessionHelloWorldBean implements SessionBean {
public void ejbCreate()
{
System.out.println("ejbCreate()");
}
public void ejbRemove()
{
System.out.println("ejbRemove()");
}
public void ejbActivate()
{
System.out.println("ejbActivate()");
}
public void ejbPassivate()
{
System.out.println("ejbPassivate()");
}
public void setSessionContext(SessionContext ctx)
{
System.out.println("setSessionContext()");
}
public String Hello()
{
System.out.println("Hello()");
return "Hello World";
}

}

Remote Intercace code:-
package SessionHelloWorld;
import java.rmi.*;
import javax.ejb.*;

public interface SessionHelloWorld extends EJBObject{
public String Hello() throws RemoteException;

}

Home Interface code:-
package SessionHelloWorld;
import java.rmi.*;
import javax.ejb.*;

public interface SessionHelloWorldHome extends EJBHome{
SessionHelloWorld create() throws RemoteException,CreateException;

}

Output:-
initial= javax.naming.InitialContext@1972e3a
myEnv= com.sun.enterprise.naming.java.javaURLContext@1955970
Before hello()
After hello()
[ September 01, 2004: Message edited by: sai Narayan ]
Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
Try this in your lookup method.



If it doesn't work you might also try initializing your context with a properties arguments like this (for jboss, for example).


[ September 01, 2004: Message edited by: Leandro Melo ]

Leandro Melo
SCJP 1.4, SCWCD 1.4
sai Narayan
Greenhorn

Joined: Aug 16, 2004
Posts: 21
hi Melo
thanks for your reply. i tried all the statements that you mentioned but it didn't work.i was getting some kind of error.
i am depoying the application in j2ee sdk 1.4.in the coded name of ejb ref
i am using ejb/HelloWorld
so i think in the lookupjava:comp/env will work.what are ur suggestions?
thanks.
do reply .
[ September 01, 2004: Message edited by: sai Narayan ]
Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
Say,
i'm not an expert here, but i there seems to be a mistake in your code.


lookup method is not supposed to return a context, but a home interface reference to your bean. Try this (also try with the properties initialization parameter):



If the jndi name of your bean is HelloWorldBean.

Anyway, I think you should post the error you're getting so others can also try to help you. Is it at deploy time? runtime?
[ September 01, 2004: Message edited by: Leandro Melo ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Client not calling ejb method!!!