0

I'm attempting to setup a JCA resource adapter for Gemfire 9.8 on IBM WebSphere Liberty base by following the link https://gemfire.docs.pivotal.io/98/geode/reference/archive_transactions/JTA_transactions.html#concept_cp1_zx1_wk

Here is my ra.xml:

<connector xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd"
version="1.5">

<display-name>GFE JCA Adaptor</display-name>
<vendor-name></vendor-name>
<spec-version>1.5</spec-version>
<eis-type>GFE JCA</eis-type>
<version>1.5</version>
<resourceadapter>
    <config-property>
        <config-property-name>ProductName</config-property-name>
        <config-property-type>java.lang.String</config-property-type>
        <config-property-value>GemFire</config-property-value>
    </config-property>
    <config-property>
        <config-property-name>UserName</config-property-name>
        <config-property-type>java.lang.String</config-property-type>
        <config-property-value/>
    </config-property>
    <config-property>
        <config-property-name>Version</config-property-name>
        <config-property-type>java.lang.String</config-property-type>
        <config-property-value>8.0</config-property-value>
    </config-property>

    <outbound-resourceadapter>
        <connection-definition>
            <managedconnectionfactory-class>org.apache.geode.internal.ra.spi.JCAManagedConnectionFactory</managedconnectionfactory-class>
            <connectionfactory-interface>org.apache.geode.ra.GFConnectionFactory</connectionfactory-interface>
            <connectionfactory-impl-class>org.apache.geode.internal.ra.GFConnectionFactoryImpl</connectionfactory-impl-class>
            <connection-interface>org.apache.geode.ra.GFConnection</connection-interface>
            <connection-impl-class>org.apache.geode.internal.ra.GFConnectionImpl</connection-impl-class>
            <transaction-support>LocalTransaction</transaction-support>
            <reauthentication-support>false</reauthentication-support>
        </connection-definition>
    </outbound-resourceadapter>
</resourceadapter>

And here is my resource adapter setting:

<library id="gemfireRaLib" apiTypeVisibility="spec, ibm-api, stable, third-party, api">
  <fileset dir="path/to/geode-lib" includes="geode-dependencies.jar"/>
</library> 

<resourceAdapter id="gemfireJCA" location="/path/to/geode-lib/geode-jca-9.8.3.rar">
    <classloader apiTypeVisibility="spec, ibm-api, stable, third-party, api" commonLibraryRef="gemfireRaLib" delegation="parentFirst"/>
</resourceAdapter>

When I start my liberty server, spring boot initialization fails saying ClassNotFoundException org.apache.geode.ra.GFConnectionFactory is not found.

Then I put all geode dependencies as a shared library:

<library id="gemfireRaLib" apiTypeVisibility="spec, ibm-api, stable, third-party, api">
  <fileset dir="/path/to/geode-lib" includes="geode-dependencies.jar"/>
  <fileset dir="/path/to/geode-lib" includes="*.jar"/>
</library> 

<resourceAdapter id="gemfireJCA" location="/path/to/geode-jca-9.8.3.rar">
    <classloader apiTypeVisibility="spec, ibm-api, stable, third-party, api" commonLibraryRef="gemfireRaLib" delegation="parentFirst"/>
</resourceAdapter>

and

<webApplication contextRoot="apprRoot13" location="/path/to/mylocation.war" name="App13" id="App13">
    <classloader apiTypeVisibility="spec, ibm-api, stable, third-party, api" commonProviderRef="gemfireRaLib" delegation="parentFirst" />
</webApplication>

Error:

spring-data-gemfire initialization fails:
AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [applicationContext-gemfire.xml]; nested exception is java.lang.NoClassDefFoundError: org.apache.geode.cache.PartitionResolver

In all above scenario I get gemfireJCA adapter installed successfully.

Update 1

/path/to/shared/geode-lib/ contains the following jars:

geode-common-9.8.3.jar geode-cq-9.8.3.jar geode-jca-9.8.3.rar geode-management-9.8.3.jar geode-core-9.8.3.jar geode-dependencies.jar geode-lucene-9.8.3.jar geode-wan-9.8.3.jar

When I pack them inside WAR the application bootsup but fails at

lookup = (GFConnectionFactory) template.lookup("gfe/jca");

saying:

java.lang.ClassCastException: org.apache.geode.internal.ra.GFConnectionFactoryImpl incompatible with org.apache.geode.ra.GFConnectionFactory

