Wildfly tries to open wrong server - wildfly

While accesing a remote database Wildfly is not able to connect to it, it tries to access COMPNAME (my computer's name) as if it was the selected database instead of the one defined on datasource, that of course doesn't exist.
I have used the same conection properties on datasource to access database with SQL Server Management Studio and it works perfectly, the standalone configuration is the same as in my old computer where it worked.
This is the datasource:
<datasource jta="true" jndi-name="java:/SQLDESTINATION" pool-name="SQLDESTINATION" enabled="true" use-ccm="true">
<connection-url>jdbc:sqlserver://urlthatworks:1433;DatabaseName=DB_NAME</connection-url>
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
<driver>sqljdbc4.jar</driver>
<security>
<user-name>userok</user-name>
<password>passok</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLValidConnectionChecker"/>
<background-validation>true</background-validation>
</validation>
</datasource>
And here is wildfly log:
2019-09-27 13:29:53,126 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (ServerService Thread Pool -- 71) javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:/SQLDESTINATION
2019-09-27 13:30:07,483 WARN [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (ServerService Thread Pool -- 71) IJ000604: Throwable while attempting to get a new connection: null: javax.resource.ResourceException: IJ031084: Unable to create connection
.......
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot open server "COMPNAME" requested by the login. The login failed.
So problem is that instead of trying to get to "DB_NAME" it is trying to access "COMPNAME"
Difference that I guess shouldn't matter is old computer was using windows 7 and this one windows 10 and in old computer wildfly folder was under C:\Users\myusername\wildfly-10.1.0.Final folder while in new one it is in D:\wildfly-10.1.0.Final

Try databaseName=DB_NAME instead of DatabaseName=DB_NAME.

I managed to get it work by changing the folder to C:\Users\myusername\wildfly-10.1.0.Final although this doesn't explain why on D: it would try to overwrite the server name with my computer name.

Related

Keycloak retry database connection during startup

I have Keycloak on one server configured to connect to a remote PostgreSQL database, both the database and the Keycloak server start at the same time in the morning but the database takes a little more time before it's available which prevents the Keycloak service from starting:
WARN [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (ServerService Thread Pool -- 63) IJ000604: Throwable while attempting to get a new connection: null: javax.resource.ResourceException: IJ031084: Unable to create connection
I tried adding the following lines to standalone.xml but it only seems to prevent Keycloak from crashing if it's already started and the database reboots:
<validation>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
<validate-on-match>false</validate-on-match>
<background-validation>true</background-validation>
<background-validation-millis>15000</background-validation-millis>
</validation>
If anyone is looking for a solution and is using systemd, I ended up adding these two lines to my keycloak.service file in the [Service] block:
Restart=always
RestartSec=5min

ActiveMQ has correct dialect but the SQL statements are incorrect AUTO_INCREMENT instead of IDENTITY tables creation

I'm using the following:
JBoss Wildfly 15.0.1.Final
MSSQL JDBC connector (i.e. mssql-jdbc-7.2.2.jre11.jar)
standalone-full.xml
I believe I have setup everything correctly. The MSSQL JDBC jar is in the modules directory with its associated module.xml. The datasource is correctly defined and functional. ActiveMQ Artemis has been setup (works fine using the file system). However when I attempt to have it use JDBC it fails trying to create the necessary tables with the following error:
SQLState: S0001 ErrorCode: 102 Message: Incorrect syntax near AUTO_INCREMENT'.
So I'm wondering what is wrong. ActiveMQ says it supports SQL Server, and it automatically figures out which SQL dialect to use based on the return value of the driver (I've checked that name with an 6.0 version of the driver and it is the same), also in the debug output it says
[org.apache.activemq.artemis.jdbc.store.journal.JDBCJournalImpl] ServerService Thread Pool -- 80) Detect database dialect as 'MSSQL'".
So that looks good. So I'm a bit confused on what is wrong and would like to get it to work. I'm providing the critical elements that I have in the standalone-full.xml. Is there any other setup I need or is this a bug?
Is this also a symptom of a problem? (i.e. see the log output...the broker is not initialized with correct driver/url that was specified by the datasource definition)
AMQ221000: live Message Broker is starting with configuration Broker Configuration (clustered=false,jdbcDriverClassName=org.apache.derby.jdbc.EmbeddedDriver,jdbcConnectionUrl=null,messageTableName=AMQ_MESSAGES,bindingsTableName=AMQ_BINDINGS,largeMessageTableName=AMQ_LARGE_MESSAGES,pageStoreTableName=AMQ_PSTORE,)
excerpts from the standalone-full.xml settings
<extensions>
<extension module="org.wildfly.extension.messaging-activemq"/>
</extensions>
<datasources>
<datasource jndi-name="java:/RMBM-DEFAULT-DS" pool-name="RMBM-DEFAULT-DS" enabled="true">
<connection-url>jdbc:sqlserver://${rmbm.default.ds.host}:${rmbm.default.ds.port:1433};DatabaseName=${rmbm.default.ds.dbname}
</connection-url>
<driver>SQLSVR</driver>
</datasource>
<drivers>
<driver name="SQLSVR" module="com.microsoft.sqlserver.jdbc">
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver- class>
</driver>
</drivers>
<subsystem xmlns="urn:jboss:domain:messaging-activemq:5.0">
<server name="default">
<journal datasource="RMBM-DEFAULT-DS" messages-table="AMQ_MESSAGES" bindings-table="AMQ_BINDINGS"
jms-bindings-table="AMQ_JMS_BINDINGS" large-messages-table="AMQ_LARGE_MESSAGES" page-store-table="AMQ_PGSTORE"/>
</server>
</subsystem>
Here is a portion of the log output:
18:36:27,116 INFO [org.wildfly.extension.messaging-activemq] (MSC service thread 1-8) WFLYMSGAMQ0001: AIO wasn't located on this platform, it will fall back to using pure Java NIO.
18:36:27,665 INFO [org.wildfly.extension.undertow] (MSC service thread 1-1) WFLYUT0006: Undertow HTTPS listener https listening on 127.0.0.1:443
18:36:27,808 INFO [org.jboss.ws.common.management] (MSC service thread 1-7) JBWS022052: Starting JBossWS 5.2.4.Final (Apache CXF 3.2.5.jbossorg-1)
18:36:27,964 DEBUG [org.apache.activemq.artemis.jdbc.store.journal.JDBCJournalImpl] (MSC service thread 1-8) Detect database dialect as 'MSSQL'.
18:36:27,968 INFO [org.wildfly.extension.messaging-activemq] (MSC service thread 1-8) use JDBC store for Artemis server, bindingsTable:AMQ_BINDINGS
18:36:28,065 DEBUG [org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl] (ServerService Thread Pool -- 80) Starting server ActiveMQServerImpl::
18:36:28,069 DEBUG [org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl] (ServerService Thread Pool -- 80) Detected no Shared Store HA options on JDBC store
18:36:28,121 INFO [org.apache.activemq.artemis.core.server] (ServerService Thread Pool -- 80) AMQ221000: live Message Broker is starting with configuration Broker Configuration (clustered=false,jdbcDriverClassName=org.apache.derby.jdbc.EmbeddedDriver,jdbcConnectionUrl=null,messageTableName=AMQ_MESSAGES,bindingsTableName=AMQ_BINDINGS,largeMessageTableName=AMQ_LARGE_MESSAGES,pageStoreTableName=AMQ_PSTORE,)
18:36:28,306 DEBUG [org.apache.activemq.artemis.jdbc.store.journal.JDBCJournalImpl] (ServerService Thread Pool -- 80) Detect database dialect as 'MSSQL'.
18:36:28,398 ERROR [org.apache.activemq.artemis.jdbc.store.drivers.AbstractJDBCDriver] (ServerService Thread Pool -- 80)
SQL STATEMENTS:
CREATE TABLE AMQ_LARGE_MESSAGES (ID BIGINT AUTO_INCREMENT, FILENAME VARCHAR(255), EXTENSION VARCHAR(10), DATA BLOB, PRIMARY KEY(ID))
SQL EXCEPTIONS:
SQLState: S0001 ErrorCode: 102 Message: Incorrect syntax near 'AUTO_INCREMENT'.
18:36:28,425 WARN [org.apache.activemq.artemis.core.server] (ServerService Thread Pool -- 80) AMQ222010: Critical IO Error, shutting down the server. file=NULL, message=Unable to start database driver: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'AUTO_INCREMENT'.
at com.microsoft.sqlserver.jdbc//com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:262)
at com.microsoft.sqlserver.jdbc//com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1621)
at com.microsoft.sqlserver.jdbc//com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:868)
at com.microsoft.sqlserver.jdbc//com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:768)
at com.microsoft.sqlserver.jdbc//com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7194)
at com.microsoft.sqlserver.jdbc//com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2935)
at com.microsoft.sqlserver.jdbc//com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:248)
at com.microsoft.sqlserver.jdbc//com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:223)
at com.microsoft.sqlserver.jdbc//com.microsoft.sqlserver.jdbc.SQLServerStatement.executeUpdate(SQLServerStatement.java:711)
at org.jboss.ironjacamar.jdbcadapters#1.4.11.Final//org.jboss.jca.adapters.jdbc.WrappedStatement.executeUpdate(WrappedStatement.java:430)
at org.apache.activemq.artemis#2.6.3.jbossorg-00014//org.apache.activemq.artemis.jdbc.store.drivers.AbstractJDBCDriver.createTableIfNotExists(AbstractJDBCDriver.java:258)
at org.apache.activemq.artemis#2.6.3.jbossorg-00014//org.apache.activemq.artemis.jdbc.store.drivers.AbstractJDBCDriver.createTable(AbstractJDBCDriver.java:118)
at org.apache.activemq.artemis#2.6.3.jbossorg-00014//org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactoryDriver.createSchema(JDBCSequentialFileFactoryDriver.java:69)
at org.apache.activemq.artemis#2.6.3.jbossorg-00014//org.apache.activemq.artemis.jdbc.store.drivers.AbstractJDBCDriver.start(AbstractJDBCDriver.java:83)
at org.apache.activemq.artemis#2.6.3.jbossorg-00014//org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory.start(JDBCSequentialFileFactory.java:131)
at org.apache.activemq.artemis#2.6.3.jbossorg-00014//org.apache.activemq.artemis.core.persistence.impl.journal.JDBCJournalStorageManager.init(JDBCJournalStorageManager.java:92)
at org.apache.activemq.artemis#2.6.3.jbossorg-00014//org.apache.activemq.artemis.core.persistence.impl.journal.AbstractJournalStorageManager.<init>(AbstractJournalStorageManager.java:229)
at org.apache.activemq.artemis#2.6.3.jbossorg-00014//org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager.<init>(JournalStorageManager.java:106)
at org.apache.activemq.artemis#2.6.3.jbossorg-00014//org.apache.activemq.artemis.core.persistence.impl.journal.JDBCJournalStorageManager.<init>(JDBCJournalStorageManager.java:55)
at org.apache.activemq.artemis#2.6.3.jbossorg-00014//org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.createStorageManager(ActiveMQServerImpl.java:2155)
at org.apache.activemq.artemis#2.6.3.jbossorg-00014//org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.initialisePart1(ActiveMQServerImpl.java:2296)
at org.apache.activemq.artemis#2.6.3.jbossorg-00014//org.apache.activemq.artemis.core.server.impl.LiveOnlyActivation.run(LiveOnlyActivation.java:64)
at org.apache.activemq.artemis#2.6.3.jbossorg-00014//org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.internalStart(ActiveMQServerImpl.java:535)
at org.apache.activemq.artemis#2.6.3.jbossorg-00014//org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.start(ActiveMQServerImpl.java:474)
at org.apache.activemq.artemis#2.6.3.jbossorg-00014//org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl.start(JMSServerManagerImpl.java:376)
at org.wildfly.extension.messaging-activemq//org.wildfly.extension.messaging.activemq.jms.JMSService.doStart(JMSService.java:206)
at org.wildfly.extension.messaging-activemq//org.wildfly.extension.messaging.activemq.jms.JMSService.access$000(JMSService.java:65)
at org.wildfly.extension.messaging-activemq//org.wildfly.extension.messaging.activemq.jms.JMSService$1.run(JMSService.java:100)
It appears that even though the dialect is correctly detected as MSSQL the broker doesn't have the corresponding SQL statements to properly support it. The SQL statements for MSSQL were added in ActiveMQ Artemis 2.6.4 via ARTEMIS-2202. You're using 2.6.3 so you don't have those.
Upgrading ActiveMQ Artemis in Wildfly can sometimes fail due to the tight coupling between the two so if you don't want to try upgrading you could theoretically crack open the artemis-jdbc-store jar file and add/replace these lines to journal-sql.properties
# MSSQL SQL statements
create-file-table.mssql=CREATE TABLE %s (ID BIGINT NOT NULL IDENTITY, FILENAME VARCHAR(255), EXTENSION VARCHAR(10), DATA VARBINARY(max), PRIMARY KEY(ID))
create-journal-table.mssql=CREATE TABLE %s(id BIGINT,recordType SMALLINT,compactCount SMALLINT,txId BIGINT,userRecordType SMALLINT,variableSize INTEGER,record VARBINARY(max),txDataSize INTEGER,txData VARBINARY(max),txCheckNoRecords INTEGER,seq BIGINT NOT NULL, PRIMARY KEY(seq))
max-blob-size.mssql=2147483647
Regarding the AMQ221000 log message that indicates there is an incorrect JDBC driver configuration...This is due to the fact that the ActiveMQ Artemis broker has its own JDBC driver configuration for when it's running standalone. When it's embedded in Wildfly and configured to use a datasource via JNDI then the standalone JDBC driver configuration isn't used. It will simply look up the specified datasource and use that.

Failed to read challenge file [Caused by java.io.FileNotFoundException: /jboss/standalone/tmp/auth/local4123__.challenge (No such file or directory)

I am trying to connect two machines both running JBoss EAP 7.1.0 using a JMS bridge. Machine 1 is to act as a web server and has a WAR file deployed which is accessible, and Machine 2 is to act as the app server and has all the necessary components deployed just fine.
This is the error I am receiving:
WARN [org.apache.activemq.artemis.jms.bridge] (ServerService Thread Pool -- 72) AMQ342010: Failed to connect JMS Bridge N/A: javax.naming.CommunicationException: WFNAM00018: Failed to connect to remote host [Root exception is javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed:
JBOSS-LOCAL-USER: javax.security.sasl.SaslException: ELY05128: [JBOSS-LOCAL-USER] Failed to read challenge file [Caused by java.io.FileNotFoundException: /.../.../jboss/standalone/tmp/auth/local3093626581916142639.challenge (No such file or directory)]]
at org.wildfly.naming.client.remote.RemoteNamingProvider.getPeerIdentityForNaming(RemoteNamingProvider.java:110)
at org.wildfly.naming.client.remote.RemoteNamingProvider.getPeerIdentityForNaming(RemoteNamingProvider.java:53)
at org.wildfly.naming.client.NamingProvider.getPeerIdentityForNamingUsingRetry(NamingProvider.java:105)
at org.wildfly.naming.client.remote.RemoteNamingProvider.getPeerIdentityForNamingUsingRetry(RemoteNamingProvider.java:91)
at org.wildfly.naming.client.remote.RemoteContext.lambda$lookupNative$0(RemoteContext.java:189)
at org.wildfly.naming.client.NamingProvider.performExceptionAction(NamingProvider.java:222)
at org.wildfly.naming.client.remote.RemoteContext.performWithRetry(RemoteContext.java:100)
at org.wildfly.naming.client.remote.RemoteContext.lookupNative(RemoteContext.java:188)
at org.wildfly.naming.client.AbstractFederatingContext.lookup(AbstractFederatingContext.java:74)
at org.wildfly.naming.client.AbstractFederatingContext.lookup(AbstractFederatingContext.java:60)
at org.wildfly.naming.client.WildFlyRootContext.lookup(WildFlyRootContext.java:144)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at org.apache.activemq.artemis.jms.bridge.impl.JNDIFactorySupport.createObject(JNDIFactorySupport.java:46)
at org.apache.activemq.artemis.jms.bridge.impl.JNDIDestinationFactory.createDestination(JNDIDestinationFactory.java:32)
at org.apache.activemq.artemis.jms.bridge.impl.JMSBridgeImpl.setupJMSObjects(JMSBridgeImpl.java:1072)
at org.apache.activemq.artemis.jms.bridge.impl.JMSBridgeImpl.start(JMSBridgeImpl.java:398)
at org.wildfly.extension.messaging.activemq.jms.bridge.JMSBridgeService.startBridge(JMSBridgeService.java:114)
at org.wildfly.extension.messaging.activemq.jms.bridge.JMSBridgeService$1.run(JMSBridgeService.java:84)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
The connection to the target machine (application server) is being made as the path to JBoss is that of the path on the machine, which I verified by testing with a Windows application server environment and the path was the correct Windows path to the directory where the challenge file should be, so clearly the connection is being made as the directories are being accessed. However, the .challenge file isn't present each time which understandably causes the error message.
I have scoured SO and JBoss forums for days now and nothing is resolving my issue.
I saw this post: JBOSS-LOCAL-USER: javax.security.sasl.SaslException: Failed to read server challenge
This is the same issue that I am facing, but the answer which was marked as correct doesn't help me very much. The solution, in this case, was to replace the default ApplicationRealm with a JAAS realm, but I do not know if this is what I need, and I certainly do not currently have one. I did research it, but it seemed to not be applicable to my setup, but I could be wrong.
I also tried this solution: https://access.redhat.com/solutions/3209281 (Subscription only access)
This solution was to remove default-user="$local" from here:
<security-realm name="ApplicationRealm">
<authentication>
<local default-user="$local" allowed-users="*" skip-group-loading="true"/>
I did this to both standalone-full.xml files on both machines, and it appeared to make no difference at all.
I have created application users on both machines and given them superuser privileges through the JBoss console as I figured it was probably an issue with permissions when trying to write the file but this too was to no avail. I have also verified that both user credentials are correct.
The workaround was to switch to using a core bridge instead of a JMS bridge, as per the recommendation from Justin in the comments.

jboss connection pool doesn't handle errors gracefully

I'm using jboss 5.0.1 with multiple data sources configured.
It seems that on startup, if one of those is configured incorrectly, jboss throws an exception and refuses to start.
I would like to know if it's possible to configure jboss to be resilient to these kind of problems.
You can configure the connections in the xml file which holds the connection parameters/mapping. In my case, i am using a microsoft sql server as the datasource, so i have to use the mssql-ds.xml file (inside the server/deploy directory) to specify:
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>myTestServer</jndi-name>
<connection-url>jdbc:sqlserver://xxx.xxx.xxx.xxx:1433;databaseName=MyDB</connection-url>
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
<user-name>test</user-name>
<password>abc123</password>
<min-pool-size>10</min-pool-size>
<max-pool-size>25</max-pool-size>
<!-- sql to call when connection is created -->
<new-connection-sql>select getdate()</new-connection-sql>
<!-- -->
<!-- sql to call on an existing pooled connection when it is obtained from pool
This will be run before a managed connection is removed from the pool
for use by a client -->
<check-valid-connection-sql>select getdate()</check-valid-connection-sql>
</local-tx-datasource>
</datasources>
This helps control the connections in the pool, and should stop dodgy deadlocks. I'm not entirely sure whether this will test the current transaction level on the connection in question, so if you want to make absolutely sure, you can try: <check-valid-connection-sql>IF ##TRANCOUNT > 0 raiserror ('%s',18,1,'Open Transactions Discovered')</check-valid-connection-sql> This will give you an explicit SQLException to handle.
But if you are getting an error on startup, it would be very useful to see what those errors are.

Connection pooling on a Tomcat 7

I am having issues with implementing connection pooling on a tomcat7.
For some reason tomcat is trying to connect with my machines username. I have been googlin it for a while now but without a luck.
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory
(FATAL: role "caspinol" does not exist)
Cant connect to db
Log In failed: An Exception has occurred! java.lang.NullPointerException
java.lang.NullPointerException
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)...
My context.xml looks as follows:
<Resource auth="Container" name="jdbc/postgres" type="javax.sql.DataSource" user="biller" password="biller"
driverClassName="org.postgresql.Driver" url="jdbc:postgresql://localhost:5432" maxActive="150"
schema="biller" maxIdle="4"/>
And the web.xml:
<resource-ref>
<description>postgreSQL Datasource</description>
<res-ref-name>jdbc/postgres</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
I am using jdbc4.jar postgres driver.
I appreciate if somebody can have a look and point out what is the mistake
Thanks in advance
The URL seems to be wrong.
Try this URL :
jdbc:postgresql://localhost:5432/<db_name>
Replace the <db_name> with actual database name.
This is not the right solution here for the issue but would help somebody searching with the same issue with correct connection string.
Check for your network connection access:
Like connection string
jdbc:postgresql://[::1]:5432/<db_name>
uses IPv6,
This will break other connections like accessing wsdl urls from application that are available only via IPv4.
Please hava a look on network connection especially windows 8.