Configure default data source for Arquillain Test in OpenLiberty - jdbc

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>

Related

Spring-based web application fails at startup on WAS Liberty

I'm writing a simple Spring-based web application and deploy it to Websphere Liberty 8.5.5.9. The deployment fails because the application start fails. The message in console.log is
[ERROR ] CWWKZ0002E: An exception occurred while starting the application userSetting.
The exception message was: com.ibm.ws.container.service.metadata.MetaDataException:
com.ibm.wsspi.adaptable.module.UnableToAdaptException:
com.ibm.ws.javaee.ddmodel.DDParser$ParseException: CWWKC2262E: The server is
unable to process the 3.1 version and the http://xmlns.jcp.org/xml/ns/javaee namespace
in the /META-INF/web-fragment.xml deployment descriptor on line 23.
The last part of the message makes now sense since I don't hav /META-INF or /WEB-INF in the Eclipse project for the application, since I'm deploying with Gradle: gradle clean build deploy.
I've tried all kinds of modifications to the project and, in desperation, I've cut it down to only have the following source code:
#SpringBootApplication
public class UserSettingApplication {
private static final LoggerUtils logger = new LoggerUtils( UserSettingApplication.class );
public static void main(String[] args) {
logger.debug( "Entering UserSettingApplication.main()" );
SpringApplication.run(UserSettingApplication.class, args);
}
}
Can you please advise me how to fix this service start-up problem?
server.xml:
<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>jsp-2.2</feature>
</featureManager>
<featureManager>
<feature>adminCenter-1.0</feature>
</featureManager>
<!-- Define the host name for use by the collective.
If the host name needs to be changed, the server should be
removed from the collective and re-joined. -->
<variable name="defaultHostName" value="localhost" />
<!-- Define an Administrator and non-Administrator -->
<basicRegistry id="basic">
<user name="admin" password="********" />
<user name="nonadmin" password="***********" />
</basicRegistry>
<!-- Assign 'admin' to Administrator -->
<administrator-role>
<user>admin</user>
</administrator-role>
<keyStore id="defaultKeyStore" password="*******" />
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint id="defaultHttpEndpoint"
host="*"
httpPort="9080"
httpsPort="9443" />
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="false"/>
</server>
This error appears to be caused by some of your build tooling generating a web-fragment.xml with a Servlet 3.1 schema.
Currently, you have the jsp-2.2 feature enabled, which by default enables servlet-3.0.
To fix the problem, I would recommend upgrading from jsp-2.2 to jsp-2.3 (which will pull in servlet-3.1), or adding <feature>webProfile-7.0</feature> to just enable all of the Java EE 7 web profile features (servlet, JPA, bean validation, cdi, jsf, etc).
So your new server.xml could look like this:
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>jsp-2.3</feature>
<feature>adminCenter-1.0</feature>
</featureManager>
<!-- rest of file unchanged.... -->

CWWKL0008W Warning seems wrong based on what I can configure in server.xml

I am getting a warning when starting my v17.0.0.4 Liberty server for a shared library and war not having the same class loading specifications:
[WARNING ] CWWKL0008W: Application [myRESTServices#myRESTServices-1.0.0-SNAPSHOT.war] is incompatible with the common class loader for library [myJARS] because they have inconsistent API visibility configurations. Library [myJARS] is configured with [[spec, ibm-api, api, stable]] and application [myRESTServices#myRESTServices-1.0.0-SNAPSHOT.war] is configured with [[spec, ibm-api, api, third-party]].
However, the server.xml defines both with the same set:
<library apiTypeVisibility="spec,ibm-api,api,third-party" description="My Shared Libraries from the myJARS directory" id="myJARS" name="myJARS">
<fileset dir="/csnext/myJARS" id="myJARS" includes="*.jar" scanInterval="30s"/>
</library>
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>
<webApplication id="myRESTServices" location="myRESTServices-1.0.0-SNAPSHOT.war" name="myRESTServices">
<classloader apiTypeVisibility="spec,ibm-api,api,third-party">
<commonLibrary id="myJARS" name="myJARS" >
<fileset id="myJARS" dir="/csnext/myJARS" includes="*.jar"></fileset>
</commonLibrary>
</classloader>
</webApplication>
Your application is not using the library that is defined with apiTypeVisibility, it is using a separate copy of the library definition. I think you want this for the application configuration:
<webApplication id="myRESTServices" location="myRESTServices-1.0.0-SNAPSHOT.war" name="myRESTServices">
<classloader apiTypeVisibility="spec,ibm-api,api,third-party" commonLibraryRef="myJARS"/>
</webApplication>

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"/>

Spring deployment-level configuration

When I wrote Java EE apps, I used JBoss Datasources to control which databases the deployment used. E.g. the dev versions would use a throwaway hibernate db, the ref and ops would use stable MySQL deployments. I also used MBeans to configure various other services and rules.
Now that I'm using Spring, I'd like the same functionality - deploy the same code, but with different configuration. Crucially, I'd also like Unit Tests to still run with stub services. My question is this - is there a way, in JBoss, to inject configuration with files which live outside of the WAR/EAR, and also include these files in test resources.
It is possible to add objects into the JNDI context by placing a file named xxx-service.xml into jboss's deploy directory. The app could then lookup the values via JNDI. In the example below the string "development" is added at java:/modes/deployment. To use JNDI in your unit tests use the org.springframework.mock.jndi package.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server PUBLIC "-//JBoss//DTD MBean Service 4.0//EN"
"http://www.jboss.org/j2ee/dtd/jboss-service_4_0.dtd">
<server>
<mbean code="org.jboss.naming.JNDIBindingServiceMgr"
name="c3po.naming:service=jndi-bindings">
<attribute name="BindingsConfig" serialDataType="jbxb">
<jndi:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jndi="urn:jboss:jndi-binding-service:1.0"
xs:schemaLocation="urn:jboss:jndi-binding-service:1.0 resource:jndi-binding-service_1_0.xsd"
>
<jndi:binding name="java:/modes/deployment">
<jndi:value type="java.lang.String">development</jndi:value>
</jndi:binding>
<jndi:binding name="java:/sites/abc">
<jndi:value type="java.lang.String">dev.site.example.com</jndi:value>
</jndi:binding>
<!-- Examples:
<jndi:binding name="urls/jboss-home">
<jndi:value type="java.net.URL">http://www.jboss.org</jndi:value>
</jndi:binding>
<jndi:binding name="hosts/localhost">
<jndi:value editor="org.jboss.util.propertyeditor.InetAddressEditor">
127.0.0.1
</jndi:value>
</jndi:binding>
<jndi:binding name="maps/testProps">
<java:properties xmlns:java="urn:jboss:java-properties"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="urn:jboss:java-properties resource:java-properties_1_0.xsd">
<java:property>
<java:key>key1</java:key>
<java:value>value1</java:value>
</java:property>
<java:property>
<java:key>key2</java:key>
<java:value>value2</java:value>
</java:property>
</java:properties>
</jndi:binding>
-->
</jndi:bindings>
</attribute>
<depends>jboss:service=Naming</depends>
</mbean>
</server>

Resources