I get java.lang.ClassCastException: org.apache.geode.internal.ra.GFConnectionFactoryImpl incompatible with org.apache.geode.ra.GFConnectionFactory because GFConnectionFactoryImpl and GFConnectionFactory are loaded by different classloaders. Thats why I created a geode-lib shared library. Sharing it between JCA resource adapter and web application

halfer
  • 19,824
  • 17
  • 99
  • 186
Gokul
  • 13
  • 6
  • 1
    I've not tried this, but assuming you want to use the classes in the RA in your application you need to set the webApplication/classloader classProviderRef attribute to reference the resource adapter. So this: – Alasdair Mar 31 '20 at 18:29
  • thanks, but when I do that, I get the following error java.lang.ClassCastException: org.apache.geode.internal.ra.GFConnectionFactoryImpl incompatible with org.apache.geode.ra.GFConnectionFactory It is GFConnectionFactoryImpl from JCA classloader cannot be converted into GFConnectionFactory of Webapplication. Classloader delegation is parentFirst. – Gokul Apr 02 '20 at 02:54

3 Answers3

0

What is causing the NoClassDefFoundError?

nested exception is java.lang.NoClassDefFoundError: org.apache.geode.cache.PartitionResolver

Seems like your Spring (Data GemFire) based Web Application does not have all the required dependencies in the deployed artifact (WAR??)?

Regarding org.apache.geode.ra.GFConnectionFactory, that class is in io.pivotal.gemfire:geode-core:9.8.7.

In the WAS Liberty descriptor definition:

<library id="gemfireRaLib" apiTypeVisibility="spec, ibm-api, stable, third-party, api">
  <fileset dir="/path/to/shared/geode-lib" includes="geode-dependencies.jar"/>
  <fileset dir="/path/to/shared/geode-lib" includes="*.jar"/>
</library> 

I do not think this is correct:

<fileset dir="/path/to/geode-lib" includes="geode-dependencies.jar"/>

By way of example, Pivotal GemFire 9.8 is based on Apache Geode 1.9. So, I will use the Apache Geode 1.9 distribution to demonstrate.

$ cd apache-geode-1.9.2/
jblum-mbpro-2:apache-geode-1.9.2 jblum$ $ jar -tvf lib/geode-dependencies.jar 
     0 Tue Oct 15 06:08:24 PDT 2019 META-INF/
  2250 Tue Oct 15 06:08:24 PDT 2019 META-INF/MANIFEST.MF
 19957 Tue Oct 15 06:05:14 PDT 2019 META-INF/LICENSE
   575 Tue Oct 15 06:05:14 PDT 2019 META-INF/NOTICE

Are you aware that the geode-dependencies.jar is a Manifest-only JAR file?

Manifest-only JARs are a convenient means to refer to other JARs that are required in your application classpath so you do not need to list all the required JARs independently, such as...

$ java -classpath /path/to/A.jar;/path/to/B.jar;...;/path/to/N.jar

Manifest-only JARs DO NOT CONTAIN any class files or other resources, as you can see above, other than a Manifest file.

A Manifest-only JARs contain a META-INF/MANIFEST.MF with the Class-Path attribute set to the required JARs. The "required JARs" are relative to the Manifest-only JAR (e.g. geode-dependecies.jar).

Since the geode-dependencies.jar is contained in ~/apache-geode-1.9.2/lib, then only JARs in the ~/apache-geode-1.9.2/lib directory are resolvable:

