Skip to main content

ResourceAdapter (JCA) from EJB, in EAR

5 replies [Last post]
jeltejansons
Offline
Joined: 2008-03-19

Hi,

Currently I am having some difficulties with using a resource adapter (JCA) from an EJB inside an EAR file. I need to get this working in Sun AppServer 9 or GlassFish v2.

I succesfully tested the following setup:
Remote Client <-> Stateless Session Bean (EJB) <-> JCA <-> File system

It works for me when I deploy the EJB as EJB Module and the JCA as Connector.

The problem is that I need to deploy my application as Enterprise Application Project since both the EJB Module and JCA share some libraries. I do not want to put those libraries in the lib folder of my domain to prevent ClassLoader problems.

I read the documentation "Deploying and Configuring an Embedded Resource Adapter" in the Sun Java System Application Server Platform Edition 9 Developer's Guide. (http://docs.sun.com/app/docs/doc/819-3659/bealq?a=view). The documentation says The association between the physical JNDI name for the connector module in the Application Server and the logical JNDI name used in the application component is specified in the Application Server specific XML descriptor sun-ejb-jar.xml.

I am looking for a code example of how to use the sun-ejb-jar in my example. When I deploy the Connector (JCA) stand alone I need to create a connection pool and resource. This works very fine. I just cannot get it working inside the EAR. Do I also need to create the connection pool and resource when I deploy my connector (resource adapter) inside an EAR?

All the examples I see are related to MDb but I am using a Stateless Session Bean and my JCA reads some file from the file system, something I would like to avoid in my EJB.

Does anybody have an idea or code example?

Thanks and merry christmas to all of you!

Jelte

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Markus Karg

GFv2 does not make a difference between RARs deployed standalone and RARs deployed as part of an EAR. In fact it is a bit odd: You first must deploy your EAR, and in this turn GF will say that it cannot find the RA used by the EJB. Then, create the RA connection pool. Now undeploy your application, and deploy it again. This time the EJB can find the RA, since it finds the connection pool. Sounds odd, but it is the only way to make it work, unless this conceptional bug of GlassFish is solved.

Regards
Markus

> -----Original Message-----
> From: glassfish@javadesktop.org [mailto:glassfish@javadesktop.org]
> Sent: Donnerstag, 25. Dezember 2008 04:39
> To: users@glassfish.dev.java.net
> Subject: ResourceAdapter (JCA) from EJB, in EAR
>
> Hi,
>
> Currently I am having some difficulties with using a resource adapter
> (JCA) from an EJB inside an EAR file. I need to get this working in Sun
> AppServer 9 or GlassFish v2.
>
> I succesfully tested the following setup:
> Remote Client <-> Stateless Session Bean (EJB) <-> JCA <-> File system
>
> It works for me when I deploy the EJB as EJB Module and the JCA as
> Connector.
>
> The problem is that I need to deploy my application as Enterprise
> Application Project since both the EJB Module and JCA share some
> libraries. I do not want to put those libraries in the lib folder of my
> domain to prevent ClassLoader problems.
>
> I read the documentation "Deploying and Configuring an Embedded
> Resource Adapter" in the Sun Java System Application Server Platform
> Edition 9 Developer's Guide. (http://docs.sun.com/app/docs/doc/819-
> 3659/bealq?a=view). The documentation says [i]The association between
> the physical JNDI name for the connector module in the Application
> Server and the logical JNDI name used in the application component is
> specified in the Application Server specific XML descriptor sun-ejb-
> jar.xml.[/i]
>
> I am looking for a code example of how to use the sun-ejb-jar in my
> example. When I deploy the Connector (JCA) stand alone I need to create
> a connection pool and resource. This works very fine. I just cannot get
> it working inside the EAR. Do I also need to create the connection pool
> and resource when I deploy my connector (resource adapter) inside an
> EAR?
>
> All the examples I see are related to MDb but I am using a Stateless
> Session Bean and my JCA reads some file from the file system, something
> I would like to avoid in my EJB.
>
> Does anybody have an idea or code example?
>
> Thanks and merry christmas to all of you!
>
> Jelte
> [Message sent by forum member 'jeltejansons' (jeltejansons)]
>
> http://forums.java.net/jive/thread.jspa?messageID=323246
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net

