8 Replies Latest reply on Oct 26, 2011 4:52 AM by Daniel Rosowski

    Resource Adapter and consuming Servlet on AS7

    Fady Moussallam Newbie

      Hi there,

       

       

      I have a resource adapter and a servlet using it. They are bundled separately in a rar and a war They have been successfully tested on Glassfish 3.1.1 however I can't get them to deploy with JBoss AS 7.0.2.Final "Arc".

       

       

      The issue seems to be related to JNDI and Dependencies.

       

       

      This is the adapter config in standalone.xml:

       

       

                      <resource-adapter>

                          <archive>legstar.socket.connector-0.1.rar</archive>

                          <transaction-support>LocalTransaction</transaction-support>

                          <connection-definitions>

                              <connection-definition class-name="com.legsem.legstar.jca.socket.LegStarSocketManagedConnectionFactoryImpl" jndi-name="java:jboss/legstar.socket.connector" enabled="true" use-java-context="true" pool-name="LegStarConnectionPool" use-ccm="true">

                                  <config-property name="ServerName">mainframe</config-property>

                                  <pool>

                                      <max-pool-size>2</max-pool-size>

                                      <prefill>false</prefill>

                                      <use-strict-min>false</use-strict-min>

                                  </pool>

                              </connection-definition>

                          </connection-definitions>

                      </resource-adapter>

       

       

      The rar deploys fine and I can see the JNDI entry java:jboss/legstar.socket.connector using the administration console.

       

       

      The servlet's war however, fails to deploy.

       

       

      The servlet references the adapter using the following code:

       

       

          @Resource(name = "legstar.socket.connector", mappedName="java:jboss/legstar.socket.connector")

          private ConnectionFactory connectionFactory;

       

       

      The mappedName is something I had to add for JBoss because otherwise, I would systematically get this warning when deploying the war:

       

       

      13:10:04,659 WARN  [org.jboss.as.ee.component.deployers.ResourceInjectionAnnotationParsingProcessor] (MSC service thread 1-3) Can't handle @Resource for ENC name: java:jboss/legstar.socket.connector on class com.legsem.legstar.connector.it.web.ClientServlet since it's missing a "lookup" (or "mappedName") value and isn't of any known type

       

       

      With the mappedName, the warning goes away but I get a ClassNotFoundException on the first reference to a class from the Resource Adapter.

       

       

      I was assuming that the classpath for the servlet would include the resource adapter classes once the @Resource has been resolved. Is that the case or do I have to declare a dependency somewhere?

       

       

      Thanks for any help.

        • 1. Re: Resource Adapter and consuming Servlet on AS7
          Jesper Pedersen Master

          JCA fixes goes into the 7.1 series - so use a nightly snapshot or build master yourself.

          • 2. Re: Resource Adapter and consuming Servlet on AS7
            Carlo de Wolf Master

            Use the workaround as described in AS7-1282.

             

            Although the spec requires RARs to be exposed (EE.8.3.1 bullete 7) it is a major drawback in keeping a clean modularized setup. So I am not sure how the issue will play out. The workaround is the most clean solution. Although in this case we could also induce the dependency from the @Resource annotation.

            • 3. Re: Resource Adapter and consuming Servlet on AS7
              Fady Moussallam Newbie

              Thank you for your reply Jesper,

               

               

              I tried to get the nightly build according to http://community.jboss.org/thread/167590. The ci server seems unresponsive though. Is there a different URL I should use ?

               

               

              Otherwise I cloned the git repository but build fails on my machine, probably due to a windows issue:

              [ERROR] Failed to execute goal org.codehaus.mojo:javacc-maven-plugin:2.3-jboss-1:jjtree (jjtree-jbossql) on project jboss-as-cmp: Execution jjtree-jbossql of goal org.codehaus.mojo:javacc-maven-plugin:2.3-jboss-1:jjtree failed: basedir C:\Users\Fady\Workspace\jbossas\src\jboss-as\cmp\C:\Users\Fady\Workspace\jbossas\src\jboss-as\cmp\src\main\jjtree does not exist -> [Help 1]

              I'll try later on a unix box.

               

              Fady

              • 4. Re: Resource Adapter and consuming Servlet on AS7
                Fady Moussallam Newbie

                Carlo,

                 

                Adding the Dependencies to the war MANIFEST yields a different result:

                 

                Caused by: org.jboss.modules.ModuleNotFoundException: Module legstar.socket.connector-0.1:main is not found

                 

                        at org.jboss.modules.LocalModuleLoader.findModule(LocalModuleLoader.java:121)

                        at org.jboss.modules.ModuleLoader.loadModuleLocal(ModuleLoader.java:245)

                        at org.jboss.modules.ModuleLoader.preloadModule(ModuleLoader.java:194)

                        at org.jboss.modules.LocalModuleLoader.preloadModule(LocalModuleLoader.java:97)

                        at org.jboss.modules.ModuleLoader.loadModule(ModuleLoader.java:176)

                        at org.jboss.modules.Module.linkImports(Module.java:1041)

                        at org.jboss.modules.Module.relink(Module.java:1153)

                        at org.jboss.modules.ModuleLoader.relink(ModuleLoader.java:400)

                        at org.jboss.as.server.moduleservice.ServiceModuleLoader.relinkModule(ServiceModuleLoader.java:204) [jboss-as-server-7.0.2.Final.jar:7.0.2.Final]

                        at org.jboss.as.server.moduleservice.ModuleLoadService.start(ModuleLoadService.java:64) [jboss-as-server-7.0.2.Final.jar:7.0.2.Final]

                        ... 5 more

                 

                So I am missing the standalone rar module name.

                 

                The rar was deployed using a regular deploy command. Therefore it is not in $JBOSS_HOME/modules and it is not explicitly described as a module to JBoss (no jboss-deployment-structure.xml).

                 

                Is there a default module name that gets assigned to a rar when it is deployed this way? (maybe this is related to https://issues.jboss.org/browse/JBMETA-270)

                 

                Thanks again for your help.

                • 5. Re: Resource Adapter and consuming Servlet on AS7
                  Jesper Pedersen Master

                  It is best to fork the project on GitHub (or do a read-only copy) - follow: http://community.jboss.org/wiki/HackingonAS7

                  • 6. Re: Resource Adapter and consuming Servlet on AS7
                    Daniel Rosowski Newbie

                    Hi Fady,

                     

                    I'm experiencing the same problem (ClassNotFoundException) using JBoss 7.1 Alpha2. Did you manage to get it working somehow?

                     

                    Cheers,

                    Daniel

                    • 7. Re: Resource Adapter and consuming Servlet on AS7
                      Fady Moussallam Newbie

                      No, sorry Daniel,

                       

                      I was in a rush so I switched back to EAP5. I am still not sure how standalone RAR classes can be made visible under AS7.

                       

                      Carlo's suggestion seemed promising but I don't know how to create a module out of a standalone RAR.

                       

                      Fady

                      • 8. Re: Resource Adapter and consuming Servlet on AS7
                        Daniel Rosowski Newbie

                        I found a working (but rather cumbersome) solution to the dependency problem.

                         

                        1. Create a module containing only the jar (not the rar) which holds the classes of your resource adapter. The module.xml should look like the following:

                        <?xml version="1.0" encoding="UTF-8"?>

                         

                        <module xmlns="urn:jboss:module:1.0" name="com.mycom.connector.legacy">

                            <resources>

                                <resource-root path="legacy.jar"/>

                            </resources>

                           

                            <dependencies>

                                <module name="javax.api"/>

                                <module name="javax.resource.api"/>

                                ...

                            </dependencies>

                           

                        </module>

                         

                        2. Build your rar archive, but do not contain the jar archive (you provide the classes via the jboss module). Your rar archive needs to add a dependency in the manifest.mf like the following (I used maven for this):

                        Dependencies: com.mycom.connector.legacy, javax.resource.api

                         

                        3. Deploy your rar archive in standalone/deployments

                        4. Deploy your consuming app, in my case a web archive. The web archive needs the dependency to your jboss module too, otherwise it cannot find the class.

                         

                        And that should be it. Now I get another error, but I'll open up another thread for this one  :-)

                         

                        Cheers,

                        Daniel