$ ll lib/
total 133376
-rw-r--r--@ 1 jblum  staff    114165 Jun 13  2019 HdrHistogram-2.1.9.jar
-rw-r--r--@ 1 jblum  staff    143577 Jul 17  2019 HikariCP-3.2.0.jar
-rw-r--r--@ 1 jblum  staff     29779 Jun 13  2019 LatencyUtils-2.0.3.jar
-rw-r--r--@ 1 jblum  staff    445288 Feb  6  2019 antlr-2.7.7.jar
-rw-r--r--@ 1 jblum  staff    346684 Feb  6  2019 classgraph-4.0.6.jar
-rw-r--r--@ 1 jblum  staff    246174 Feb  6  2019 commons-beanutils-1.9.3.jar
-rw-r--r--@ 1 jblum  staff    284184 Feb  6  2019 commons-codec-1.10.jar
-rw-r--r--@ 1 jblum  staff    588337 Feb  6  2019 commons-collections-3.2.2.jar
-rw-r--r--@ 1 jblum  staff    196768 Feb  6  2019 commons-digester-2.1.jar
-rw-r--r--@ 1 jblum  staff    214788 Feb  6  2019 commons-io-2.6.jar
-rw-r--r--@ 1 jblum  staff    501879 Feb  6  2019 commons-lang3-3.8.1.jar
-rw-r--r--@ 1 jblum  staff     61829 Feb  6  2019 commons-logging-1.2.jar
-rw-r--r--@ 1 jblum  staff   1692782 Aug 21  2019 commons-math3-3.2.jar
-rw-r--r--@ 1 jblum  staff    112005 Aug 21  2019 commons-modeler-2.0.1.jar
-rw-r--r--@ 1 jblum  staff    186077 Feb  6  2019 commons-validator-1.6.jar
-rw-r--r--@ 1 jblum  staff  18800316 Jun 13  2019 fastutil-8.2.2.jar
-rw-r--r--@ 1 jblum  staff     15322 Feb  6  2019 findbugs-annotations-1.3.9-1.jar
-rw-r--r--@ 1 jblum  staff     23712 Aug 21  2019 geo-0.7.1.jar
-rw-r--r--@ 1 jblum  staff     12987 Oct 15 06:07 geode-common-1.9.2.jar
-rw-r--r--@ 1 jblum  staff    130813 Oct 15 06:08 geode-connectors-1.9.2.jar
-rw-r--r--@ 1 jblum  staff  12280133 Oct 15 06:08 geode-core-1.9.2.jar
-rw-r--r--@ 1 jblum  staff     96220 Oct 15 06:08 geode-cq-1.9.2.jar
-rw-r--r--@ 1 jblum  staff      8200 Oct 15 06:08 geode-dependencies.jar
-rw-r--r--@ 1 jblum  staff     24431 Oct 15 06:08 geode-jca-1.9.2.rar
-rw-r--r--@ 1 jblum  staff    220612 Oct 15 06:08 geode-lucene-1.9.2.jar
-rw-r--r--@ 1 jblum  staff    103539 Oct 15 06:07 geode-management-1.9.2.jar
-rw-r--r--@ 1 jblum  staff     14225 Oct 15 06:08 geode-old-client-support-1.9.2.jar
-rw-r--r--@ 1 jblum  staff    110608 Oct 15 06:08 geode-protobuf-1.9.2.jar
-rw-r--r--@ 1 jblum  staff    607104 Oct 15 06:07 geode-protobuf-messages-1.9.2.jar
-rw-r--r--@ 1 jblum  staff     22805 Oct 15 06:08 geode-rebalancer-1.9.2.jar
-rw-r--r--@ 1 jblum  staff    516805 Oct 15 06:08 geode-redis-1.9.2.jar
-rw-r--r--@ 1 jblum  staff     87754 Oct 15 06:08 geode-wan-1.9.2.jar
-rw-r--r--@ 1 jblum  staff     41262 Oct 15 06:08 geode-web-1.9.2.jar
-rw-r--r--@ 1 jblum  staff      8236 Oct 15 06:08 gfsh-dependencies.jar
-rw-r--r--@ 1 jblum  staff      9902 Aug 21  2019 grumpy-core-0.2.2.jar
-rw-r--r--@ 1 jblum  staff    767140 Jun 13  2019 httpclient-4.5.6.jar
-rw-r--r--@ 1 jblum  staff    326356 Jun 13  2019 httpcore-4.4.10.jar
-rw-r--r--@ 1 jblum  staff     20024 Jun 13  2019 istack-commons-runtime-2.2.jar
-rw-r--r--@ 1 jblum  staff     66894 May 13  2019 jackson-annotations-2.9.8.jar
-rw-r--r--@ 1 jblum  staff    325619 Feb  6  2019 jackson-core-2.9.8.jar
-rw-r--r--@ 1 jblum  staff   1347236 Feb  6  2019 jackson-databind-2.9.8.jar
-rw-r--r--@ 1 jblum  staff    283858 Aug 21  2019 jansi-1.17.1.jar
-rw-r--r--@ 1 jblum  staff     78030 Jun 13  2019 javax.activation-1.2.0.jar
-rw-r--r--@ 1 jblum  staff     56674 Jun 13  2019 javax.activation-api-1.2.0.jar
-rw-r--r--@ 1 jblum  staff    219146 Aug 21  2019 javax.mail-api-1.6.2.jar
-rw-r--r--@ 1 jblum  staff     69900 Jun 13  2019 javax.resource-api-1.7.1.jar
-rw-r--r--@ 1 jblum  staff     95806 May 13  2019 javax.servlet-api-3.1.0.jar
-rw-r--r--@ 1 jblum  staff     28016 Jun  7  2019 javax.transaction-api-1.3.jar
-rw-r--r--@ 1 jblum  staff    128076 Jun 13  2019 jaxb-api-2.3.1.jar
-rw-r--r--@ 1 jblum  staff   1099204 Jun 13  2019 jaxb-impl-2.3.1.jar
-rw-r--r--@ 1 jblum  staff    195664 Jul 16  2019 jetty-http-9.4.12.v20180830.jar
-rw-r--r--@ 1 jblum  staff    139436 Jun 13  2019 jetty-io-9.4.12.v20180830.jar
-rw-r--r--@ 1 jblum  staff     93077 Jul 16  2019 jetty-security-9.4.12.v20180830.jar
-rw-r--r--@ 1 jblum  staff    609290 Jun 13  2019 jetty-server-9.4.12.v20180830.jar
-rw-r--r--@ 1 jblum  staff    110983 Oct  7 15:01 jetty-servlet-9.4.12.v20180830.jar
-rw-r--r--@ 1 jblum  staff    502985 Jun 13  2019 jetty-util-9.4.12.v20180830.jar
-rw-r--r--@ 1 jblum  staff    128579 Jul 16  2019 jetty-webapp-9.4.12.v20180830.jar
-rw-r--r--@ 1 jblum  staff     52044 Jul 16  2019 jetty-xml-9.4.12.v20180830.jar
-rw-r--r--@ 1 jblum  staff   2512913 Feb  6  2019 jgroups-3.6.14.Final.jar
-rw-r--r--@ 1 jblum  staff    213854 Feb  6  2019 jline-2.12.jar
-rw-r--r--@ 1 jblum  staff    914597 Feb  6  2019 jna-4.1.0.jar
-rw-r--r--@ 1 jblum  staff     78146 Feb  6  2019 jopt-simple-5.0.4.jar
-rw-r--r--@ 1 jblum  staff    264060 Jul  3  2019 log4j-api-2.11.1.jar
-rw-r--r--@ 1 jblum  staff   1607947 Aug  8  2019 log4j-core-2.11.1.jar
-rw-r--r--@ 1 jblum  staff     12664 Aug 21  2019 log4j-jcl-2.11.1.jar
-rw-r--r--@ 1 jblum  staff     23999 Sep  3  2019 log4j-jul-2.11.1.jar
-rw-r--r--@ 1 jblum  staff     23241 Aug 20  2019 log4j-slf4j-impl-2.11.1.jar
-rw-r--r--@ 1 jblum  staff   1513791 Feb  6  2019 lucene-analyzers-common-6.6.2.jar
-rw-r--r--@ 1 jblum  staff     26142 Feb  6  2019 lucene-analyzers-phonetic-6.6.2.jar
-rw-r--r--@ 1 jblum  staff   2783525 Feb  6  2019 lucene-core-6.6.2.jar
-rw-r--r--@ 1 jblum  staff    237891 Feb  6  2019 lucene-queries-6.6.2.jar
-rw-r--r--@ 1 jblum  staff    405545 Feb  6  2019 lucene-queryparser-6.6.2.jar
-rw-r--r--@ 1 jblum  staff    422554 Jun 13  2019 micrometer-core-1.1.3.jar
-rw-r--r--@ 1 jblum  staff    409467 Feb  6  2019 mx4j-3.0.2.jar
-rw-r--r--@ 1 jblum  staff    172221 Aug 21  2019 mx4j-remote-3.0.2.jar
-rw-r--r--@ 1 jblum  staff    497017 Aug 21  2019 mx4j-tools-3.0.1.jar
-rw-r--r--@ 1 jblum  staff   3905888 Aug 21  2019 netty-all-4.1.31.Final.jar
-rw-r--r--@ 1 jblum  staff   1421323 Aug 21  2019 protobuf-java-3.6.1.jar
-rw-r--r--@ 1 jblum  staff     17522 Oct 15 06:08 ra.jar
-rw-r--r--@ 1 jblum  staff    110848 Feb  6  2019 rmiio-2.1.2.jar
-rw-r--r--@ 1 jblum  staff     13601 Feb  6  2019 shiro-cache-1.4.0.jar
-rw-r--r--@ 1 jblum  staff     18037 Feb  6  2019 shiro-config-core-1.4.0.jar
-rw-r--r--@ 1 jblum  staff     43303 Feb  6  2019 shiro-config-ogdl-1.4.0.jar
-rw-r--r--@ 1 jblum  staff    410541 Feb  6  2019 shiro-core-1.4.0.jar
-rw-r--r--@ 1 jblum  staff     24024 Feb  6  2019 shiro-crypto-cipher-1.4.0.jar
-rw-r--r--@ 1 jblum  staff     10873 Feb  6  2019 shiro-crypto-core-1.4.0.jar
-rw-r--r--@ 1 jblum  staff     34298 Feb  6  2019 shiro-crypto-hash-1.4.0.jar
-rw-r--r--@ 1 jblum  staff     19210 Feb  6  2019 shiro-event-1.4.0.jar
-rw-r--r--@ 1 jblum  staff     51122 Feb  6  2019 shiro-lang-1.4.0.jar
-rw-r--r--@ 1 jblum  staff     41203 Feb  6  2019 slf4j-api-1.7.25.jar
-rw-r--r--@ 1 jblum  staff     57954 Feb  6  2019 snappy-0.4.jar
-rw-r--r--@ 1 jblum  staff    379904 Sep  4  2019 spring-aop-4.3.20.RELEASE.jar
-rw-r--r--@ 1 jblum  staff    763445 Aug 21  2019 spring-beans-4.3.20.RELEASE.jar
-rw-r--r--@ 1 jblum  staff   1142763 Aug 21  2019 spring-context-4.3.20.RELEASE.jar
-rw-r--r--@ 1 jblum  staff   1130638 Aug 21  2019 spring-core-4.3.20.RELEASE.jar
-rw-r--r--@ 1 jblum  staff    274952 Aug 21  2019 spring-expression-4.3.20.RELEASE.jar
-rw-r--r--@ 1 jblum  staff    195025 Feb  6  2019 spring-shell-1.2.0.RELEASE.jar
-rw-r--r--@ 1 jblum  staff    828588 Sep  4  2019 spring-web-4.3.20.RELEASE.jar

