• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing a Remote EJB in Glassfish from Tomcat

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchmates,

I am having some troubles in accessing a Remote EJB (version 3.0) in Glassfish v2.1 from Tomcat 5.

I’d already copied the following required jar below in %CATALINA_HOME\shared\lib:

- appserv-rt
- appserv-ext
- appserv-deployment-client
- javaee

My Servlet:


My SessionBean:


I deployed my web app in a war file.

As I’d follow the implementations in this link https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#nonJavaEEwebcontainerRemoteEJB

&

http://technology.amis.nl/blog/1368/connecting-to-an-ejb-30-remote-sessionbean-from-tomcat


Unfortunately, lots of errors appears (the usual error for this topic), naming, classNotFound, NoClassDefFoundError, etc…

Unless I’ve miss something important!

Your response is highly appreciated.

Thank you very much!

Daniel
 
author
Posts: 580
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Daniel,

I would first check with the GlassFish folks to see if the resources you are using are really up to date. Then, I would post specific questions here.

Regards,
Reza
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,



Based on your configuration, the glassfish app server is on the same machine as the tomcat. If not, then please change it to the actual IP.

Given that all jars are present, then if the configuration of the host and port are incorrect then you would only get NamingException. Other exceptions would point to configuration and environment problems.

Regards.
 
Daniel Jabonete
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am running my Glassfish and Tomcat in the same machine without any conflicts, host or ports. I’ve also tested it in a peer-2-peer environment without any issues, aside from the accessing the Remote EJB using Tomcat.

I’ve tested it via stand-alone client and it works, in a network environment, as well in the same machine (localhost/127.0.0.1), please see below:



With regards to the results of the test, it seems that I am missing something in the configurations for Tomcat 5.

As in my original post I’d included/copied the required jar files in %CATALINA_HOME%\shared\lib folder in my Tomcat.

I’ve checked the MANIFEST.MF of appserv-rt.jar, in which referring to the ff. jar below:

appserv-rt_ja.jar
appserv-rt_zh.jar
appserv-rt_fr.jar
appserv-rt_de.jar
appserv-rt_es.jar
appserv-rt_it.jar
appserv-rt_sw.jar
appserv-rt_ko.jar
appserv-rt_zh_TW.jar
appserv-rt_zh_CN.jar

I am not sure where this jar files are located.

As I’ve ran the client successfully which is specifically referring its classpath to the required jars, how can we do this in Tomcat.

Any help will be highly appreciated.

Thanks!

Daniel
 
Jerwin Louise Uy
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Is it possible for you to post the stacktrace here?

Regards.
 
Daniel Jabonete
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

This is the latest stackTraceError for this issues, please see below:



By the way, the version of my Glassfish is "Sun GlassFish Enterprise Server v2.1 (9.1.1) (build b60e-fcs)", as I understand that there are bugs fixes related to this.

This is the latest promoted builds in https://glassfish.dev.java.net/public/downloadsindex.html.

So more or less my Glassfish is up to date.

Regards,

Daniel
 
Jerwin Louise Uy
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The application failed to load the JAR file of the EJB. Please check whether the ejb-jar is in the classloader path of your web application (WEB-INF\lib).

Regards.
 
Daniel Jabonete
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I included the “interface class” in my war file (web app) in Tomcat and it works.

It seems that when accessing a Remote EJB deployed in Glassfish from Tomcat, the web application deployed in Tomcat need also the jar or classes/interfaces like the one deployed in Glassfish.

Is this only for Glassfish Application Server, or is this stated in the EJB 3.0 Specs?

This seems not portable in a sense that the “remote interface class” should be equal to each other when doing this set-up.

Thanks very much, I appreciate it.

Cheers!

Daniel
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I included the “interface class” in my war file (web app) in Tomcat and it works.



Yes, you need the interface to the EJB in order to connect to it and call it's business methods. This is how EJBs work. This is true whether the client is local or remote, and is common with all Java Application servers.

Keep in mind that there is a lot of EJB code that is generated by the application server, not you the programmer. So, the interface API on a remote client is not the same as the code that is in the application server.



This seems not portable in a sense that the “remote interface class” should be equal to each other when doing this set-up.



This sentence is confusing. "What" should be equal to each other when doing "what" set-up? Please explain.

The remote objects that enable client code to connect to the EJB are not required on the server. An EJB is never a client of itself. This does not make any sense.





 
Reza Rahman
author
Posts: 580
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Daniel,

Hmm...is there some confusion here?

All you should need from the EJB code is the business interfaces for the client to make the call through. Although simply copying over the interface classes to the WAR is fine unless it is within the same EAR as the EJB JAR (because the class would be loaded twice in the same class loader hierarchy, which is wrong), the best practice in this case would be to separate the interfaces out into a separate EJB client JAR (http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.jst.ejb.doc.user/topics/ceclientjars.html) and have both the WAR and EJB JAR reference the common JAR with the interfaces. Most IDEs support this, Eclipse certainly does...

What is the portability issue that you see? There is nothing all that different here than using any ordinary Java interface to any old API? What do you think the expected behavior should be?

Thanks,
Reza
 
Daniel Jabonete
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

My apologies for the confusion, please let me clear the set-up I am illustrating.

Machine 1:
IP Address = 192.168.1.1
App Server = Glassfish (latest version)
Deployed EJB (ver. 3.0):


Machine 2:
IP Address = 192.168.1.2
Web Server = apache-tomcat-5.5.27
Deployed WAR file:


The SimpleBean:
In which this "interface" was deployed in Glassfish & Tomcat.


The Servlet in the Web App deployed in Tomcat.


Basically, as illustrated above, if the SimpleBean interface changes you need to apply those changes in machine 1 & 2.
We need to copy over the modified (if there are) SimpleBean.class in Glassfish (machine 1) and in Tomcat (machine 2).

So the client (particularly in web application) need the copy of the EJB in order to connect to a Remote Machine with the same EJB.

Now, is this a binding contract in accessing Remote EJB? Is it written in the specs?

Thanks very much, really appreciate your time and effort. If there are still some confusions, please let me know.

P.S.
I'd contacted the author of the blog from my first post, and he re-read his blog and he said that he failed to mention that the EJB needs to be included in Tomcat.

Cheers!

Daniel
 
Reza Rahman
author
Posts: 580
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Daniel,

OK. As I mentioned, the best practice in your case would be to extract just the EJB remote interface to a separate JAR. The EJB spec calls this the EJB client JAR (as described in the link above). This jar would just contain some simple POJOs (for example DTOs passed as EJB parameters) and POJIs (for example, the business interfaces), no container generated stuff.

This common interface then needs to be referenced both by the client on Tomcat and the EJB JAR containing the EJB implementation. This way, there is no copying of source code. You simply have your build system generate the JAR ans place it as a dependency for both the client and the EJB jar. For example, Eclipse will help you with this, as will ANT, Maven, etc.

This make more sense? Or do you see a possibility of doing this better with existing Java semantics. modularization and class-loading?

Regards,
Reza
 
reply
    Bookmark Topic Watch Topic
  • New Topic