jeltejansons
Offline
Joined: 2008-03-19

Thanks! That did they trick!

I now understand that I need to make the Connection Pool and Resource even for Connectors (JCA) that are inside an EAR. The connector is also listed as Resource Adapter EJBWithEAR#PropertiesConnector in the Connector Conection Pool.

The new problem that I run into is a ClassNotFoundException because the EJB uses the connector. This is weird since they are both inside the same EAR file. I tried to play by adding the interfaces into a seperare JAR and importing them without result. I also tried the
in application.xml. But it does not work.

Does GlassFishV2 support a Connector inside an EAR? What am I doing wrong here?

Thanks!
Jelte

Markus Karg

As I wrotein this forum before: You do nothing wrong. You cannot get rid of the ClassNotFoundException. This is a bug in GlassFish's conception. You have to live with it. The message is gone as soon as you have deployed a second time, after the pool is installed. After the pool is installed and you undeployed and deployed again AND stopped and restarted GlassFish, the app will work correctly. Yes that sounds crazy but it is the result of the misconception in GFv2.

Regards
Markus

> -----Original Message-----
> From: glassfish@javadesktop.org [mailto:glassfish@javadesktop.org]
> Sent: Freitag, 26. Dezember 2008 15:04
> To: users@glassfish.dev.java.net
> Subject: Re: RE: ResourceAdapter (JCA) from EJB, in EAR
>
> Thanks! That did they trick!
>
> I now understand that I need to make the Connection Pool and Resource
> even for Connectors (JCA) that are inside an EAR. The connector is also
> listed as Resource Adapter EJBWithEAR#PropertiesConnector in the
> Connector Conection Pool.
>
> The new problem that I run into is a ClassNotFoundException because the
> EJB uses the connector. This is weird since they are both inside the
> same EAR file. I tried to play by adding the interfaces into a seperare
> JAR and importing them without result. I also tried the
> directory> in application.xml. But it does not work.
>
> Does GlassFishV2 support a Connector inside an EAR? What am I doing
> wrong here?
>
> Thanks!
> Jelte
> [Message sent by forum member 'jeltejansons' (jeltejansons)]
>
> http://forums.java.net/jive/thread.jspa?messageID=323334
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net

jeltejansons
Offline
Joined: 2008-03-19

Thanks again for your quick reply. I did not understand that you meant ClassNotFoundException when you meant could not be found. I thought you meant cannot be found in JNDI.

It was the restart of GlassFish that I forgot. When I restarted it the problem was solved.

I need to discuss with my team if we want to live with this workaround or simply deploy as standalone modules (not EAR)

But the most important is you got it working for me!

Thanks for your help!

Message was edited by: jeltejansons

Markus Karg

The problem of the unclean undeployment is not Eclipse related. You will have the same problem if you do a lot of deploy and undeploy cycles using e. g. the admin GUI or asadmin CLI. It is a bug in GlassFish v2. To workaround it, stop and restart GlassFish between (and / or) after deploy and undeploy. Yes, it is annoying, but it helped in our case. In Eclipse, there can be another problem: If GlassFish is started in the same VM that also runs the IDE, then it might be the case that the IDE did not correctly release some files. We had a similar issue with Eclipse Europa. It just kept a lock on some JARs after creating it and we always had to shutdown the IDE to be able to modify the archive. In Eclipse Ganimede it was gone.

Regards
Markus

> -----Original Message-----
> From: glassfish@javadesktop.org [mailto:glassfish@javadesktop.org]
> Sent: Samstag, 27. Dezember 2008 03:36
> To: users@glassfish.dev.java.net
> Subject: Re: RE: Re: RE: ResourceAdapter (JCA) from EJB, in EAR
>
> Thanks again. I did not understand that you meant
> ClassNotFoundException when you meant could not be found. I thought you
> meant cannot be found in JNDI.
>
> I work from Eclipse and I think that Eclipse does not undeploy properly
> when you add and remove projects, because your workaround did not work
> there.
>
> But now I got it working! Thanks for your help!
> [Message sent by forum member 'jeltejansons' (jeltejansons)]
>
> http://forums.java.net/jive/thread.jspa?messageID=323372
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net