See geode-dependenies.jar in the lib directory?

Now, let's inspect the META-INF/MANIFEST.MF file.

$ $ jar -xvf lib/geode-dependencies.jar META-INF/MANIFEST.MF
 inflated: META-INF/MANIFEST.MF

$ cat META-INF/MANIFEST.MF 
Manifest-Version: 1.0
Organization: Apache Software Foundation (ASF)
Class-Path: geode-common-1.9.2.jar geode-core-1.9.2.jar geode-connecto
 rs-1.9.2.jar geode-lucene-1.9.2.jar geode-redis-1.9.2.jar geode-old-c
 lient-support-1.9.2.jar geode-protobuf-1.9.2.jar geode-protobuf-messa
 ges-1.9.2.jar geode-management-1.9.2.jar geode-wan-1.9.2.jar geode-cq
 -1.9.2.jar geode-rebalancer-1.9.2.jar antlr-2.7.7.jar jgroups-3.6.14.
 Final.jar jackson-databind-2.9.8.jar jackson-annotations-2.9.8.jar sp
 ring-shell-1.2.0.RELEASE.jar commons-io-2.6.jar commons-validator-1.6
 .jar javax.activation-1.2.0.jar jaxb-api-2.3.1.jar jaxb-impl-2.3.1.ja
 r istack-commons-runtime-2.2.jar commons-lang3-3.8.1.jar micrometer-c
 ore-1.1.3.jar fastutil-8.2.2.jar javax.resource-api-1.7.1.jar jna-4.1
 .0.jar jopt-simple-5.0.4.jar log4j-slf4j-impl-2.11.1.jar log4j-core-2
 .11.1.jar log4j-jcl-2.11.1.jar log4j-jul-2.11.1.jar log4j-api-2.11.1.
 jar jetty-webapp-9.4.12.v20180830.jar jetty-servlet-9.4.12.v20180830.
 jar jetty-security-9.4.12.v20180830.jar jetty-server-9.4.12.v20180830
 .jar spring-core-4.3.20.RELEASE.jar snappy-0.4.jar shiro-core-1.4.0.j
 ar classgraph-4.0.6.jar rmiio-2.1.2.jar jansi-1.17.1.jar shiro-cache-
 1.4.0.jar shiro-crypto-hash-1.4.0.jar shiro-crypto-cipher-1.4.0.jar s
 hiro-config-ogdl-1.4.0.jar shiro-config-core-1.4.0.jar shiro-event-1.
 4.0.jar shiro-crypto-core-1.4.0.jar shiro-lang-1.4.0.jar slf4j-api-1.
 7.25.jar commons-beanutils-1.9.3.jar commons-collections-3.2.2.jar ht
 tpclient-4.5.6.jar commons-logging-1.2.jar javax.servlet-api-3.1.0.ja
 r httpcore-4.4.10.jar jackson-core-2.9.8.jar javax.activation-api-1.2
 .0.jar HdrHistogram-2.1.9.jar LatencyUtils-2.0.3.jar javax.transactio
 n-api-1.3.jar jetty-xml-9.4.12.v20180830.jar jetty-http-9.4.12.v20180
 830.jar jetty-io-9.4.12.v20180830.jar jline-2.12.jar jetty-util-9.4.1
 2.v20180830.jar commons-codec-1.10.jar HikariCP-3.2.0.jar lucene-anal
 yzers-phonetic-6.6.2.jar lucene-analyzers-common-6.6.2.jar lucene-que
 ryparser-6.6.2.jar lucene-core-6.6.2.jar lucene-queries-6.6.2.jar geo
 -0.7.1.jar netty-all-4.1.31.Final.jar grumpy-core-0.2.2.jar commons-m
 ath3-3.2.jar protobuf-java-3.6.1.jar
Title: geode
Version: 1.9.2
Created-By: jdeppe

All the JARs listed in the Class-Path Manifiest file attribute are relative to the geode-dependencies.jar and are also the JARs you require on your classpath inside WAS... So multiple <fileset> declarations for minimally, the Geode/GemFire JARs...

geode-core geode-cq geode-lucence geode-wan

... as well as any JARs that Spring Data GemFire needs, including potentially, 3rd party libs (i.e. the transitive dependencies) based on the features of GemFire your using (perhaps), e.g. Lucene..

lucene-xyz.jar

Etc.

Make sense?

Let's start here and iterate if needed. This should get you a bit further.

Hope this helps!

Gokul
  • 13
  • 6
John Blum
  • 7,381
  • 1
  • 20
  • 30
  • Thank you. You are right, geode-dependencies.jar is manifest only, thats why i kept the following jars in '/path/to/shared/geode-lib/: geode-common-9.8.3.jar geode-cq-9.8.3.jar geode-jca-9.8.3.rar geode-management-9.8.3.jar geode-core-9.8.3.jar geode-dependencies.jar geode-lucene-9.8.3.jar geode-wan-9.8.3.jar When I pack them inside WAR the application bootsup but fails at lookup = (GFConnectionFactory) template.lookup("gfe/jca"); saying: java.lang.ClassCastException: org.apache.geode.internal.ra.GFConnectionFactoryImpl incompatible with org.apache.geode.ra.GFConnectionFactory – Gokul Apr 01 '20 at 00:54
  • I get java.lang.ClassCastException: org.apache.geode.internal.ra.GFConnectionFactoryImpl incompatible with org.apache.geode.ra.GFConnectionFactory because GFConnectionFactoryImpl and GFConnectionFactory are loaded by different classloaders. Thats why I created a geode-lib shared library. Sharing between JCA resource adapter and web application – Gokul Apr 01 '20 at 00:56
