Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Client not calling ejb method!!!

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Every snowflake is perfect and unique. And every snowflake contains a very tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic