Websphere liberty 19 configure jndi datasource - websphere-liberty

I have deployed two ears and to one of them i do not have access.
There is a file
application-web-bnd.xml where is reference to datasource
In my server.xml file i have defined datasource
<application id="MyCustomApp.war" location="F:\programming\source\MyCustomApp\target\MyCustomApp" name="MyCustomApp" type="war">
<application-bnd>
<security-role name="admin">
<special-subject type="ALL_AUTHENTICATED_USERS" />
</security-role>
<data-source binding-name="jdbc/Sample" name="java:comp/env/jdbc/db" />
</application-bnd>
</application>
<dataSource id="Sample" jndiName="jdbc/Sample" type="javax.sql.DataSource">
<jdbcDriver>
<library name="JdbcJarFiles">
<fileset dir="${shared.resource.dir}" includes="db2jcc4.jar, db2jcc_license_cisuz.jar, db2jcc_license_cu.jar, pdq.jar, pdqmgmt.jar" />
<folder dir="${shared.resource.dir}" />
</library>
</jdbcDriver>
</dataSource>
In code in ear where i do not have access there is initialContext
java:comp/env/jdbc/db.
Reference to data source exists but datasource does not exists.
I do not have access to web.xml for create reference .
I do not have ide how override it.
Could You help ?
My ear looks that:
<module>
<ejb>PRE-BF.jar</ejb>
</module>
<module>
<web>
<web-uri>PRE-WS.war</web-uri>
<context-root>/PRE-WS</context-root>
</web>
</module>
<module>
<web>
<web-uri>PRE-RS.war</web-uri>
<context-root>/PRE-RS</context-root>
</web>
</module>
<module>
<web>
<web-uri>PRE-PF.war</web-uri>
<context-root>/PRE-PF</context-root>
</web>
</module>

You can override bindings in server configuration as follows. (This will require having your application defined in server configuration rather than dropins).
<application location="MyApp.war">
<web-bnd moduleName="MyApp">
<resource-ref name="jdbc/Sample" binding-name="java:comp/env/jdbc/db"/>
</web-bnd>
</application>

Related

Define class loader for web application with Liberty

I have an application Rest service it is a war I want to deploy it in Liberty profile.Currently I am packaging the app along with all spring jar inside war.
But we want to create a shared library and move all those jar's into shared lib and reference that shared library using class loader from application.
server.xml
<application location ="restapp-1.0.0-SNAPSHOT.war" context-root="/myrestapp/mytestapp">
<classloader commonLibraryRef="global"/>
</application>
<library id="global">
<fileset includes="*.jar" dir="${server.config.dir}/lib/global"></fileset>
</library>
Also I have placed all the jar dependencies under server/config/lib/global.
I am having below entries in my ibm-web-ext.xml which is in webapp/WEB-INF/
<web-ext
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-ext_1_0.xsd"
version="1.0">
<reload-interval value="3"/>
<context-root uri="/myrestapp/mytestapp" />
<enable-directory-browsing value="false"/>
<enable-file-serving value="true"/>
<enable-reloading value="true"/>
<enable-serving-servlets-by-class-name value="false" />
</web-ext>
Same config is working fine if I bundle all the jar's as part of WAR and place the war in dropins folder. But Sharedlibrary configuration is not working.
You can define a shared library for your application in WebSphere Liberty by putting the following configuration in the server.xml:
<library id="springLib">
<fileset dir="${server.config.dir}/libs/spring/" includes="*.jar"/>
</library>
<application location ="restService.war">
<classloader commonLibraryRef="springLib"/>
</application>
With this configuration, code in the restService.war will be able to load classes from the springLib shared library.
See also: Liberty: Shared Libraries

Multiple DataSource into Websphere Liberty Profile

