WL6.1 Deploying sql adapter with dataSourceJNDIName give error Runtime: Datasource not found in jndi - websphere

i am deploying an sql adapter on was liberty 8.5.5. i'm trying to connect to the APPCNTR database installed with WL.
the datasource name declared in server.xml :
<dataSource jndiName="jdbc/AppCenterDS" transactional="false">
<jdbcDriver libraryRef="MySQLLib"/>
<properties URL="jdbc:mysql://127.0.0.1:3306/APPCNTR" user="ibmappcenter" password="xxxx"/>
</dataSource>
the adapter xml :
<connectivity>
<connectionPolicy xsi:type="sql:SQLConnectionPolicy">
<dataSourceJNDIName>java:comp/env/jdbc/AppCenterDS</dataSourceJNDIName>
</connectionPolicy>
<loadConstraints maxConcurrentConnectionsPerNode="5" />
</connectivity>
the error in javascript console : Runtime: Datasource java:comp/env/jdbc/AppCenterDS not found in jndi
what is the correct syntax ?
do i miss something while deploying the application?
thanks for your help
regards,

I know that the generated files has
<dataSourceJNDIName>java:/data-source-jndi-name</dataSourceJNDIName>
as the model, but I've never been able to get that to work. It should work with the simple name:
<dataSourceJNDIName>jdbc/AppCenterDS</dataSourceJNDIName>

Related

SpringBoot and IBM MQ connection properties not overrided on deploy