0

As was suggested in alasdair's comment to the post, your application classloader ref is not pointing to the right thing. In your snippet, it's pointing to the shared lib not the resource adapter:

<webApplication contextRoot="apprRoot13" location="/path/to/mylocation.war" name="App13" id="App13">
    <classloader ... commonProviderRef="gemfireRaLib" ... />
</webApplication>

point it to the resource adapter instead:

<webApplication contextRoot="apprRoot13" location="/path/to/mylocation.war" name="App13" id="App13">
    <classloader ... commonProviderRef="gemfireJCA" ... />
</webApplication>

Update 1: A colleague pointed out I had a typo in my snippet, let me try again. Assuming:

  1. you dumped all the geode stuff into a shared lib

  2. the RA needs to access geode classes

  3. your app needs to access geode classes

here's what your server.xml should look like:

<resourceAdapter id="gemfireJCA" location="/path/to/geode-lib/geode-jca-9.8.3.rar">
    <classloader commonLibraryRef="gemfireRaLib" />
</resourceAdapter>
<library id="gemfireRaLib">
  <fileset dir="/path/to/geode-lib" includes="*.jar"/>
</library>
<webApplication contextRoot="apprRoot13" location="/path/to/mylocation.war" name="App13" id="App13">
    <classloader commonLibraryRef="gemfireRaLib"  />
