Working Example of Resource Adapter with Red Hat EAP 6.2 or 6.4

967 views
Skip to first unread message

P Esko

unread,
Oct 7, 2015, 3:56:15 AM10/7/15
to IronJacamar Users
Hello,

we have the task to migrate our applications from Red Hat JBoss EAP 5.1 to Red Hat EAP 6.2/6.4.
For 5.1 we developed several JCA Resource Adapters for handling connections to an outside system for our applications.

Now we have to migrate our sources to RH 6.x.
We already checked the available documentation and examples.
Unfortunately we can't get a function resource adapter working in RH EAP 6.2 or 6.4.

As first approach I generated a RAR with the codegenerator and deployed it as standard application within JB.
The RAR successfully deployed and could be activated.
Also the RAR registered itself within the JNDI naming.

For first tests I used a simple web service application, which tries to get an instance of the ManagedConnectionFactory.
When I call my web service which tries to get a connection I get the following Exception:

###########
09:46:37,043 ERROR [org.jboss.as.webservices.invocation.InvocationHandlerJAXWS] (http-/127.0.0.1:8080-1) JBAS015594: Method invocation failed with exception: com/irrp/jca/cme/ws/MyConnectionFactory: java.lang.NoClassDefFoundError: com/irrp/jca/cme/ws/MyConnectionFactory
###########

I also tried to register the RAR as module, but when I start the JBoss instance, I get a simple message, that the module can't be loaded.
For information, I know how to register a module in JB 6.x, as I already did for an oracle JDBC driver, which works fine for a database datasource.

I tried to register the RAR file as module and also the unpacked RAR. No chance!
I tried the also all interface version from 1.0 to 1.6 with the codegenerator.

The only thing I successfully could use is a rescource adapter which is based on definition 1.0 and implementing the CCI interface. But I think this isn't the way we can go.

My question here:
Has somebody a full working example of a resource adapter inluding all deployment descriptors for RH EAP 6.x?

Best Regards
Peter

P Esko

unread,
Oct 7, 2015, 7:48:58 AM10/7/15
to IronJacamar Users

Problem solved!

For all who run into the same problems, here's my solution:

1) Download the IronJacamar package (for me it was 'IronJacamar 1.2.6.Final released').
2) Run the 'codegenerator.bat'. Here are my input values:

Profile version (1.7/1.6/1.5/1.0) [1.7]: 1.5
Type (O/Outbound/I/Inbound/B/Bidirectional) [O]:
Package name: com.jca.myadapter
Transaction support (N/NoTransaction/L/LocalTransaction/X/XATransaction) [N]:
Reauthentication (Y/Yes/N/No) [N]:
Include a ResourceAdapter (Y/Yes/N/No) [Y]:
Resource adapter class name [AcmeResourceAdapter]: MyResourceAdapter
Should the resource adapter class be Serializable (Y/Yes/N/No) [Y]:
Resource adapter config properties [enter to quit]:
    Name:
Managed connection factory class name [MyManagedConnectionFactory]:
Managed connection factory config properties [enter to quit]:
    Name:
Use ResourceAdapterAssociation (Y/Yes/N/No) [Y]:
Managed connection class name [MyManagedConnection]:
Use CCI (Y/Yes/N/No) [N]:
Connection factory interface class name [MyConnectionFactory]:
Connection factory implementation class name [MyConnectionFactoryImpl]:
Connection interface class name [MyConnection]:
Connection implementation class name [MyConnectionImpl]:
Add methods to connection interface (Y/Yes/N/No) [N]: Y
    Method name [enter to quit]: getHelloWorld
    Return type: String
    Parameter name [enter to quit]:
    Exception type:
    Method name [enter to quit]:
Additional managed connection factory (Y/Yes/N/No) [N]:
Include an admin object (Y/Yes/N/No) [N]:
Generate a MBean class (Y/Yes/N/No) [Y]: N
Integrate EIS test server (Y/Yes/N/No) [N]:
Use JBoss Logging  (Y/Yes/N/No) [N]: Y
Build environment [A/Ant/I/Ant+Ivy/M/Maven/G/Gradle] [A]:
Code generated

3) Step into the 'out' directory and edit 'MyManagedConnection.java' to add some output to the method 'getHelloWorld()':

   String getHelloWorld()
   {
      log.trace("getHelloWorld()");

      return "Hello World from My JCA Resource Adapter!";
   }

4) Run ant within the 'out' directory to build the classfiles and the RAR

5) Step into your <jboss_home>/modules directory and create beneeth the following path: com/jca/myadapter/main, so your path should like this '<jboss_home>/modules/com/jca/myadapter/main'

