You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by rherschke <to...@sonstiges.herschke.de> on 2014/11/26 12:17:33 UTC

Please provide a working example for configuring any kind of resource-adapters in tomee!

After several hours of trial-and-error and googling for any kind of at least
a little bit of documentation, I'm very disappointed of tomee!

The main problem is configuring a resource adapter. No! Not an ActiveMQ or a
Datasource or a Topic or  a Mail-Session... Just a plain JCA Resource
Adapter - either with CCI or with another ConnectionInterface...

So please provide a working example that will explain:

1. how to configure AdministeredObjects in the JNDI Namespace

In Glassfish one can use glassfish-resources.xml or the console to create
any instances of an AdministeredObject defined in a JCA RA. What is the
corresponding way in Tomee?

For example: The RA defines an Administered Object com.my.ra.MyAdminObject
with ConfigProperties a,b and c.

How do I add a global (for all Applications) instance of
com.my.ra.MyAdminObject with a = 1, b = 4 and c = 42 in the JNDI Namespace
at: java:global/env/MyAdminObjectOne

How do I ad another local (only for my WAR) instance of
com.my.ra.MyAdminObject with another configuration to
java:comp/env/MyAdminObjectTwo

--> in JEE 7 this can be done via:


How to do this in Tomee?

2. how to configure ConnectionFactory lookups in the JNDI Namespace

In Glassfish one can use glassfish-resources.xml or the console to create a
Connection Pool and the corresponding Connection and bind it to a JNDI name.

For example: The RA defines ManagedConnection, ManagedConnectionFactory and
a com.my.ra.MyConnectionFactory extends ConnectionFactory as well as
com.my.ra.MyConnection extends Connection and the corresponding Impls.

How do I specify, that any WAR can lookup this MyConnectionFactory via a
@Resource?
How do I bind MyConnectionFactoryImpl of the my-ra ResourceAdapter to a JNDI
name java:comp/env/eis/my-ra/MyConnection?
How do I specify Values for Config-Properties of the
ManagedConnectionFactory?

--> in JEE 7 there is:


How to do this in Tomee? 

3. (same as 2. but with CCI Implementations instead of MyConnectionFactory
interfaces)

Please provide an EXACT documentation of this kind of Resource-Adapter
configuration in https://tomee.apache.org/containers-and-resources.html. 

You could use http://connectorz.adam-bien.com as an example JCA RA.

Thanks,
Robert



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Please-provide-a-working-example-for-configuring-any-kind-of-resource-adapters-in-tomee-tp4673033.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Please provide a working example for configuring any kind of resource-adapters in tomee!

Posted by Romain Manni-Bucau <rm...@gmail.com>.
> Hi Romain,
>
> thanks for your help, but it won't work.
>
> For Example:
>
> I try to use the Files-Connector from Adam Bien
> (http://connectorz.adam-bien.com).
>
> - unpack the rar
> - add a ra.xml with:
>
>
>
> - repack the rar and deploy it to tomee, results in:
>
>
>
> - create a test.war application with a startup singleton:
>
>
>
> - deploy the test.war results in the following log:
>
>
>
> So as a resume:
>
> The RA is deployed and the ConnectionFactory (BucketStore) is created with
> id=filesCXF but this connection is not injected in the @Resource(name =
> "filesCXF") BucketStore store.
>
> While the Session-Context-Lookup returns an instance of FileBucketStore
> (which implements BucketStore), a cast to BucketStore fails. Which leads to
> classloader-problems.
>
> Both the files-connector.rar and the test.war contains the
> files-connector-api.jar. This API-Jar contains the BucketStore.class
> (Interface).
>
> This is really weird!
>

Not that much: api jar is not shared so you don't use the same class.
You can extract this api jar, put it in tomee and remove it from the
war and rar.

> Why Tomee does it in it's own way? Why isn't this documented? Why can't I
> define my own JNDI-Name for the connection to be looked up as I can do it in
> other Application Servers?
>

It is documented by JVM classloader behavior ;). About JNDI names I
guess that's just because we use id directly but using activemq
samples you can find anywhere you can surely do it using <Resource />
as I described before. In any case that's something not that hard to
enhance we'll tackle on the road to EE 7 in the worse case.

> Robert
>
>
>
>
>
> --
> View this message in context: http://tomee-openejb.979440.n4.nabble.com/Please-provide-a-working-example-for-configuring-any-kind-of-resource-adapters-in-tomee-tp4673033p4673048.html
> Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Please provide a working example for configuring any kind of resource-adapters in tomee!

Posted by Romain Manni-Bucau <rm...@gmail.com>.
You  an alread with jca 1.6 put a connector in a war like ejbs normally
Le 28 nov. 2014 08:52, "rherschke" <to...@sonstiges.herschke.de> a écrit :