</webApplication>

Notice I got rid of the apiTypeVisibility and delegation for now, typically the defaults are correct.

F Rowe
  • 2,042
  • 1
  • 11
  • 12
  • Thanks @F Rowe, When I do that, I get the following error java.lang.ClassCastException: org.apache.geode.internal.ra.GFConnectionFactoryImpl incompatible with org.apache.geode.ra.GFConnectionFactory It is GFConnectionFactoryImpl from JCA classloader cannot be converted into GFConnectionFactory of Webapplication. Classloader delegation is parentFirst. When I remove all geode-*.jar out of WAR, and refer are sharedlib I get class not found exception – Gokul Apr 02 '20 at 02:57
0

Thanks a lot for your response. Here is the root cause of the issue.

  • In Liberty there is no SingleClassloader per application policy. The classloader of a JCA resource adapter is different and WebApplication is different.
  • Hence geode-*.jar is loaded by 2 different classloaders.
  • GFConnectionFactory provided by gemfireJCA RA is different from application. Hence it is impossible to 'class cast' GFConnectionFactory loaded by JCA classloader into application classloader.

To solve this I can follow any of the below solutions:

Solution 1:

Deploy GemfireJCA and WAR in a Single EAR. Pack geode-jca.rar along with geode-*.jar and geode-dependencies.jar as a common library and WAR.

Please note: These geode-*.jar should not be in WEB-INF/lib of WAR. Here is the EAR tree: App13.ear: | |--gemfire-jca-9.8.3.rar |--WebApp13.war(Without geode-*.jar) |--lib | |--geode-common-9.8.3.jar | |--geode-cq-9.8.3.jar | |--geode-management-9.8.3.jar | |--geode-core-9.8.3.jar | |--geode-dependencies.jar | |--geode-lucene-9.8.3.jar | |--geode-wan-9.8.3.jar |--META-INF | |--application.xml (with module connector for gemfireJCA using gemfire-jca-9.8.3.rar)

Solution 2:

Handle connection via source code:

@Bean
public JCAManagedConnectionFactory jcaManagedConnectionFactory() {

    JCAManagedConnectionFactory jcaManagedConnectionFactory =
        new JCAManagedConnectionFactory();
    jcaManagedConnectionFactory.setProductName("GemFire");
    jcaManagedConnectionFactory.setUserName(""); // DO NOT SET ANY USERNAME
    jcaManagedConnectionFactory.setVersion("8.0");
    return jcaManagedConnectionFactory;
}
@Bean
public JCAManagedConnection jcaManagedConnection(JCAManagedConnectionFactory jcaManagedConnectionFactory)
    throws ResourceException {

    return (JCAManagedConnection) jcaManagedConnectionFactory
        .createManagedConnection(null, null);
}
    @Bean
public GFConnectionFactory getGFConnectionFactory(JCAManagedConnectionFactory jcaManagedConnectionFactory,
                                                  JCAManagedConnection jcaManagedConnection)
    throws ResourceException {

    GFConnectionFactory lookup =
        (GFConnectionFactory) jcaManagedConnectionFactory
            .createConnectionFactory(new ConnectionManager() {

                private static final long serialVersionUID =
                    1L;

                @Override
                public Object allocateConnection(ManagedConnectionFactory mcf,
                                                 ConnectionRequestInfo cxRequestInfo)
                    throws ResourceException {

                    return jcaManagedConnection.getConnection(null,
                        cxRequestInfo);
                }
            });
    return lookup;
}

Clean up connection during shutdown:

 @Override
public void onApplicationEvent(ContextClosedEvent event) {

    if (null != jcaManagedConnection) {
        try {
            jcaManagedConnection.cleanup();
        } catch (ResourceException e) {
            LOGGER.error("Error while shuttingdown the container {}",
                e.getMessage());
            LOGGER.error(e.getMessage(), e);
        }
    }
}
Gokul
  • 13
  • 6