You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by Fredrik Jonson <fr...@myrealbox.com> on 2009/01/21 16:44:54 UTC

How do I declare and inject a jms resource in a connector component?

Hi, 

I have a ear that contains a rar with a ResourceAdapter. In my
resource adapter I need to use the jms resources that I've declared
in geronimo-application.xml - a activemq connection factory and
a queue. 

I've tried to inject with annotations:

 public class FooAdapter implements ResourceAdapter
 {
    @Resource(name = "ConnectionFactory")
    private javax.jms.ConnectionFactory connectionFactory;
    @Resource(name = "foo.gateway")
    private Queue gatewayQueue;

    ...

But when I do that my adapter just hangs on the call to:

    Connection c = connectionFactory.createConnection();

I also tried jndi lookup, and it fails too, so I suspect that I need
to declare that the rar component has a dependency on the jms-resources
that I have declared in geronimo-application.xml?

The thing is, I do not see any exceptions when I deploy the jca component,
and geronimo seems to inject something. Otherwise I'd expect a nullpointer
exception on deployment.

Anyway, I'd be greatful for any help here.

Below is my geronimo-ra.xml (the ra.xml is as minimal):

<?xml version="1.0" encoding="UTF-8"?>
<connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2">
  <dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2">
    <dep:moduleId>
      <dep:groupId>foo</dep:groupId>
      <dep:artifactId>foo-connector</dep:artifactId>
      <dep:version>1.0.0</dep:version>
      <dep:type>rar</dep:type>
    </dep:moduleId>
  </dep:environment>
  <resourceadapter>
    <resourceadapter-instance>
      <resourceadapter-name>foo.FooAdapter</resourceadapter-name>
      <workmanager>
        <gbean-link>DefaultWorkManager</gbean-link>
      </workmanager>
    </resourceadapter-instance>
  </resourceadapter>
</connector>

-- 
Fredrik Jonson


Re: How do I declare and inject a jms resource in a connector component?

Posted by Fredrik Jonson <fr...@myrealbox.com>.
In <A3...@yahoo.com> David Jencks wrote:

>  Right, connnectors don't support annotations at all. Annotations only  
>  work in web apps, ejbs, and javaee app clients.

Ah, figures. Guess I've been spoiled by various ioc frameworks...

After posting I looked a bit deeper and used initialContext.list(name)
to explore the context. There I found the 'jca:' namespace, where I my
application's connection factory was available as:

 "jca:/org.foo/foo-ear/JCAManagedConnectionFactory/ConnectionFactory"

That at least seems to give me a way forward in Geronimo. Remains to
see how it pans out of for other app servers, like glassfish, though.

>  Note also that connectors don't have a configurable java:comp/env  
>  naming context: they'll get the java:comp/env context of whatever  
>  happens to be calling the connector object.

Good to know.

Thank you David! You deserve a world of credits for your help to us
newbies that are stumbling around here on the user's list.

-- 
Fredrik Jonson


Re: How do I declare and inject a jms resource in a connector component?

Posted by David Jencks <da...@yahoo.com>.
On Jan 21, 2009, at 8:13 AM, Fredrik Jonson wrote:

> In <sl...@scout.jonson.org> Fredrik Jonson wrote:
>
>> The thing is, I do not see any exceptions when I deploy the jca  
>> component,
>> and geronimo seems to inject something. Otherwise I'd expect a  
>> nullpointer
>> exception on deployment.
>
> Oups, that is not correct. I got a nullpointer, but it was swallowed  
> by the
> work manager, so it didn't show up in the log file.
>
> So, the @Resource injection of the jms resources clearly does not  
> work in
> my connector component.

Right, connnectors don't support annotations at all.  Annotations only  
work in web apps, ejbs, and javaee app clients.

Note also that connectors don't have a configurable java:comp/env  
naming context: they'll get the java:comp/env context of whatever  
happens to be calling the connector object.  So if you want to use  
jndi in an app-independent way you'll have to make sure your jca stuff  
is bound in global jndi under known names and look it up using those  
names.  These global jndi names will be specific to a particular app  
server (at least).  You might be able to configure them using config- 
properties.

thanks
david jencks

>
>
> -- 
> Fredrik Jonson
>


Re: How do I declare and inject a jms resource in a connector component?

Posted by Fredrik Jonson <fr...@myrealbox.com>.
In <sl...@scout.jonson.org> Fredrik Jonson wrote:
 
>  The thing is, I do not see any exceptions when I deploy the jca component,
>  and geronimo seems to inject something. Otherwise I'd expect a nullpointer
>  exception on deployment.

Oups, that is not correct. I got a nullpointer, but it was swallowed by the
work manager, so it didn't show up in the log file.

So, the @Resource injection of the jms resources clearly does not work in
my connector component.

-- 
Fredrik Jonson