> Hi Anthony,
>
> thanks for your reply.
>
> The problem isn't regarding the development of a JCA Resource Adapter, but
> about configuring and referencing it in Tomee.
>
> I see, the id-attributes in the ra.xml are neccessary to create the
> corresponding resources in the JNDI-Namespace.
>
> Next, I see, that there is an undocumented way to create Per-App-Instances
> of a Resource via <Resource ... class="..."> (rather than type="...", as
> documented at the Tomee Site).
>
> But without packaging both the WAR and the RAR in one EAR and deploying
> this
> EAR, a Resource Adapter that provides it's own Connection/ConnectionFactory
> Interfaces cannot be effectively used in Tomee due to classloading issues.
>
> Looking forward to Java EE 7 (with JCA 1.7) Support in Tomee soon, to get a
> clarified, streamlined and well documented, yet specified way to
> registering
> connections via @ConnectionFactoryDefinition and instances via
> @AdminObjectDefinition.
>
> As a sad conclusion: for me, there is no reason to use Tomee for
> Full-Profile-Enterprise-Apps, until Tomee supports JCA 1.7. Thats why, we
> consult our customers to go with Wildfly 8.x rather than with Tomee.
>
> Robert
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/Please-provide-a-working-example-for-configuring-any-kind-of-resource-adapters-in-tomee-tp4673033p4673068.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Re: Please provide a working example for configuring any kind of resource-adapters in tomee!

Posted by Anthony Fryer <ap...@hotmail.com>.
rherschke wrote
> The problem isn't regarding the development of a JCA Resource Adapter, but
> about configuring and referencing it in Tomee.
> 
> ...
> 
> I see, that there is an undocumented way to create Per-App-Instances of a
> Resource via 
> <Resource ... class="...">
>  (rather than type="...", as documented at the Tomee Site). 

You don't need to do any configuration in resources.xml for a connection
factory.  The standard ra.xml file is all you need.  If you have a war file,
then you can put the ra.xml in the WEB-INF folder (this is where tomee leads
the way by allowing packaging of resource adapters in war files).  If you
are packaging in a standard ear file, then you need a .rar file with the
ra.xml packaged up inside of that.  TomEE will create the resource and bind
it to JNDI using ra.xml.

To use a  jca connection factory from a managed bean (eg. an ejb), you can
get it using the @Resource annotation.  The normal rules regarding @Resource
apply.  You don't need to specify the name in the @Resource annotation if
the connection factory class is unique and tomee can resolve the dependency. 
The test case in the project i gave you a link to demonstrates how to inject
a connection factory.  That project wasn't about showing you how to develop
a resource adapter, it was more to demonstrate how a resource adapter is
instantiated and used from a test case.  The same technique applies in a
normal application.

I've found when i've had issues with tomee features, the community here is
very helpful.  If you can identify a defect or a place where tomee doesn't
properly implement the spec, then that will be immediately fixed.  I'm not
sure that is the case here.

Regards,

Anthony











--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Please-provide-a-working-example-for-configuring-any-kind-of-resource-adapters-in-tomee-tp4673033p4673075.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Please provide a working example for configuring any kind of resource-adapters in tomee!

Posted by rherschke <to...@sonstiges.herschke.de>.
Hi Anthony,

thanks for your reply.

The problem isn't regarding the development of a JCA Resource Adapter, but
about configuring and referencing it in Tomee.

I see, the id-attributes in the ra.xml are neccessary to create the
corresponding resources in the JNDI-Namespace.

Next, I see, that there is an undocumented way to create Per-App-Instances
of a Resource via <Resource ... class="..."> (rather than type="...", as
documented at the Tomee Site).

But without packaging both the WAR and the RAR in one EAR and deploying this
EAR, a Resource Adapter that provides it's own Connection/ConnectionFactory
Interfaces cannot be effectively used in Tomee due to classloading issues.

Looking forward to Java EE 7 (with JCA 1.7) Support in Tomee soon, to get a
clarified, streamlined and well documented, yet specified way to registering
connections via @ConnectionFactoryDefinition and instances via
@AdminObjectDefinition. 

As a sad conclusion: for me, there is no reason to use Tomee for
Full-Profile-Enterprise-Apps, until Tomee supports JCA 1.7. Thats why, we
consult our customers to go with Wildfly 8.x rather than with Tomee.

Robert



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Please-provide-a-working-example-for-configuring-any-kind-of-resource-adapters-in-tomee-tp4673033p4673068.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Please provide a working example for configuring any kind of resource-adapters in tomee!

Posted by Anthony Fryer <ap...@hotmail.com>.
I worked on a JCA adapter recently in tomee so know what you're going
through.

I created a very basic JCA skeleton project that contains a very simple jca
adapter and a single test case that loads the resource adapter in tomee and
injects the connection factory.  You can see this project here...

https://github.com/httpants/jcatest

Also some other threads discussing tomee and jca that might help...

http://openejb.979440.n4.nabble.com/openejb-not-destroying-ManagedConnections-on-shutdown-td4658799.html#a4658979

http://openejb.979440.n4.nabble.com/How-do-i-deploy-a-ManagedConnectionFactory-in-a-war-file-td4659993.html

One feature of tomee that no other container has is the ability to package a
rar in a war (non standard feature but extremely useful in some cases)! 
Other containers only support rar in ear. 



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Please-provide-a-working-example-for-configuring-any-kind-of-resource-adapters-in-tomee-tp4673033p4673064.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Please provide a working example for configuring any kind of resource-adapters in tomee!

Posted by rherschke <to...@sonstiges.herschke.de>.
Hi Romain,

thanks for your help, but it won't work.

For Example: 

I try to use the Files-Connector from Adam Bien
(http://connectorz.adam-bien.com). 

- unpack the rar
- add a ra.xml with:



- repack the rar and deploy it to tomee, results in:



- create a test.war application with a startup singleton:



- deploy the test.war results in the following log:



So as a resume: 

The RA is deployed and the ConnectionFactory (BucketStore) is created with
id=filesCXF but this connection is not injected in the @Resource(name =
"filesCXF") BucketStore store.

While the Session-Context-Lookup returns an instance of FileBucketStore
(which implements BucketStore), a cast to BucketStore fails. Which leads to
classloader-problems.

Both the files-connector.rar and the test.war contains the
files-connector-api.jar. This API-Jar contains the BucketStore.class
(Interface).

This is really weird!

Why Tomee does it in it's own way? Why isn't this documented? Why can't I
define my own JNDI-Name for the connection to be looked up as I can do it in
other Application Servers?

Robert





--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Please-provide-a-working-example-for-configuring-any-kind-of-resource-adapters-in-tomee-tp4673033p4673048.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Please provide a working example for configuring any kind of resource-adapters in tomee!

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

tomee has basically 2 kinds of resources: global and application ones.
Both use the same syntax but one in tomee.xml (global) the other in
WEB-INF/resources.xml (app).


Syntax is:

<Resource id="name" class-name="com.foo.MyImpl">
  a = 1
  b= 2
  c = value
</Resource>


It ends in openejb:Resource/name or java:openejb/Resource/name. You
can also use java:global/name if you need.

For JCA connectors normally once they are deployed (either from a war
or in the container) then you can access them from the name you have
in the logs with @Resource(name = "myconnectorRA") - this name is
logged at startup.


Romain Manni-Bucau
@rmannibucau
http://www.tomitribe.com
http://rmannibucau.wordpress.com
https://github.com/rmannibucau


2014-11-26 12:17 GMT+01:00 rherschke <to...@sonstiges.herschke.de>:
> After several hours of trial-and-error and googling for any kind of at least
> a little bit of documentation, I'm very disappointed of tomee!
>
> The main problem is configuring a resource adapter. No! Not an ActiveMQ or a
> Datasource or a Topic or  a Mail-Session... Just a plain JCA Resource
> Adapter - either with CCI or with another ConnectionInterface...
>
> So please provide a working example that will explain:
>
> 1. how to configure AdministeredObjects in the JNDI Namespace
>
> In Glassfish one can use glassfish-resources.xml or the console to create
> any instances of an AdministeredObject defined in a JCA RA. What is the
> corresponding way in Tomee?
>
> For example: The RA defines an Administered Object com.my.ra.MyAdminObject
> with ConfigProperties a,b and c.
>
> How do I add a global (for all Applications) instance of
> com.my.ra.MyAdminObject with a = 1, b = 4 and c = 42 in the JNDI Namespace
> at: java:global/env/MyAdminObjectOne
>
> How do I ad another local (only for my WAR) instance of
> com.my.ra.MyAdminObject with another configuration to
> java:comp/env/MyAdminObjectTwo
>
> --> in JEE 7 this can be done via:
>
>
> How to do this in Tomee?
>
> 2. how to configure ConnectionFactory lookups in the JNDI Namespace
>
> In Glassfish one can use glassfish-resources.xml or the console to create a
> Connection Pool and the corresponding Connection and bind it to a JNDI name.
>
> For example: The RA defines ManagedConnection, ManagedConnectionFactory and
> a com.my.ra.MyConnectionFactory extends ConnectionFactory as well as
> com.my.ra.MyConnection extends Connection and the corresponding Impls.
>
> How do I specify, that any WAR can lookup this MyConnectionFactory via a
> @Resource?
> How do I bind MyConnectionFactoryImpl of the my-ra ResourceAdapter to a JNDI
> name java:comp/env/eis/my-ra/MyConnection?
> How do I specify Values for Config-Properties of the
> ManagedConnectionFactory?
>
> --> in JEE 7 there is:
>
>
> How to do this in Tomee?
>
> 3. (same as 2. but with CCI Implementations instead of MyConnectionFactory
> interfaces)
>
> Please provide an EXACT documentation of this kind of Resource-Adapter
> configuration in https://tomee.apache.org/containers-and-resources.html.
>
> You could use http://connectorz.adam-bien.com as an example JCA RA.
>
> Thanks,
> Robert
>
>
>
> --
> View this message in context: http://tomee-openejb.979440.n4.nabble.com/Please-provide-a-working-example-for-configuring-any-kind-of-resource-adapters-in-tomee-tp4673033.html
> Sent from the TomEE Users mailing list archive at Nabble.com.