6) Copy the file 'myadapter.rar' from out/target of the codegenerator to '<jboss_home>/modules/com/jca/myadapter/main'

7) Unpack the RAR on the same level! So the myadapter.jar and META-INF should appear within '<jboss_home>/modules/com/jca/myadapter/main'.
You may remove the myadapter.rar.

8) Within '<jboss_home>/modules/com/jca/myadapter/main' create a file named 'module.xml' with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.jca.myadapter">
  <resources>
    <resource-root path="."/>
    <resource-root path="myadapter.jar"/>
  </resources>
  <dependencies>
        <module name="javax.api"/>
        <module name="javax.resource.api"/>
        <module name="org.jboss.logging"/>
    </dependencies>
</module>

9) NOTE: This entry in module.xml is very important:     <resource-root path="."/>

10) Open the file 'standard.xml' from <jboss_home>/standalone/configuration'

11) Introduce your resource adapter as global module:

        <subsystem xmlns="urn:jboss:domain:ee:1.2">
            <global-modules>
                <module name="com.jca.myadapter" slot="main"/>
            </global-modules>

            <ear-subdeployments-isolated>false</ear-subdeployments-isolated>
            <spec-descriptor-property-replacement>false</spec-descriptor-property-replacement>
            <jboss-descriptor-property-replacement>true</jboss-descriptor-property-replacement>
            <annotation-property-replacement>false</annotation-property-replacement>
        </subsystem>

12) Add also a resource adapter definition in 'standalone.xml':

        <subsystem xmlns="urn:jboss:domain:resource-adapters:1.1">
            <resource-adapters>
                <resource-adapter id="MyResourceAdapter">
                    <module slot="main" id="com.jca.myadapter"/>
                    <transaction-support>NoTransaction</transaction-support>
                    <connection-definitions>
                        <connection-definition class-name="com.jca.myadapter.MyManagedConnectionFactory" jndi-name="java:/eis/MyConnectionFactory" enabled="true" pool-name="MyAdapter">
                            <security>
                                <application/>
                            </security>
                            <validation>
                                <background-validation>false</background-validation>
                            </validation>
                        </connection-definition>
                    </connection-definitions>
                </resource-adapter>
            </resource-adapters>
        </subsystem>
...

13) Start your JBoss instance and check, whether the adapter was registered as module:

13:13:58,108 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-2) JBWEB003000: Coyote HTTP/1.1 starting on: http-/127.0.0.1:8080
13:13:58,264 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-3) JBAS010406: Registered connection factory java:/eis/MyConnectionFactory
13:13:58,280 INFO  [org.jboss.as.connector.deployers.RaXmlDeployer] (MSC service thread 1-3) IJ020002: Deployed: file:/E:/JBoss/jboss-eap-6.4.0/jboss-eap-6.4/modules/com/jca/myadapter/main/
13:13:58,295 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-3) JBAS010401: Bound JCA ConnectionFactory [java:/eis/MyConnectionFactory]

14) Now you can create your own EAR accessing the resource adapter. Add the 'myadapter.jar' to your library path of your project.

15) add the following imports to your project:

import com.jca.myadapter.MyConnection;
import com.jca.myadapter.MyConnectionFactory;

16) add the follwoing code to test the adapter:

       try {
           
            log.debug("--- before InitialContext ---");
            InitialContext ctx = new InitialContext();
           
            log.debug("--- before (MyConnectionFactory) ctx.lookup ---");
            MyConnectionFactory mycf = (MyConnectionFactory) ctx.lookup("java:/eis/MyConnectionFactory");
           
            log.debug("--- before mycf.getConnection() ---");
            MyConnection myConnection = (MyConnection)mycf.getConnection();
           
            log.debug("--- before myConnection.getHelloWorld() ---");
            strWorld = myConnection.getHelloWorld();
           
            log.debug("From myConnection: " + strWorld);
           
            log.debug("--- before myConnection.close() ---");
            myConnection.close();
          
            log.debug("--- DONE! ---");
           
        } catch (Exception ex) {
           
            log.debug("################## START EXCEPTION ##############################");
            log.debug(ex.getMessage());
            log.debug("################## END EXCEPTION ##############################");

        }


I hope I can help with this steps anyone who has the same troubles.
Best Regards
Peter



Robert Corcoran

unread,
Nov 30, 2015, 10:26:17 AM11/30/15
to IronJacamar Users
Thanks Peter. We are also migrating an enterprise web application from JBoss 5.2 to JBoss 6.3. This post really helped us.

Thanks again,
 Bob
Reply all
Reply to author
Forward
0 new messages