Is it possible to declare multiple DataSources into Websphere Liberty Profile server.xml ? any examples ?
I try to do it but I can see only one. When the second one is looked up I have an error message that says the jndi name is not found.
My server.xml :
<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>webProfile-7.0</feature>
<feature>jndi-1.0</feature>
<feature>jdbc-4.0</feature>
</featureManager>
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint id="defaultHttpEndpoint"
httpPort="9080"
httpsPort="9443" />
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>
<!-- Configuration for DSPB -->
<jndiEntry jndiName="dspb/configuration/files" value="classpath:properties/dspb.properties,classpath:properties/dspb_db_connector.properties" />
<dataSource id="ds1" jndiName="DB_DSPB_ACTIVITI" connectionManagerRef="connectionManager1" jdbcDriverRef="MyJDBCDriver">
<properties.oracle driverType="thin" databaseName="xe"
serverName="localhost" portNumber="1521"
user="dspb_activiti" password="dspb_activiti"/>
</dataSource>
<dataSource id="ds2" jndiName="DB_DSPB" connectionManagerRef="connectionManager2" jdbcDriverRef="MyJDBCDriver">
<properties.oracle driverType="thin" databaseName="xe"
serverName="localhost" portNumber="1521"
user="dspb" password="dspb"/>
</dataSource>
<connectionManager id="connectionManager1" maxPoolSize="20" minPoolSize="5"
connectionTimeout="10s" agedTimeout="30m"/>
<connectionManager id="connectionManager2" maxPoolSize="20" minPoolSize="5"
connectionTimeout="10s" agedTimeout="30m"/>
<jdbcDriver id="MyJDBCDriver">
<library>
<fileset dir="C:/oraclexe/app/oracle/product/11.2.0/server/jdbc/lib/" includes="ojdbc6.jar"/>
</library>
</jdbcDriver>
</server>
And the definitions in web.xml :
<resource-ref>
<res-ref-name>DB_DSPB</res-ref-name>
<res-type>javax.sql.ConnectionPoolDataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-ref>
<res-ref-name>DB_DSPB_ACTIVITI</res-ref-name>
<res-type>javax.sql.ConnectionPoolDataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-ref>
<res-ref-name>dspb/configuration/files</res-ref-name>
<res-auth>Container</res-auth>
</resource-ref>
And I can only see DSPB in jconsole view : http://i.stack.imgur.com/euN8e.jpg
What's wrong ?
So, the ibm-web-bnd.xml was missing, cheaty thing...
<web-bnd
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">
<resource-ref name="DB_DSPB" binding-name="DB_DSPB"/>
<resource-ref name="DB_DSPB_ACTIVITI" binding-name="DB_DSPB_ACTIVITI"/>
Eric
Yes this is possible. Simply specify separate <dataSource> elements in your server.xml.
For example:
<dataSource id="ds1" jndiName="jdbc/ds1" jdbcDriverRef="MyJDBCDriver">
<properties ... />
</dataSource>
<dataSource id="ds2" jndiName="jdbc/ds2" jdbcDriverRef="MyJDBCDriver">
<properties ... />
</dataSource>
Note that both datasources have a jdbcDriverRef on them, which corresponds to the ID of a <jdbcDriver> element. This is convenient so you don't have to specify another JDBCDriver each time you want to declare a <dataSource>.
<jdbcDriver id="MyJDBCDriver">
<library>
<fileset dir="${server.config.dir}/jdbcDrivers" includes="driver.jar"/>
</library>
</jdbcDriver>
Alternatively, you can nest <jdbcDriver> elements under a datasource if you choose to. This would be ideal if you never share a <jdbcDriver> between multiple <dataSource> elements.
<dataSource id="ds1" jndiName="jdbc/ds1">
<properties ... />
<jdbcDriver>
<library>
<fileset dir="${server.config.dir}/jdbcDrivers" includes="someJDBCDriver.jar"/>
</library>
</jdbcDriver>
</dataSource>
Here a link to the official IBM doc: Configuring database connectivity in Liberty

WebSphere Liberty Profile: Context Root Not Found

I can't seem to get this working locally, even though the same WAR works on a remote server. When I go to visit my application locally, I get the "Context Root Not Found" error. The Liberty profile version is 8.5.5.5.
Here are the relevant files:
server.xml
<?xml version="1.0" encoding="UTF-8"?>
<server description="tlc server">
<!-- Enable features -->
<featureManager>
<feature>jsp-2.2</feature>
<feature>ssl-1.0</feature>
<feature>localConnector-1.0</feature>
<feature>restConnector-1.0</feature>
<feature>json-1.0</feature>
<feature>jaxrs-1.1</feature>
<feature>servlet-3.0</feature>
<feature>jpa-2.0</feature>
<feature>beanValidation-1.0</feature>
<feature>jndi-1.0</feature>
<feature>jdbc-4.0</feature>
<feature>monitor-1.0</feature>
</featureManager>
<httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9080" httpsPort="9443" virtualHost="default_host" />
<jdbcDriver id="DerbyJDBCDriver">
<library name="DerbyLib">
<fileset dir="C:\tools\servers\wlp\lib" includes="derbyclient-10.6.1.0.jar" />
</library>
</jdbcDriver>
<dataSource jndiName="jdbc/TLCDataSource" id="derbyDataSource" jdbcDriverRef="DerbyJDBCDriver">
<properties.derby.client databaseName="TLC" password="APP" user="APP" />
</dataSource>
<applicationMonitor updateTrigger="mbean" />
<application id="TLC_war" context-root="/TLC" location="C:\Users\nd26434\gitrepos\tlc\target\TLC-1.0.0-SNAPSHOT.war" name="TLC_war" type="war">
<classloader delegation="parentLast">
<privateLibrary>
<fileset dir="C:\tools\servers\wlp\lib" includes="aspectjweaver-1.8.0.jar" />
</privateLibrary>
</classloader>
</application>
</server>
message.log
[3/18/15 20:19:54:789 EDT] 0000001b com.ibm.ws.app.manager.AppMessageHelper A CWWKZ0022W: Application TLC_war has not started in 30.018 seconds.
[3/18/15 20:20:03:174 EDT] 0000001f com.ibm.ws.webcontainer.osgi.webapp.WebGroup I SRVE0169I: Loading Web Module: TLC-1.0.0-SNAPSHOT.
[3/18/15 20:20:03:175 EDT] 0000001f com.ibm.ws.webcontainer I SRVE0250I: Web Module TLC-1.0.0-SNAPSHOT has been bound to tlc_host.
ibm-web-bnd.xml
<?xml version="1.0" encoding="UTF-8"?>
<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="tlc_host"/>
<resource-ref name="jdbc/TLCDataSource"
binding-name="jdbc/TLCDataSource" />
</web-bnd>
ibm-web-ext.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-ext
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-ext_1_0.xsd"
version="1.0">
<reload-interval value="3"/>
<context-root uri="TLC" />
<enable-directory-browsing value="false"/>
<enable-file-serving value="true"/>
<enable-reloading value="true"/>
<enable-serving-servlets-by-class-name value="false" />
</web-ext>
Remove <virtual-host name="tlc_host"/> from your ibm-web-ext.xml file. As you dont have tlc_host, but default_host.
Context Root Not found is caused due to issue in one of the config files.
In my case, web.xml had an unclosed comment due to which the war was not built correctly.
This resulted in EAR file not updating.
Solution:
Compare you web.xml with previous versions to see what changed.
Add war to the server instead of the ear file to see the error. (If Running on Liberty Server)

