Wildfly Postgres JDBC module issue - postgresql

I have postgres jdbc driver configured as module in Wildfly 10. What I am trying to do, is to use that driver as dependency in application that will be deployed on the server - so in application, I mark this dependency as provided (in pom.xml file) but it seems to be not working.
Current configuration:
Wildfly postgres module is added at wildfly-10.1.0.Final\modules\org\postgresql\main where there is: postgresql-9.4-1206-jdbc4.jar and module.xml with following content:
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">
<resources>
<resource-root path="postgresql-9.4-1206-jdbc4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
Module is used to define datasource. To this point, everything is working well - with hibernate help tables are happily mapped to entities. Except one thing:
I started to map postgres-jsonb columns with use of javax.persistence.AttributeConverter and following happens:
Scenario 1
When I use postgresql-9.4-1206-jdbc4.jar as a provided (in pom.xml - deployed application), I get following error trying to convert anything:
Caused by: java.lang.ClassNotFoundException: org.postgresql.util.PGobject from [Module "deployment.priject-1.0.1.ear.project.data-1.0.1-SNAPSHOT.jar:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)
... 269 more
Scenario 2
When I use postgresql-9.4-1206-jdbc4.jar with default scope, there is following error:
Caused by: java.lang.ClassCastException: org.postgresql.util.PGobject cannot be cast to org.postgresql.util.PGobject
at com.project.entity.util.converters.JSONBTypeConverter.convertToEntityAttribute(JSONBTypeConverter.java:33)
at com.project.entity.util.converters.JSONBTypeConverter.convertToEntityAttribute(JSONBTypeConverter.java:1)
at org.hibernate.type.descriptor.converter.AttributeConverterSqlTypeDescriptorAdapter$2.doConversion(AttributeConverterSqlTypeDescriptorAdapter.java:140)
... 266 more
Which means: class loader load the same jar two times, and can not cast this object to itself.
Question: Why provided scope of the dependency does not work for manually added (to wildfly) postgres driver? (I guess that would be the solution for me)

You need to use a jboss-deployment-structure.xml to add the module dependency to your deployment.
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.postgresql" />
</dependencies>
</deployment>
<sub-deployment name="project.data-1.0.1-SNAPSHOT.jar">
<dependencies>
<module name="org.postgresql" />
</dependencies>
</sub-deployment>
</jboss-deployment-structure>
Note the module dependency on the EAR may not be required. It just depends on how your EAR is setup.
Another option would be to add a Dependencies manifest entry. Since you're using Maven you could just use the maven-jar-plugin (since it appears this is a JAR inside an EAR) to create the entry.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Dependencies>org.postgresql</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>

Related

ModuleNotFoundException after Thorntail upgrade

I just upgraded the Thorntail version of my application from 2.5.0.Final to 2.6.0. Final.
My app is using a module (for authorization), which lies in a separate git repo, so I've included it in my pom.xml.
Since the upgrade I'm getting a ModuleNotFoundException when the module is called (authorization is triggered)
Caused by: org.jboss.modules.ModuleNotFoundException: org.apache.santuario.xmlsec
at org.jboss.modules.Module.addPaths(Module.java:1266) [backend-thorntail.jar:]
at org.jboss.modules.Module.link(Module.java:1622) [backend-thorntail.jar:]
at org.jboss.modules.Module.relinkIfNecessary(Module.java:1650) [backend-thorntail.jar:]
at org.jboss.modules.ModuleLoader.loadModule(ModuleLoader.java:299) [backend-thorntail.jar:]
at org.jboss.modules.ModuleLoader.loadModule(ModuleLoader.java:283) [backend-thorntail.jar:]
at org.jboss.as.security.plugins.SecurityActions.getModuleClassLoader(SecurityActions.java:50) [thorntailwildfly-security-18.0.1.Final5333088777079625058.jar:18.0.1.Final]
at org.jboss.as.security.plugins.ModuleClassLoaderLocator.get(ModuleClassLoaderLocator.java:65) [thorntailwildfly-security-18.0.1.Final5333088777079625058.jar:18.0.1.Final]
... 49 more
The problem is, that the org.apache.santuario.xmlsec dependency of the module is not being bundled in the thorntail jar, while all other dependencies are present in the jar.
This is the module.xml of the used module:
</module>
...
<dependencies>
<module name="javax.api"/>
<module name="javax.servlet.api"/>
<module name="org.apache.xalan"/>
<module name="org.apache.santuario.xmlsec"/>
<module name="org.picketbox"/>
<module name="org.jboss.logging"/>
</dependencies>
</module>
Does anyone have an idea how I can "force" Thorntail to include this dependency?
I also tried simply adding the latest version of the missing dependency in my pom.xml but unfortunately this doesn't help.
Any help is appreciated - thanks!

Migration to JBoss7.2eap from jboss5.1.2eap : java.lang.NoClassDefFoundError: Lorg/apache/commons/dbcp/BasicDataSource

I have migrated my application from jboss5.1.2-eap to jboss-7.2-eapand java6 to java8 but after migration it is starting giving me exception while starting the server.
Caused by: java.lang.NoClassDefFoundError: Lorg/apache/commons/dbcp/BasicDataSource
we have a datasource.xml file present in the classpath of the server, having the following line of code.
<bean id="beanName" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
<property name="maxActive" value="10"/>
Also we have commons-dbcp-1.2.2.jar present in the classpath but it is not working for jboss-7.2-eap.
Now I am not sure if commons-dbcp-1.2.2.jar is supported by jboss7-eap. as it is present in the classpath of the application(present in the loaded module), but still spring is not able to create the bean for datasource.
I suppose that datasource in Jboss EAP should be placed in standalone.xml configuration file and looks like here:
<datasource jndi-name="java:jboss/datasources/Altis" pool-name="Altis" enabled="true">
<connection-url>jdbc:oracle:thin:#255.255.255.255:1521:sid</connection-url>
<driver-class>oracle.jdbc.OracleDriver</driver-class>
<driver>oracle</driver>
<security>
<user-name>username</user-name>
<password>passwd</password>
</security>
</datasource>
Given module information in the jboss-deployment-structure.xml inside the WEB-INF directory of the war file.
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.oracle.sql" export="true"/>
<module name="org.apache.commons.dbcp" export="true"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
Also the module directories should also follow the same naming convention as per the availability of your .class files inside the jar, like in my case I have created module org.apache.commons.dbcp as while opening commons-dbcp-1.2.2.jar file, .class files are present inside org/apache/commons/dbcp folder.
Note: In case of multiple modules, you need to identify there dependency if a module is dependent on other and that information will be given inside module.xml file. like
<module xmlns="urn:jboss:module:1.1" name="org.apache.commons.dbcp">
<resources>
<resource-root path="commons-dbcp-1.2.2.jar"/>
</resources>
<dependencies>
<module name="org.apache.commons.pool"/>
<module name="com.oracle.jdbc.driver"/>
</dependencies>
</module>

Does the application server JBoss include CXF installation?

I'm trying to set the CXF Runtime on Eclipse web services preferences window.
I'm trying to point to JBoss installation in my pc at :
C:\jboss-eap-6.3\modules\system\layers\base\org\apache\cxf
But I'm getting error : Missing CXF jar: Please select the CXF home directory.
Shouldn't JBoss include a working CXF installation ?
Jboss AS 7.x have the dependency for apache CXF, you can use that by loading the module in your web application. There are a lot of way to achieve this on of common is setting apache cfx module as global module which will loaded into memory as the application server will started. Add the following lines in standalone.xml of jboss server-
<subsystem xmlns="urn:jboss:domain:ee:1.0" >
<global-modules>
<module name="org.apache.cxf" slot="main" />
</global-modules>
</subsystem>
If you want to add the module as web application dependent then you can use jboss-deployment-structure.xml-
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.apache.cxf" services="import">
<imports>
<include path="**" />
</imports>
</module>
</dependencies>
</deployment>
</jboss-deployment-structure>
and if you are using the maven build the you can load the module by manifest entry for the dependency-
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Dependencies>org.apache.cxf</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>

Why does my JBoss module throw a ClassCastException?

Hi StackOverflow Community,
I have a WAR which I have deployed to a JBoss Wildfly 8.2 instance. Also in Wildfly, I have created two modules:
a third party JMS JCA adapter module,
and a model module (model.jar) that contains message classes used to communicate between the JMS broker and the WAR
The WAR has a jboss-deployment-structure.xml that declares a dependency on the JCA module:
<?xml version='1.0' encoding='UTF-8'?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<dependencies>
<module name="com.thirdparty.mq.ra" slot="main"/>
<module name="com.company.model" slot="main">
</dependencies>
</deployment>
</jboss-deployment-structure>
The WAR has the model.jar file packaged in its WEB-INF/lib folder.
The JMS module has a dependency on the model module:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.thirdparty.mq.ra">
<resources>
<resource-root path="."/>
<resource-root path="thirdparty-jms-provider.jar"/>
...
<resource-root path="thirdparty-lib.jar"/>
</resources>
<dependencies>
<module name="com.company.model"/>
<module name="javax.api"/>
<module name="javax.jms.api"/>
<module name="javax.transaction.api"/>
<module name="javax.management.j2ee.api"/>
<module name="javax.resource.api"/>
<module name="org.jboss.invocation"/>
<module name="org.jboss.remote-naming" optional="true"/>
<module name="org.slf4j"/>
</dependencies>
</module>
When running, I get the following exception:
Caused by: java.lang.ClassCastException: com.company.model.web.dto.WebAuthenticationResponse cannot be cast to com.company.model.web.dto.WebAuthenticationResponse
I suspect it is a classloader issue. Is there some extra information I have to specify in the module.xml or jboss-deployment-structure.xml files?
Thanks for your help!
Assuming that your model.jar corresponds to your com.company.model module, your WAR classloader now sees the model classes twice, both from its own libraries in WEB-INF/lib and via the module dependency.
You should either import or embed a module/library, but not both.
By the way, importing a RAR module looks a bit suspicious. You should never depend on the implementation of a resource adapter. Maybe you can factor out an API module and import that.

JBOSS CLI adding module with optional dependency

I have a module.xml that looks like:
<module xmlns="urn:jboss:module:1.1" name="com.oracle">
<resources>
<resource-root path="ojdbc6.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
Using JBOSS-CLI one can do this:
./jboss-cli.sh -c --command="module add --name=com.oracle --resources=<path-to-file>/ojdbc6.jar --dependencies=javax.api,javax.transaction.api,javax.servlet.api"
to deploy the module. It is almost the same exact thing and the module.xml is generated; so I need not keep track of another xml.
But how can I get the 'optional="true"' from JBOSS-CLI?
Version: JBOSS-EAP 6.2.0. (would be great if I can find a solution that would work for either jboss 6.x EAP and wildfly 8x).
The CLI module command appears to only support simple dependencies.
You could work around it by supplying a pre-generated modules.xml file and specifying it in the CLI command using
--module-xml=filepath_to_modules.xml