Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB3.0 and Struts with different servers

 
Gaurav Ag Agarwal
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Well i'm making EJB3.0 in netbeans with GlassFush server2.1 and for client struts framework in Tomcat5.5 server. But whn finally running the application getting the error as follows..

This is my struts action class where i'm getting error..

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

TestAppForm testReference=(TestAppForm)form;
String userName=testReference.getName();
String firstName=testReference.getfirstName();
TestSessionRemote jndiReference=lookupTestSessionBean();
jndiReference.insert(userName, firstName);
return mapping.findForward(SUCCESS);
}

private TestSessionRemote lookupTestSessionBean() {
try {
Context c = new InitialContext();
System.out.println(c+" this is initial context");

return (TestSessionRemote) c.lookup("mytestapp"); // here i'm getting error
} catch (NamingException ne) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
throw new RuntimeException(ne);
}
}


error as:

javax.naming.InitialContext@31ff23yhis is initial context
25 Mar, 2010 10:04:15 AM com.mq.action.TestAction lookupTestSessionBean
SEVERE: exception caught
javax.naming.NameNotFoundException: Name mytestapp is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:769)
at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:136)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at com.mq.action.TestAction.lookupTestSessionBean(TestAction.java:56)
at com.mq.action.TestAction.execute(TestAction.java:47)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

From stack trace, you can make out that the naming provider throwing the exception is Tomcat's own naming provider. That's because Tomcat configures its own naming provider as default provider.

But what you actually need is for your application to contact Glassfish server's naming provider, not Tomcat's. So,

Step 1: Create a file 'jndi.properties' and add it under /WEB-INF or /WEB-INF/classes. The contents of this 'jndi.properties' specify how to contact Glassfish's naming provider:

If Glassfish server's running in a different machine, set that machine's hostname or IP instead of localhost. Port 3700 is by default, unless it's been changed in the domain.xml.

Step 2: In lookupTestSessionBean(), load 'jndi.properties' using


Step 3: Create the InitialContext using these loaded Properties.


Step 4: Those entries in 'jndi.properties' refer to classes inside GLASSFISH/lib jars. Glassfish jar dependencies are multilevel and rather complex. So instead of adding jars to your /WEB-INF/lib like you'd normally do, it's better to add the entire directory as a class repository to Tomcat's shared ClassLoader. You can do this by adding the line "GLASSFISH/lib/*.jar" (where GLASSFISH/lib is the actual filepath of your Glassfish lib folder) to the 'shared.loader' key in TOMCAT's '/conf/catalina.properties’.

Cheers
Karthik
 
Gaurav Ag Agarwal
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thnks man...
 
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!