users@glassfish.java.net

Re: Inbound JCA Resource Adapter example

From: Ed Hillmann <ed.hillmann_at_gmail.com>
Date: Thu, 14 Aug 2008 08:34:52 +1000

On Wed, Aug 13, 2008 at 5:17 PM, <glassfish_at_javadesktop.org> wrote:
> Hi all,
> I'm looking for the example of Inbound JCA Resource Adapter compliant to JCA 1.5 spec.
> So it would be possible to deploy it into Glassfish.
>
> How does JCA RA become aware of EJBs subscribed to this JCA RA?
> The parameters MessageEndpointFactory and ActivationSpec don't give any clue to EJBs.
> [Message sent by forum member 'neighbour' (neighbour)]
>

This has worked for me in the past. The RA has the following
definition in the ra.xml file..

        <inbound-resourceadapter>
            <messageadapter>
                <messagelistener>

<messagelistener-type>com.ib.connector.TreEventListener</messagelistener-type>
                    <activationspec>

<activationspec-class>com.ib.connector.TreEventActivationSpec</activationspec-class>
                        <required-config-property>

<config-property-name>ServerName</config-property-name>
                        </required-config-property>
                        <required-config-property>

<config-property-name>PortNumber</config-property-name>
                        </required-config-property>
                        <required-config-property>

<config-property-name>UserName</config-property-name>
                        </required-config-property>
                        <required-config-property>

<config-property-name>Password</config-property-name>
                        </required-config-property>
                        <required-config-property>

<config-property-name>EventPatterns</config-property-name>
                        </required-config-property>
                    </activationspec>
                </messagelistener>
... additional <messagelistener> entries for each supported inbound interface
        </inbound-resourceadapter>

So, the messagelistener-type defines the interface the RA will be
expecting the endpoint to be implementing. It also defines the
activationSpec.

As previously replied, the RA doesn't know anything about the EJB's
that are being called. It has the MessageEndpointFactory, which
creates the MessageEndpoint instances. It is these MessageEndpoints
that must implement the interface defined in <messagelistener-type>

From an application wanting to receive events, I've used Java
Annotations to define a Message-Driven Bean...

@MessageDriven(
    name="TreEventBean",
    messageListenerInterface=TreEventListener.class,
    activationConfig={
        @ActivationConfigProperty(propertyName="ServerName",propertyValue="wallaby"),
        @ActivationConfigProperty(propertyName="PortNumber",propertyValue="10551"),
        @ActivationConfigProperty(propertyName="UserName",propertyValue="tpsysadm"),
        @ActivationConfigProperty(propertyName="Password",propertyValue="tpsysadm"),
        @ActivationConfigProperty(propertyName="EventPatterns",propertyValue="myPattern")
    }
)
public class TreEventBean implements TreEventListener {

    /**
     * Method that will be called by the inbound Tre Event handler
     */
    public void handleEvent(String eventName, List paramList) throws
ResourceException {
        System.out.println("In MDB: " + eventName + " with params " +
paramList.toString());
    }

}

And, to get this running in Glassfish, I needed to add the following
to the sun-ejb-jar.xml file

<sun-ejb-jar>
    <enterprise-beans>
        <ejb>
            <ejb-name>TreEventBean</ejb-name>
            <mdb-resource-adapter>
                <resource-adapter-mid>svConnector</resource-adapter-mid>
            </mdb-resource-adapter>
        </ejb>
    </enterprise-beans>
</sun-ejb-jar>

This allows the Glassfish container to find the resource adapter in
which the messageListenerInterface exists.

Hope this helps,
Ed