Meaningless Drivel is fun!*
The moose likes EJB and other Java EE Technologies and the fly likes Calling ejb on OC4J application server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Calling ejb on OC4J application server" Watch "Calling ejb on OC4J application server" New topic
Author

Calling ejb on OC4J application server

amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231
Hi,

There is an EJB running on an OC4J server. I have a servlet runnning on tomcat on a different machine. The servlet wants to call the EJB. How can it do that?

Thanks and regards,
Amit Sanghai.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
You have to know the JNDI information of OC4J where your ejb's are deployed and then can get the stub of the home from the servler (using the JNDI information) and move further.



Rahul Bhattacharjee
LinkedIn - Blog
amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231
I tried that but it did not work. What should be the Provider url and the initial naming factory class?
amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231
I tried that but it did not work. What should be the Provider url and the initial naming factory class?
amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231
I used the following code:

protected void doPost( final HttpServletRequest request
, final HttpServletResponse response ) throws ServletException, IOException
{
InitialContext context = getInitialContext() ;

try
{
System.out.println("context : " + context.toString()) ;

// Get a reference to the Bean
Object reference = context.lookup("HELLOEJB") ;
System.out.println("object reference : " + reference.toString());

// Get a reference from this to the Bean's Home interface
HelloHome home = (HelloHome) PortableRemoteObject.narrow (reference, HelloHome.class);

System.out.println("home interface : " + home.toString());

// Create the EJBObject from the Home interface
HelloRemote hello = home.create();
System.out.println("remote interface : " + hello.toString());

// Get the result
String result = hello.helloWorld() ;
response.setContentType("text/html") ;
PrintWriter out = response.getWriter() ;
out.println("Output from HelloEJB : " + result) ;
}
catch(Exception e)
{
e.printStackTrace() ;
}
}

private InitialContext getInitialContext()
{
Hashtable props = null ;
InitialContext context = null ;
try
{
props = new Hashtable();

// For OC4J SERVER
props.put(Context.INITIAL_CONTEXT_FACTORY, "oracle.j2ee.rmi.RMIInitialContextFactory");
props.put(Context.PROVIDER_URL, "ormi://172.16.88.49:8888/Testhello") ;
context = new InitialContext(props) ;
}
catch(Exception e)
{
e.printStackTrace() ;
}
return context ;
}


The client servlet is at my machine on Tomcat. The ejb is at some other machine on OC4J. Using the above code there is no error but the ejb is not reached... It hangs, waiting for the ejb. The two machines are on a normal intranet.

Thanks and regards,
Amit.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
The posted code seems to be ok.Upto what line of the code is getting executed before it gets hung ? Have you checked the Tomcat log for errors ?
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9315
    
109

props.put(Context.PROVIDER_URL, "ormi://172.16.88.49:8888/Testhello") ;


I dont think that's the correct url, especially the Testhello part. I believe, it should be:



Also, make sure that the port 8888 is the jndi port and not the http port.


[My Blog] [JavaRanch Journal]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9315
    
109

Looks like i misspoke in my last post about the Testhello part. Have a look at this article and see if it helps.
Amit M Tank
Ranch Hand

Joined: Mar 28, 2004
Posts: 257
Take a Thread dump on both the client and server side. It will tell you where it hanged.


Amit Tank
Linked In
Sudarshan Sreenivasan
Ranch Hand

Joined: Jun 28, 2007
Posts: 188


You have to know the JNDI information of OC4J where your ejb's are deployed and then can get the stub of the home from the server (using the JNDI information) and move further.


I suppose if these the two machines are separate(Different projects with different code ) then the client would need the class files of the stubs and homes it needs to use in order to avoid compile time errors ??

Please correct me if i am wrong
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling ejb on OC4J application server
 
Similar Threads
compatability between oc4j and other application server
Ejb-servlet communication
OC4J Question
Jdeveloper - Stateless Session Bean + OC4J Exception - Urgent Please Help
jdeveloper lookup error