I am starting introduction with wildfly learning.
I have downloaded distribution of server.
Now I am trying to configure datasource but I see following error:
Unexpected HTTP response: 500
Request
{
"address" => [
("subsystem" => "datasources"),
("data-source" => "PostgreDataSource")
],
"operation" => "test-connection-in-pool"
}
Response
Internal Server Error
{
"outcome" => "failed",
"failure-description" => "WFLYJCA0040: failed to invoke operation: WFLYJCA0042: failed to match pool. Check JndiName: java:jboss/datasources/PostgreDataSource",
"rolled-back" => true
}
My steps:
1. Created folder wildfly-10.0.0.CR2\wildfly-10.0.0.CR2\modules\org\postgres\main and copy postgresql-9.0-801.jdbc4.jar from \.m2\repository\postgresql\postgresql\9.0-801.jdbc4 there.
2.Created module.xml(inside wildfly-10.0.0.CR2\wildfly-10.0.0.CR2\modules):
with following content:
<module xmlns="urn:jboss:module:1.0" name="org.postgres">
<resources>
<resource-root path="postgresql-9.0-801.jdbc4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
Modified standalone.xml(wildfly-10.0.0.CR2\wildfly-10.0.0.CR2\standalone\configuration) like this(sorry - I don't know how to copy xml that it can be visible for another users(full content visible here: http://collabedit.com/psk4a)):
Please help to understand what do I wrong?
Below given is driver configuration and data source creation and how to make it globally visible so that all J2EE deployments can access the particular module if needed.
1. PostGreSQL Driver Configuration
Create directory structure as below inside the modules in wildfly-8.2.0.Final\modules directory and place the mentioned files and driver jar.
Directory: wildfly-8.2.0.Final\modules\org\postgresql\main
File: module.xml
<!--<?xml version="1.0" encoding="UTF-8"?>-->
<module xmlns="urn:jboss:module:1.0" name="org.postgresql">
<resources>
<resource-root path="postgresql-9.4-1204.jdbc41.jar"/>
</resources>
<dependencies><module name="javax.api"/></dependencies>
</module>
JAR : PostGreSQL Driver: postgresql-9.4-1204.jdbc41.jar
Note : Driver version can be your choice and please ensure to reflect that version name in module.xml file.
Please note that the driver name="org.postgresql” mentioned in the module.xml file should be matching with the data source(s) configuration in the standalone.xml file.
Note: The PostGreSQL driver version should be compatible to the java version in the system.
In this example, java is 1.7 & PostGreSQL driver used is postgresql-9.4-1204.jdbc41.jar.
2. Configuring the DataSources
Datasources are configured in the standalone.xml file in the WildFly 8.2.0.Final\standalone\configuration.
As the first step configure the PostGreSQL driver reference in the standalone.xml file as below inside the tag
<driver name="postgresql" module="org.postgresql">
<datasource-class>org.postgresql.Driver</datasource-class>
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
1. Add the datasource details:
Please add this inside tag
<datasource jndi-name="java:/db1" pool-name="db1" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://localhost:5432/dbname</connection-url>
<driver>postgresql</driver>
<security>
<user-name>user_name</user-name>
<password>password</password>
</security>
</datasource>
2.make the published drivers globally visible by adding
to the section
Here it is:
<global-modules>
<module name="org.postgresql" slot="main"/>
</global-modules>
Note : Global modules is a set of JBoss Modules that will be added as dependencies to the JBoss Module of every Java EE deployment. Such dependencies allows Java EE deployments to see the classes exported by the global modules. Refer : https://docs.jboss.org/author/display/WFLY8/Subsystem+configuration
Once configured the above, please start your WildFly instance.
Problem resolved after move module.xml to wildfly-10.0.0.CR2\wildfly-10.0.0.CR2\modules\org\postgres\main
I am not 100% positive, but if I see some links around the net it may be caused by default pool settings. You might try by adding specific pool configuration settings to your datasource:
<datasource jndi-name="blabla"... >
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>20</max-pool-size>
<prefill>true</prefill>
</pool>
</datasource>
I base that on this stackoverflow thread: WildFly jdbc connection with Oracle
where an answer links to this related JBoss forum thread: https://developer.jboss.org/thread/257721
The pool settings are mentioned in the Wildfly configuration documentation by the way. This is Wildfly 9, but I can't imagine things changed much in Wildfly 10: https://docs.jboss.org/author/display/WFLY9/DataSource+configuration
I'd like to say that I solved the problem only by using wildfly admin console (http://localhost:9990/console/). Not so spartan solution, but it works. I only pointed the JDBC driver jar from external directory and after I created a datasource. No xml by hand and no modifying wildfly's directory structure.
For java 8 + postgresql 9.5 I used postgresql-42.1.1.jar. I had problems befor only because I chose the wrong driver and database's name was wrong.
Although this topic is a bit old, I'd like to stress that the recommended way to install a datasource as a module is using the CLI 'module add' command which creates the full path for the module and the module.xml configuration file. This makes the whole process less error-prone.
module add --name=org.postgres --resources=[JDBC JAR FILE] --dependencies=javax.api,javax.transaction.api
Also, I see mentioned here the usage of global modules for datasource. This is not a common practice for JDBC drivers as global modules are meant to be used for shared libraries which are common to all applications and don't require maintenance. You might end up with an unconsistent datasource configuration if the Database is upgraded and you forget to update the JDBC Driver in your modules configuration.
Ref: How to configure a Datasource in WildFly
Related
I am try to convert a WAS traditional 8.5 websphere configuration to a websphere liberty 20.x configuration and getting an error. I believe the connection settings are right, the names are correct, the jar file for the driver exists but getting the error below.
Here is essentially the configuration.
<dataSource jndiName="jdbc/db2a" type="javax.sql.DataSource">
<jdbcDriver javax.sql.DataSource="com.ibm.db2.jcc.DB2Driver" libraryRef="DB2JCCLib"/>
<properties.db2.jcc driverType="4" databaseName="DB1" serverName="host.name" portNumber="446"/>
</dataSource>
<web-bnd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://websphere.ibm.com/xml/ns/javaee"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd" version="1.0">
<virtual-host name="default_host"/>
<resource-ref name="jdbc/db2a" binding-name="jdbc/db2a"/>
</web-bnd>
...
Configuration at top of server.xml
<!-- Enable features -->
<featureManager>
<feature>appSecurity-2.0</feature>
<feature>jaxrs-2.0</feature>
<feature>jsp-2.3</feature>
<feature>localConnector-1.0</feature>
<feature>jaxws-2.2</feature>
<feature>ldapRegistry-3.0</feature>
</featureManager>
The jar file is : db2jcc4-4.22.29.jar
And has as reference to that jar / class file.
The java code for the connection is standard jdbc connection:
DriverManager.getConnection (connStr);
And this:
InitialContext initialContext = new InitialContext();
Context context = (Context)initialContext.lookup("java:comp/env");
DataSource dataSource = (DataSource)context.lookup(string5);
logger.info((Object)"CVDBBackendHandler.getConnection() out");
return dataSource.getConnection();
The error is below.
Root exception is com.ibm.wsspi.injectionengine.InjectionException: CWNEN0030E: The server was unable to obtain an object instance for the java:comp/env/jdbc/db2a reference. The exception message was: CWNEN1003E: The server was unable to find the jdbc/db2a binding with the java.lang.Object type for the java:comp/env/jdbc/db2a reference.
You need to add one of the JDBC features to your feature list, e.g.
<featureManager>
<feature>jdbc-4.3</feature>
</featureManager>
(or one of the earlier JDBC features, e.g.jdbc-4.2, etc.).
Though your messages.log should show a feature set like this (including features pulled in from the features you explicitly enabled):
CWWKF0012I: The server installed the following features: [appSecurity-2.0, distributedMap-1.0, el-3.0, federatedRegistry-1.0, jaxb-2.2, jaxrs-2.0, jaxrsClient-2.0, jaxws-2.2, jndi-1.0, json-1.0, jsp-2.3, ldapRegistry-3.0, localConnector-1.0, servlet-3.1, ssl-1.0].
this list doesn't include any activating the JDBC feature, so you must explicitly enable it. (On the other hand, note the jndi-1.0 feature required to do JNDI lookups is included even though it wasn't one you added directly to server.xml, since one of the other features included it).
Some helpful links for reference:
https://openliberty.io/docs/latest/reference/feature/jdbc-4.3.html
https://openliberty.io/docs/latest/relational-database-connections-JDBC.html
There is an error in the configuration. com.ibm.db2.jcc.DB2Driver is not an implementation of javax.sql.DataSource.
You can remove the configuration attribute javax.sql.DataSource="com.ibm.db2.jcc.DB2Driver" and let the built-in knowledge in Liberty infer it from the JDBC driver jar, or you can specify it as,
javax.sql.DataSource="com.ibm.db2.jcc.DB2DataSource"
The above data source class name can be found in DB2 documentation here
UPDATE: This unanswered question on jboss forums, is another way of describing my exact problem: https://developer.jboss.org/thread/199888
Original post:I am trying to make integrated authentication work on web applications deployed to JBoss 7.x. I have successfully made one work, by copying sqljdbc_auth.dll into either Windows/System32, or {java location}/jre/bin. However, if two or more applications are running, I will get an error saying that Native Library sqljdbc_auth.dll already loaded in another classloader
I know why this error is happening, and this question and answer has a Tomcat solution. But I can't make it work in JBoss. Actually, putting the dll inside the jboss/bin folder gives the exact same error as before:
Failed to load the sqljdbc_auth.dll cause :
Native Library C:\Jboss-eap-7.0\bin\sqljdbc_auth.dll already loaded in another classloader
How do I configure JBoss, and/or place the sqljdbc_auth.dll?
My deployments are not located under any module, or named server instance. I think it's simply called standalone
I have tried this approach as well, but I can not figure out where to put the jar file, in the JBoss directories. I tried deploying it as a deployment like the web applications, and I tried copying it into the lib folder, under standalone. No success.
EDIT:
I am trying to implement a global module, as per the answer posted, but get following error now:
14:00:25,333 ERROR [stderr] (ServerService Thread Pool -- 121)
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver from
[Module "deployment.MyWebapp.war:main" from Service Module Loader]
I assume you must have created a module for sql jdbc driver something like this.
<module xmlns="urn:jboss:module:1.3" name="com.microsoft.sqlserver">
<resources>
<resource-root path="sqljdbc.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
And added this module as dependency to each of your deployed application.
I would suggest to declare this module as global module by editing the standalone.xml file like this ..
<subsystem xmlns="urn:jboss:domain:ee:4.0">
<global-modules>
<module name="com.microsoft.sqlserver" slot="main"/>
.
.
</global-modules>
.
.
</subsystem>
And remove the dependency to this module from your individual applications.
Can anyone help me in configuring MongoDB driver as a core module for connection pooling in JBoss. Please refer to following step which I have tried after reading few posts.
Created a directory EAP_HOME/modules/com/mongodb/main/ and copy the mongodb-driver-3.4.0-rc1.jar (rc1 version because stable version 3.3.0 doesn't contain MongoClientFactory.class) and created module.xml file as below.
<module xmlns="urn:jboss:module:1.3" name="com.mongodb">
<resources>
<resource-root path="mongodb-driver-3.4.0-rc1.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
Then, Added MongoDB driver into standalone.xml file, please refer to the following properties I have added into standalone.xml file.
<driver name="com.mongodb" module="com.mongodb">
<xa-datasource-class>com.mongodb.client.jndi.MongoClientFactory</xa-datasource-class>
</driver>
After all these configuration I have started JBoss server and getting "Unable to find driver class name in "com.mongodb" jar" whereas jar is present and also contains MongoClientFactory datasource class.
I did not find a freeware solution to enable xa-datasource driver configuration.
Accordingly to Red Hat JBoss Enterprise Application Platform 7 supported configurations, MongoDB isn't currently being supported:
https://access.redhat.com/articles/2026253
You can try these approaches below (using proprietary drivers):
https://www.progress.com/jdbc
http://www.unityjdbc.com/mongojdbc/mongo_jdbc.php (trial for 15 days)
However, you can try configuring a JNDI interface using MongoDB java driver:
http://mongodb.github.io/mongo-java-driver/3.3/driver/reference/connecting/jndi/#examples
"A MongoClient instance will be accessible via the JNDI name mongodb/MyMongoClient in the java:comp/env context."
Answering your question, maybe you'll need to put the *.jar inside this directory:
modules/system/layers/base/org/mongodb/main
I've tried tutorial at mastertheboss.com:
./jboss-cli.sh
module add --name=org.postgres --resources=/tmp/postgresql-9.3-1101.jdbc41.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)
data-source add --jndi-name=java:/PostGreDS --name=PostgrePool --connection-url=jdbc:postgresql://localhost/postgres --driver-name=postgres --user-name=postgres --password=postgres
This tutorial works with WildFly 8.2, but it doesn't work with WildFly 9.0. 3rd step fails with error message:
{
"outcome" => "failed",
"failure-description" => "WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
How to add Postgres datasource to WildFly 9.0?
I've encountered the same error and behavior of WildFly 9. I'm a complete newbie to WF, but after some research I've found that the trouble is in the module naming.
If I'm getting it well, the actual package names in the module are used to resolve the path to module.xml.
I've changed the steps to those below and it worked:
module add --name=org.postgresql --slot=main --resources=/usr/local/lib/postgresql-9.4-1201.jdbc4.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql",driver-class-name=org.postgresql.Driver)
I am running wildfly 10 in a docker:
#ADD DATASOURCES
RUN mkdir -p $JBOSS_HOME/modules/org/postgres/main
COPY files/postgresql-9.4.1208.jre7.jar $JBOSS_HOME/modules/org/postgres/main/
COPY files/module.xml $JBOSS_HOME/modules/org/postgres/main/
COPY files/standalone.xml $JBOSS_HOME/standalone/configuration
Where module.xml is
<module xmlns="urn:jboss:module:1.1" name="org.postgres">
<resources>
<resource-root path="postgresql-9.4.1208.jre7.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
And standalone contains driver:
<driver name="postgresql" module="org.postgres">
<xa-datasource-class>org.postgresql.Driver</xa-datasource-class>
</driver>
then datasource can be:
<datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://ndis-db:5432/postgres</connection-url>
<driver>postgresql</driver>
...
Note that my ndis-db is a postgres docker. In your case can be localhost.
How I ended up with the error mentioned by you:
1. file name spelled wrongly
2. /modules/org ...etc contain a typo
3. module.xml misspelled as modules.xml
4. ...
Its very simple but could take more time if you will be new with JBOSS EAP/WilFly
Use below steps to create a datasource:
Go to bin folder of server where jboss-cli(Power script) file present: right click on jboss-cli(power script file)--> Run with power shell (a console will open).
Add the PostgreSQL JDBC driver as a core module.
module add --name=com.postgresql
--resources=/path/to/postgresql-9.3-1102.jdbc4.jar --dependencies=javax.api,javax.transaction.api
Register the PostgreSQL JDBC driver.
/subsystem=datasources/jdbc-driver=postgresql:add(driver-name=postgresql,driver-module-name=com.postgresql,driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource)
Add the PostgreSQL datasource.
data-source add --name=PostgresDS --jndi-name=java:jboss/PostgresDS
--driver-name=postgresql --connection-url=jdbc:postgresql://localhost:5432/postgresdb --user-name=admin --password=admin --validate-on-match=true --background-validation=false --valid-connection-checker-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker
--exception-sorter-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter
be careful with path path/to this is path where your downloded Postgresql-jdbc.jar is present.
Put your Postgres JDBC driver into deployment folder (just deploy).
Now use CLI console and enter this command:
data-source add --name=PostgresqlDS --jndi-name=java:jboss/datasources/PostgresqlDS --driver-name=postgresql-9.4-1201.jdbc41.jar --connection-url=jdbc:postgresql://localhost:5432/test --user-name=USER --password=PASSWORD
Check if your driver is jdbc4.
I don't know why but adding datasources by web console doesn't work. By CLI works.
The right solution for extending JDBC drivers is add driver as module to server.
In WildFly 9 you can do it using cli console. You can't do this by copy JDBC jar file (with xml) to "module" folder like in WildFly 8.
Execute commands:
module add --name=org.postgres --resources=postgresql-9.4-1201.jdbc41.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)
To list instaled drivers enter:
/subsystem=datasources:installed-drivers-list
With driver creating datasources will be easy.
Please use 9.0 Final version. In CR are bugs.
Regards,
Pawel M
You don't mention your java/jdbc version. I've just experienced the same issue and it was due to a driver vs Java 1.8 mismatch. With the wildfly 9 upgrade did you also upgrade Java?
The ".jdbc41." driver version is built for Java 1.7. Postgres has a matrix showing the combinations of Java/JDBC and Postgres driver versions that are compatible. Perhaps you need: postgresql-9.4.1209.jar (which is for 1.8/jdbc42)
Then in the CLI (assuming domain mode and profile=full)
module add --name=org.postgresql.Driver --resources=/tmp/postgresql-9.4.1209.jar
connect
/profile=full/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql.Driver",driver-class-name=org.postgresql.Driver)
exit
Just a note: I have tested the CLI commands, as taken from the tutorial mentioned, against WildFly 10 and it works correctly in creating the JDBC Driver and the datasource.
Besides it, I can see that the error log reported contains a mispelling of the module name ("org.portgres"):
{
"outcome" => "failed",
"failure-description" => "WFLYJCA0041: Failed to load module for driver [org.portgres]",
"rolled-back" => true
}
Disclaimer: I'm the owner of mastertheboss.com
I am trying to deploy an ear in jboss EAP 6.3 but I am getting following error:
JBAS014775: New missing/unsatisfied dependencies:
service jboss.naming.context.java.jdbc.mn572phOraDataSource (missing) dependents: [service jboss.naming.context.java.module.pharma.pharma.env.jdbc.mn572phOraDataSource]
service jboss.naming.context.java.jdbc.mn572phaOraDataSource (missing) dependents: [service jboss.naming.context.java.module.pharma.pharma.env.jdbc.mn572phaOraDataSource]
15:01:38,171 ERROR [org.jboss.as] (Controller Boot Thread) JBAS015875: JBoss EAP 6.3.0.GA (AS 7.4.0.Final-redhat-19) started (with errors) in 66301ms - Started 462 of 659 services (160 services failed or missing dependencies, 64 services are lazy, passive or on-demand)
My standlone.xml file has this entry:
<datasource jndi-name="java:/module/env/jdbc/mn572phOraDataSource" pool-name="mn572phOraDataSource" enabled="true" use-java-context="true">
<connection-url>jdbc:oracle:thin:#test:1521:mndb11g</connection-url>
<driver>oracle.jdbc.driver.OracleDriver</driver>
<security>
<user-name>test</user-name>
<password>test</password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="oracle.jdbc.driver.OracleDriver" module="oracle.jdbc.driver.OracleDriver">
<datasource-class>oracle.jdbc.driver.OracleDriver</datasource-class>
</driver>
</drivers>
</datasources>
My jboss-web.xml inside .war file has following entry:
<resource-ref>
<res-ref-name>jdbc/mn572phaOraDataSource</res-ref-name>
<jndi-name>java:/jdbc/mn572phaOraDataSource</jndi-name>
</resource-ref>
Can anyone please explain what the error says and what the problem can be.
In general 'New missing/unsatisfied dependencies:' is about the contents of your ear file in relation to the resources within it and provided on the server. What it is telling you is that there are requests for injection of objects for which you have not supplied either:
the required classes; or
not configured resources in your server.
This could be caused by six things that I can think of.
You have missed a jar from the ear file.
You have classes in an enclosed jar file that do not have access to the jars that contain their dependencies.
You have beans.xml missing from one of the included jar files.
Your classes depend on a module that should be installed in the server but which has not been installed.
You have missed the declaration of the dependency in item 4 from your joss*.xml files
Your application requires a resource (such as a DataSource) and you have not defined one in your server.
The second point is quite complex and deals with the scope of class loaders In Java EE applications. Basically:
classes in war files can access normal jar files in lib.
EJB jars can access jar files in lib.
jar files in lib may have trouble accessing the other two.
Update:
Sorry for the delay in replying but I wanted to check this before I replied as this area is quite complex.
In this case the problem is a mismatch between the name you have provided in in the jboss-web.xml and the name you provided in standalone.xml.
JavaEE6 has several different namespaces for resources.
The default namespace for the jboss-web.xml is the module namespace which works as java:module///XXXXX. In your case your module is your war file (pharma) and unless you actually defined it in an ear file called pharma JBOSS automatically wraps it in an ear file called pharma. So you get java:module/pharma/pharma/XXXXXX.
The default namespace for standalone.xml is java:global so your actual DataSource is probably installed at java:global/module/env/jdbc/mn572phaOraDataSource
I have tried to run up a little webapp app with your provided configuration files in it and to provide a resource for the mapping I added a #Singleton #Startup bean that defined link to Datasource #Resource.
I managed to get something similar to your error messages although not completely
I think that there are 2 problems:
one is that some of your jndi names read mn572phOraDataSource and some read mn572phaOraDataSource your can see this in the error message because the 2 variants are include.
second is that the JNDI name java:/jdbc/mn572phaOraDataSource in jboss-web does not match java:/module/env/jdbc/mn572phOraDataSource in standalone.xml. I got it to work by changing the name in the standalone.xml to java:/jdbc/mn572phaOraDataSource.