I've a SpringBoot App with a local configuration to connect and listen a local Queue
ibm:
mq:
queueManager: LOCAL_QM
channel: DEV.ADMIN.SVRCONN
connName: localhost(1414)
user: admin
password: passw0rd
user-authentication-m-q-c-s-p: false
When a I deploy the app with Gitlab CI some properties are overrided (with a war_name.xml file in ../tomcat/current/conf/Catalina/localhost/) like database connection properties and mq connection properties to listen a Developpement or Qualification environment queue.
But when the app start the database connection is OK but not the MQ connection (The app use the local connection properties defined in the application.yml file)
When I check the xml file on the remote server, the properties are override.
And when I use a tool like spring actuator, I have the right properties override with the specific env properties.
But in the logs: /tomcat/current/logs/catalina.out I can read that the app try to connect to the local queue manage : LOCAL_QM not the specific environment queue.
2021-05-11 12:19:23.484 ERROR 14483 --- [ntContainer#0-1] o.s.j.l.DefaultMessageListenerContainer : Could not refresh JMS Connection for destination '***' - retrying using FixedBackOff{interval=5000, currentAttempts=16093, maxAttempts=unlimited}. Cause: JMSWMQ0018: Failed to connect to queue manager 'LOCAL_QM' with connection mode 'Client' and host name 'localhost(1414)'.; nested exception is com.ibm.mq.MQException: JMSCMQ0001: IBM MQ call failed with compcode '2' ('MQCC_FAILED') reason '2538' ('MQRC_HOST_NOT_AVAILABLE')
The properties are in the same xml file, it works for the database "spring.datasource" but not for MQ "ibm.mq"
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Environment name="spring.datasource.url" value="jdbc:postgresql://***:5432/**" type="java.lang.String"/>
<Environment name="spring.datasource.username" value="****" type="java.lang.String"/>
<Environment name="spring.datasource.password" value="****" type="java.lang.String"/>
<Environment name="ibm.mq.queueManager" value="***" type="java.lang.String"/>
<Environment name="ibm.mq.channel" value="***" type="java.lang.String"/>
<Environment name="ibm.mq.connName" value="***" type="java.lang.String"/>
<Environment name="ibm.mq.user" value="***" type="java.lang.String"/>
<Environment name="ibm.mq.password" value="" type="java.lang.String"/>
</Context>
Any idea why the properties are not overrided ?
Thanks
This started out as a comment, but as I wrote it I suspected that you are missing the relevant ibm.mq properties. If you don't provide the following properties:
ibm.mq.queueManager
ibm.mq.channel
ibm.mq.connName
ibm.mq.user
ibm.mq.password
then they default to
ibm.mq.queueManager=QM1
ibm.mq.channel=DEV.ADMIN.SVRCONN
ibm.mq.connName=localhost(1414)
ibm.mq.user=admin
ibm.mq.password=passw0rd
ie. localhost.
The mq-jms-spring-boot-starter makes use of
import org.springframework.boot.context.properties.ConfigurationProperties;
#ConfigurationProperties(prefix = "ibm.mq")
to read the connection properties. In this module https://github.com/ibm-messaging/mq-jms-spring/blob/master/mq-jms-spring-boot-starter/src/main/java/com/ibm/mq/spring/boot/MQConfigurationProperties.java
So it relies on spring to make the properties prefixed with ibm.mq available to it. ie. As long as spring through #ConfigurationProperties knows how to handle the overrides it will make them available to mq-jms-spring-boot-starter.

Configure default data source for Arquillain Test in OpenLiberty

I started a new ejb branch to add some simple Ejb and JPA codes.
Java EE 6/7 should include a default data source via java:comp/DefaultDataSource, but it is not available in OpenLiberty by default.
I added the following config to server.xml to provide a DefaultDataSource.
<!-- Derby Library Configuration -->
<library id="derbyJDBCLib">
<fileset dir="${shared.resource.dir}" includes="derby*.jar"/>
</library>
<!-- Datasource Configuration -->
<!-- remove jndiName="" to serve java:comp/DefaultDataSource for Java EE 7 or above -->
<dataSource id="DefaultDataSource">
<jdbcDriver libraryRef="derbyJDBCLib" />
<properties.derby.embedded databaseName="ExampleDb" createDatabase="create"/>
</dataSource>
The derby lib is prepared by Maven dependency plugin, see here.
When running the codes, I got a deployment Timeout exception.
Check the details here.
Update: resolved via issue OpenLiberty/liberty-arquillian#94.
Add an appDeployTimeout into arquillian.xml.
<property name="appDeployTimeout">120</property>

Application is not working in WebSphere

I deployed WAR file on Websphere console and mapped it to datasource. I am able to test the datasource which I configured with PostgreSQL server details. But my application is not connecting to the server. I am new to WebSphere and could anyone please help me to configure the datasource based on the below context.xml file. My application works well in tomcat but not in Websphere.
I think am doing something wrong in the datasource configuration.
<Resource
name="jdbc/domains/ABC" url="jdbc:postgresql://localhost:5432/postgres"
initConnectionSqls="SET search_path TO my_schme;"
username="abccc"
password="******"
auth="Container"
type="javax.sql.DataSource"
driverClassName="org.postgresql.Driver"
validationQuery="select 1"
initialSize="5"
maxActive="20"
maxIdle="10"
maxWait="-1"
/>
Here is an example based on the most common way to configure data sources in WebSphere Application Server Liberty -- in server.xml (it is also possible to define within the application via the standard #DataSourceDefinition annotation or deployment descriptor, which would be a separate example)
In server.xml,
<featureManager>
<feature>jdbc-4.2</feature>
<feature>jndi-1.0</feature>
... other features
</featureManager>
<dataSource id="ABC" jndiName="jdbc/domains/ABC" type="javax.sql.ConnectionPoolDataSource" validationTimeout="30s">
<jdbcDriver libraryRef="PostGreLib" javax.sql.ConnectionPoolDataSource="org.postgresql.ds.PGConnectionPoolDataSource"/>
<properties url="jdbc:postgresql://localhost:5432/postgres"/>
<containerAuthData user="abccc" password="******"/>
<connectionManager maxPoolSize="20" connectionTimeout="-1"/>
<!-- no equivalents for initialSize and maxIdle -->
<onConnect>SET search_path TO my_schme;</onConnect>
</dataSource>
<library id="PostGreLib">
<file name="C:/PostGreSQL/postgresql-42.1.4.jar"/>
</library>
Here are some helpful knowledge center articles on data source configuration in WebSphere Application Server Liberty,
https://www.ibm.com/support/knowledgecenter/en/SSEQTP_liberty/com.ibm.websphere.wlp.doc/ae/twlp_dep_configuring_ds.html
https://www.ibm.com/support/knowledgecenter/en/SSEQTP_liberty/com.ibm.websphere.liberty.autogen.base.doc/ae/rwlp_feature_jdbc-4.2.html

Configuring Oracle dataSource settings on WAS Liberty (WL ) - failure

I am receiving below exception. on Liberty console & in browser.
javax.servlet.ServletException: Worklight Console initialization failed.Logged Exception: com.worklight.server.database.api.WorklightDataSourceException: FWLSE0194E: MobileFirst Server cannot be started because of failure while getting a connection from data-source bound to resource reference: jdbc/WorklightDS. Make sure the database is up, the credentials are correct and the driver is available for the server. [project worklight]
at com.worklight.core.auth.impl.AuthenticationFilter.verifyServletInitialized(AuthenticationFilter.java:451)
at com.worklight.core.auth.impl.AuthenticationFilter.doFilter(AuthenticationFilter.java:138)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:194)
at [internal classes]
When running/viewing an app (war) on a UAT machine having below configuration.
Environment:
WL 6.3 EE
WAS Liberty Core V8.5.5.4
Oracle 11g
Windows Server 2012 R2
worklight.properties
publicWorkLightHostname=localhost
publicWorkLightProtocol=http
publicWorkLightPort=9080
wl.db.url=jdbc:oracle:thin:#10.100.11.1:1529:gmaxem
wl.db.username=WRKLIGHT
wl.db.password=wrklight
wl.reports.db.url=jdbc:oracle:thin:#10.100.11.1:1529:gmaxem
wl.reports.db.username=WLRREPOR
wl.reports.db.password=wlrrepor
Web.xml
<resource-ref>
<description>Worklight Server Database</description>
<res-ref-name>jdbc/WorklightDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
<description>Reports Database</description>
<res-ref-name>jdbc/WorklightReportsDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Liberty - server.xml
<application id="worklight" name="worklight" location="myapp.war" type="war" context-root="/worklight" >
<classloader delegation="parentLast">
<privateLibrary id="worklightlib_worklight">
<fileset dir="${shared.resource.dir}/lib" includes="worklight-jee-library.jar"/>
</privateLibrary>
</classloader>
</application>
<jndiEntry value="9080" jndiName="publicWorkLightPort"/>
<jndiEntry value="localhost" jndiName="publicWorkLightHostname"/>
<jndiEntry value="http" jndiName="publicWorkLightProtocol"/>
<jndiEntry value="10" jndiName="serverSessionTimeout"/>
<library id="OracleLib">
<fileset dir="${shared.resource.dir}/oracle" includes="*.jar"/>
</library>
<dataSource jndiName="jdbc/AppCenterDS" transactional="false">
<jdbcDriver libraryRef="OracleLib"/>
<properties.oracle driverType="thin" URL="jdbc:oracle:thin:#10.100.11.1:1529:gmaxem" user="WLAPPCENTER" password="wlappcenter"/>
</dataSource>
<dataSource jndiName="worklight/jdbc/WorklightDS" transactional="false">
<jdbcDriver libraryRef="OracleLib" />
<properties.oracle driverType="thin" url="jdbc:oracle:thin:#10.100.11.1:1529:gmaxem" user="WRKLIGHT" password="wrklight" />
</dataSource>
<dataSource jndiName="worklight/jdbc/WorklightReportsDS" transactional="false">
<jdbcDriver libraryRef="OracleLib" />
<properties.oracle driverType="thin" url="jdbc:oracle:thin:#10.100.11.1:1529:gmaxem" user="WLRREPOR" password="wlrrepor" />
</dataSource>
I have also copied:
jdbc jar (ojdbc6.jar) at Liberty\usr\shared\resources\oracle
worklight-jee-library.jar at Liberty\usr\shared\resources\lib
myapp.war at Liberty\usr\servers\WorklightServer\apps
The apps folder on Liberty contains only these 3 war files.
myapp.war
appcenterconsole.war
applicationcenter.war
The error message mentions jdbc/WorklightDS, therefore the configuration mistake must be in the <dataSource jndiName="worklight/jdbc/WorklightDS" ...> element.
You are using the syntax url="jdbc:oracle:thin:#//10.100.11.1:1529/WRKLIGHT" which is the syntax for a JDBC URL with a service name, but WRKLIGHT is probably not the service name but the SID of your database. (Service names usally include some dots.)
You have two options:
Use the syntax which references the SID: url="jdbc:oracle:thin:#10.100.11.1:1529:WRKLIGHT"
Look up the service name in the file ORACLE_HOME\network\admin\tnsnames.ora, and use this service name in the URL, instead of WRKLIGHT.
Error in update 2: javax.servlet.ServletException: Worklight Console initialization failed.Logged Exception: java.lang.RuntimeException: FWLSE0206E: The project /worklight failed to initialize, because the project database schema for data source jdbc:oracle:thin:#10.100.11.1:1529:gmaxem is from version N/A, which is not supported by the server from version 6.3.0.00.20141127-1357. Use the MobileFirst ant tasks to upgrade the project database schema. [project worklight
This means that the connection to the database worked but that the tables that are expected to be in the table were not found.
If you install manually, you need to create the schema of the tables.
https://www-01.ibm.com/support/knowledgecenter/SSHS8R_6.3.0/com.ibm.worklight.installconfig.doc/admin/t_config_oracle_DB_manually_for_wladmin.html
Solved
This issue has been resolved.
Unfortunately my client had not created WLADMIN database at all and I was told that it does exists. Plus app center database was having wrong tables created as I mentioned in another post.
I was not given privileges to install any db tool to interact/see the databases structure.
Note: - The above mentioned configuration is correct and is working fine.
might be useful to someone, it should be '/' separator for port name and service name
<dataSource beginTranForResultSetScrollingAPIs="true" beginTranForVendorAPIs="false" commitOrRollbackOnCleanup="rollback" connectionManagerRef="default-conn-mgr" isolationLevel="TRANSACTION_READ_COMMITTED" jndiName="jdbc/test" transactional="true" type="javax.sql.ConnectionPoolDataSource">
<jdbcDriver libraryRef="oracleJDBCJars"/>
<properties.oracle URL="jdbc:oracle:thin:#my-host.name.xxx.com:portnumber/service.name.com" password="xxx" user="test_usr"/>

JNDI with JMS in jdeveloper 11g

I'm trying to start JMS application from OAS 10.1.2 to BeaWebLogic 11g
but there is a problem locating the JMS JNDI's.
When I start the server this exception is thrown:
weblogic.application.ModuleException: Could not setup environment
at weblogic.servlet.internal.WebAppModule.activateContexts(WebAppModule.java:1495)
at weblogic.servlet.internal.WebAppModule.activate(WebAppModule.java:438)
at weblogic.application.internal.flow.ModuleStateDriver$2.next(ModuleStateDriver.java:375)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
at weblogic.application.internal.flow.ModuleStateDriver.activate(ModuleStateDriver.java:95)
Truncated. see log file for complete stacktrace
Caused By: javax.naming.NamingException: Cannot bind null object to jndi with name jms/TopicJNDI
at weblogic.jndi.internal.BasicNamingNode.bind(BasicNamingNode.java:311)
at weblogic.jndi.internal.WLEventContextImpl.bind(WLEventContextImpl.java:277)
at weblogic.deployment.EnvironmentBuilder.addConnectorRef(EnvironmentBuilder.java:277)
at weblogic.deployment.EnvironmentBuilder.addResourceReferences(EnvironmentBuilder.java:169)
at weblogic.servlet.internal.CompEnv.activate(CompEnv.java:138)
Truncated. see log file for complete stacktrace
The jndi which I have mapped in the BWL console is jms/Topic.
I recieved this error on server start up:
<An entity of type "ConnectionFactories" withname "Demo Topic Connection Factory" in JMS module "jmsModule" is not targeted. There is no sub-deployment with name "Demo Topic Connection Factory" in the configuration repository (config.xml), and so this entity will not exist anywhere in the domain.>
Thanks in advance.
The answer of my question is here
Here is how I got it to work.
Add the following line to the weblogic.xml file.
<resource-description>
<res-ref-name>MyDataSourceRefName<res-ref-name>
<jndi-name>jdbc/MyDataSourceNameAsDefinedInWeblogic</jndi-name>
</resource-description>
Then add the following to your web.xml file
<resource-ref>
<description>Some description</description>
<res-ref-name>MyResourceRefName</res-ref-name>
<res-type>javax.sql.Datasource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
After I did that, everything worked fine. Additionally, if you are trying to configure Spring to use this data source, add the following bean.
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>MyDataSourceRefName</value>
</property>
</bean>
Then use your data source a appropriate. I hope this helps.

Resources