How to Cluster infinispan cache in Jboss 7 1 1 Final?

Bean Decleration:
bean id="cacheManager" class="org.infinispan.spring.provider.SpringEmbeddedCacheManagerFactoryBean"
p:configurationFileLocation="classpath:infinispan.xml" ..
infinispan.xml
<infinispan
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:infinispan:config:5.1 http://www.infinispan.org/schemas/infinispan-config-5.1.xsd"
xmlns="urn:infinispan:config:5.1">
<global>
<transport clusterName="CASCluster"/>
<globalJmxStatistics enabled="true"/>
</global>
<default>
<jmxStatistics enabled="true"/>
<clustering mode="distribution">
<hash numOwners="2" rehashRpcTimeout="120000"/>
<sync/>
</clustering>
</default>
<namedCache name="mtx.infinispan.global">
<eviction strategy="LIRS" maxEntries="50000" />
</namedCache>
<namedCache name="books">
<eviction strategy="LIRS" maxEntries="50000" />
</namedCache>
<namedCache name="scheduleprofiletemplates">
<eviction maxEntries="1000000" strategy="LIRS" />
<loaders passivation="false" shared="false" preload="true">
<!-- We can have multiple cache loaders, which get chained -->
<loader class="org.infinispan.loaders.file.FileCacheStore"
fetchPersistentState="true" purgerThreads="3" purgeSynchronously="true"
ignoreModifications="false" purgeOnStartup="false">
<!-- See the documentation for more configuration examples and flags. -->
<properties>
<property name="location" value="/home/cas/infinispanCache" />
</properties>
</loader>
</loaders>
</namedCache>
I want deploy the application Jboss cluster so that the cache created in one node is accessible/replicated to other node also....
I am using Jboss Domain mode full-ha for the deployment....I have HornetQ, Mod_cluster working properly on the same cluster.
By googling, I cam to know that it achieving thru JNDI....Can you pls tel how to modify the XMl files to achiiev this....I have to create 4 named cache(Where to create this ? In sping config file or Jboss domain.xml).
Thanks in advance
Create a Jboss cluster full-ha profile.
2.Create queus on Jboss side
3.Ovveride the SpringEmbeddedCacheManagerFactoryBean cacheManager

spring example with wrong datasource configuration

I try to run the example project of jboss-springmvc-webapp, but I fail to configure the data source.
the error is:
JBAS014775: New missing/unsatisfied dependencies:
service jboss.jdbc-driver.mysql (missing) dependents: [service jboss.data-source.jboss/datasources/SpringQuickstartDS]
my persistence.xml is:
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="primary">
<!-- If you are running in a production environment, add a managed
data source, this example data source is just for development and testing! -->
<!-- The datasource is deployed as WEB-INF/spring-quickstart-ds.xml, you
can find it in the source at src/main/webapp/WEB-INF/spring-quickstart-ds.xml -->
<jta-data-source>java:jboss/datasources/SpringQuickstartDS</jta-data-source>
<properties>
<property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/spring-quickstart/persistence" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
</persistence>
my datasource.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
<!-- The datasource is bound into JNDI at this location. We reference
this in META-INF/persistence.xml -->
<datasource jndi-name="java:jboss/datasources/SpringQuickstartDS"
pool-name="kitchensink-quickstart" enabled="true"
use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/testdb</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password></password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="mysql" module="com.mysql.jdbc">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
<driver name="postgresql" module="org.postgresql.jdbc">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
If you use the jboss-springmvc-webapp architype then it should come configured to use H2 as a datasource. I would go back to that configuration first to confirm that it works.
Then when you know everything else is working you can set up a MySQL datasource. There are 2 things you need to know. You can only point to one datasource at a time, so you must remove the other ones from the file above. It can only have the MySQL info (if that is the datasource you are using). Second, you will need to make sure you have the JDBC driver for the database that you are going to use.
Every version of JBoss has good docs on setting this up. What version of JBoss are you using, I'll post the doc page?

Resources