Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Client not calling ejb method!!!

 
sai Narayan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
sai Narayan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic