3

I have installed a new WildFly instance on CentOS 7. I'm trying to create a connection to a remote PostgreSQL instance.

The way I do it is by deploying the PostgreSQL JDBC jar to WildFly, and create datasource using that. I've done all this through the web console.

Here is my datasource configuration:

my datasource configuration

Here is my datasource configuration in standalone.xml

<datasource jndi-name="java:/PostgresDS" pool-name="PostgresDS">
    <connection-url>jdbc:postgresql://10.130.31.43:5432/postgresdb</connection-url>
    <driver-class>org.postgresql.Driver</driver-class>
    <datasource-class>org.postgresql.ds.PGSimpleDataSource</datasource-class>
    <driver>postgresql-42.2.5.jar</driver>
    <security>
        <user-name>admin</user-name>
        <password>admin</password>
    </security>
    <validation>
        <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/>
        <background-validation>true</background-validation>
        <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/>
    </validation>
</datasource>

Everytime I test the connection, this error is returned:

2018-10-30 11:28:46,392 WARN  [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (External Management Request Threads -- 1) IJ000604: Throwable while attempting to get a new connection: null: javax.resource.ResourceException: IJ031084: Unable to create connection
    at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:345)
    at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:352)
    at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:287)
    at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.createConnectionEventListener(SemaphoreConcurrentLinkedDequeManagedConnectionPool.java:1326)
    at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.getConnection(SemaphoreConcurrentLinkedDequeManagedConnectionPool.java:499)
    at org.jboss.jca.core.connectionmanager.pool.AbstractPool.internalTestConnection(AbstractPool.java:1067)
    at org.jboss.jca.core.connectionmanager.pool.strategy.OnePool.testConnection(OnePool.java:93)
    at org.jboss.as.connector.subsystems.common.pool.PoolOperations$TestConnectionInPool.invokeCommandOn(PoolOperations.java:240)
    at org.jboss.as.connector.subsystems.common.pool.PoolOperations$1.execute(PoolOperations.java:97)
    at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:999)
    at org.jboss.as.controller.AbstractOperationContext.processStages(AbstractOperationContext.java:743)
    at org.jboss.as.controller.AbstractOperationContext.executeOperation(AbstractOperationContext.java:467)
    at org.jboss.as.controller.OperationContextImpl.executeOperation(OperationContextImpl.java:1411)
    at org.jboss.as.controller.ModelControllerImpl.internalExecute(ModelControllerImpl.java:423)
    at org.jboss.as.controller.ModelControllerImpl.lambda$execute$1(ModelControllerImpl.java:243)
    at org.wildfly.security.auth.server.SecurityIdentity.runAs(SecurityIdentity.java:265)
    at org.wildfly.security.auth.server.SecurityIdentity.runAs(SecurityIdentity.java:231)
    at org.jboss.as.controller.ModelControllerImpl.execute(ModelControllerImpl.java:243)
    at org.jboss.as.domain.http.server.DomainApiHandler.handleRequest(DomainApiHandler.java:212)
    at io.undertow.server.handlers.encoding.EncodingHandler.handleRequest(EncodingHandler.java:72)
    at org.jboss.as.domain.http.server.DomainApiCheckHandler.handleRequest(DomainApiCheckHandler.java:93)
    at org.jboss.as.domain.http.server.security.ElytronIdentityHandler.lambda$handleRequest$0(ElytronIdentityHandler.java:62)
    at org.wildfly.security.auth.server.SecurityIdentity.runAs(SecurityIdentity.java:289)
    at org.wildfly.security.auth.server.SecurityIdentity.runAs(SecurityIdentity.java:246)
    at org.jboss.as.controller.AccessAuditContext.doAs(AccessAuditContext.java:254)
    at org.jboss.as.controller.AccessAuditContext.doAs(AccessAuditContext.java:225)
    at org.jboss.as.domain.http.server.security.ElytronIdentityHandler.handleRequest(ElytronIdentityHandler.java:61)
    at io.undertow.server.handlers.BlockingHandler.handleRequest(BlockingHandler.java:56)
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:360)
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
    at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)
    at java.lang.Thread.run(Thread.java:748)
    at org.jboss.threads.JBossThread.run(JBossThread.java:485)
Caused by: org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:280)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
    at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
    at org.postgresql.Driver.makeConnection(Driver.java:454)
    at org.postgresql.Driver.connect(Driver.java:256)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:94)
    at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:314)
    ... 35 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at org.postgresql.core.PGStream.<init>(PGStream.java:70)
    at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:91)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192)
    ... 43 more

2018-10-30 11:28:46,393 ERROR [org.jboss.as.controller.management-operation] (External Management Request Threads -- 1) WFLYCTL0013: Operation ("test-connection-in-pool") failed - address: ([
    ("subsystem" => "datasources"),
    ("data-source" => "PostgresDS")
]) - failure description: "WFLYJCA0040: failed to invoke operation: WFLYJCA0047: Connection is not valid"

I'm confused, in the stacktrace there is localhost:5432 mentioned. I have defined the connection URL, and it is written in standalone.xml as well.

Is there another reason why WildFly isn't using the defined connection-url and instead defaults to localhost:5432? And is there another reason why WildFly throws WFLYJCA0047: Connection is not valid?

Ferdi
  • 71

3 Answers3

2

I want to provide answer in case anyone else stumbles upon this issue.

Turns out I have to set "Connection Properties" instead of "Connection URL".

Only then WildFly connects to the correct database server.

Screenshot below.

WildFly Console DataSource configuration

Ferdi
  • 71
1

Remove this tag

<datasource-class>org.postgresql.ds.PGSimpleDataSource</datasource-class>

https://issues.jboss.org/browse/WFLY-6157

Ok, the problem comes when you have datasource-class defined in your driver. If a datasource-class is defined then it takes precedence to create the datasource and as such it can only use connection-properties. Since there is not a single connection-url property for all drivers, you have to use connection-properties if you adre defining the datasource-class.

0
  1. Remove the tag

    <datasource-class>org.postgresql.ds.PGSimpleDataSource</datasource-class>
    

enter image description here

  1. Change the driver jar file to the latest one.
MarianD
  • 2,726