• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tomcat: call remote Glassfish EJB

 
Liuk Cipriota
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm trying to allow Tomcat calls a Glassfish EJB.
I wrote an EJBTest (and EJBTestRemote):


Then i took note of the JDNI portable name:


So i wrote an Application Client Project (I'm using Eclipse Luna):


In the Build Path I added the gf-client.jar as an external JAR, and HelloWorld-EJB (the Project containing the EJBTest) as a project.
Now, i deploy my EJB Project on Glassfish (v4.1), and my Client as a Standard Java Application, and IT WORKS!
The output is:


Now, i want to call the EJB from a Dynamic Web Application, deployed in Tomcat (v7).
I created a new Dynamic Web Project, with a index.jsp:

In the Build Path - Projects, i added the HelloWorld-EJB project, and in libraries i added gf-client.jar, and in Deployment Assembly too.
When i try to deploy the project on Tomcat, this is the Stacktrace:


I just lost 4 days to find solutions on Internet, but i could not solve the problem
Can someone help me?

Thank you, guys!
 
Claude Moore
Ranch Hand
Posts: 832
7
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure that somehow your client application isn't using full Glassfish runtoime ? From stack trace, it looks like that web client running in tomcat can't find some classes, whose names make me think there is some missing jar.
I remember that importing gf-client.jar wasn't enough to get all required dependencies.
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Liuk!

First of all, there's NO SUCH THING as a "Dynamic Web Project" in Tomcat or J2EE. I think you're referring to a construct of the Eclipse/IBM IDE.

Secondly, the easiest way to test and see if a Tomcat webapp can employ services in a Glassfish EJB is to write a stand-alone (non-web) Java Application to call the EJB. If you can make that work, then you can make it work in Tomcat.

One thing that's important to remember is that Tomcat and Glassfish BOTH have JNDI servers in them. However, to locate an EJB, your Tomcat webapp must address the GlassFish JNDI server, which is done by proper definition of the JNDI properties in your Tomcat webapp. They are the same values that the stand-alone app would be using.

Beyond that, I should warn you that some of our local curmudgeons will take you to task for coding that app in a JSP scriptlet. Which is obsolete, bad practice, and when it comes to debugging. Better to write a servlet, populate a javabean with the results and forward to a JSP that displays what's in the javabean.
 
Liuk Cipriota
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, thank you both for the replies.

@Claude:
After your reply, i created a new client (as java standard application) and i deselected "Glassfish" as runtime. So now i'm a bit sure that it doesnt use full Glassfish runtime.


@Tim:
Yes, i'm sorry, i was sure that i wrote i'm using Eclipse, but i was wrong :P
About the standalone App, i created a Standalone Java SE client (in Eclipse: New - Java Project), and it works only by adding gf-clients.jar and the EJB Project.
For the JNDI properties, i copied the properties used in the standalone client.
For now, my goal isn't about good practices (jsp, servlet, ecc...), but i only need the communication works. BTW i tried with a Servlet too, but it doesnt work!!

So, I can't solve the problem
I tried to do it again, by copying standalone client properties on the tomcat web application client, but nothing!!!

Thank you both again, any suggestion is accepted :'(
 
Claude Moore
Ranch Hand
Posts: 832
7
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liuk,
I am pretty sure that if you got a ClassNotFound error, there is something missing in your class path.
It seems that com.sun.enterprise.naming.SerialInitContextFactory class cannot be loaded, so, or it is not exposed by gf-clients.jar, or if it is provided by that jar somehow gf-clients isnot loaded by your webappsonce started. To verify if SerialContextFactory is provided by the gf-clients jar, just try and open it with a zip program, to see if it's included or not. If not include, you must verify what other jars need to be included. If it is included, verify if you added it in web-inf lib folder of your web app.
 
Liuk Cipriota
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just found on Internet that com.sun.enterprise.naming.SerialInitContextFactory class is in the glassfish-naming.jar
I added it to the WEB-INF/lib, to the Deployment Assembly and to the Build Path, but nothing!!!
 
Claude Moore
Ranch Hand
Posts: 832
7
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exception or error did you get this time? I would suggest you to search on glassfish docs which jars
are required for stand-alone programs to connect.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!