Cannot activate SimpleNamingContextBuilder: there is already a JNDI provider registered - spring

Getting follwing error when I run junit test case report through ant srcipt:
Cannot activate SimpleNamingContextBuilder: there is already a JNDI provider registered. Note that JNDI is a JVM-wide service, shared at the JVM system class loader level, with no reset option. As a consequence, a JNDI provider must only be registered once per JVM.
java.lang.IllegalStateException: Cannot activate SimpleNamingContextBuilder: there is already a JNDI provider registered. Note that JNDI is a JVM-wide service, shared at the JVM system class loader level, with no reset option. As a consequence, a JNDI provider must only be registered once per JVM.
at org.springframework.mock.jndi.SimpleNamingContextBuilder.activate(SimpleNamingContextBuilder.java:135)
at org.springframework.mock.jndi.SimpleNamingContextBuilder.emptyActivatedContextBuilder(SimpleNamingContextBuilder.java:113)
at com.bgc.ecm.core.test.ElNinoAbstractTestCase.prepareTestInstance(ElNinoAbstractTestCase.java:216)
at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:100)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76)
at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
code:
this.callerContext = (CallerContext) getApplicationContext().getBean("CallerContext");
assertNotNull(this.callerContext);
SimpleNamingContextBuilder builder =
SimpleNamingContextBuilder.emptyActivatedContextBuilder();
Junit target:
<junit printsummary="on" fork="yes" forkmode="perBatch" haltonfailure="false" failureproperty="junit.failure" showoutput="false">
<classpath>
<path refid="CLASSPATH_JUNIT"/>
</classpath>
<batchtest fork="no" todir="${TEST_BUILD_DIR}">
<fileset dir="${APP_DIR_CORE}\src\test">
<include name="**/*Test.java" />
<include name="**/Test*.java" />
</fileset>
</batchtest>
</junit>

I had enabled JNDI datasource in Hibernate config file which causes 2 jndi reference and thows JNDI/JVM binding exception.

Related

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>

IllegalStateException: Failed to introspect Class

I am trying to implement extension capability on my SpringBoot application where the #ComponentScan is supposed to scan for bean definitions in a separate jar present in the classpath.
The #ComponentScan looks like below
#ComponentScan({"com.myapp.rest","com.mycompany.search.rest"})
Where package "com.mycompany.search.rest" will be present in an external jar ESExt.jar
I added below configuration in the server.xml file of my WebSphere Liberty Server to include an external folder for classpath scanning
<library id="extention" apiTypeVisibility="+third-party, -api">
<fileset dir="${server.config.dir}/ext" includes="*.jar" scanInterval="5s" />
</library>
<webApplication id="Myapp" location="Myapp.war" type="war" name="Myapp" contextRoot="/resources">
<classloader commonLibraryRef="extention" />
</webApplication>
When I deploy my application in a WebSphere Liberty Server, it throws below exception
[28/9/20 13:43:04:878 IST] 0000002a com.ibm.ws.logging.internal.impl.IncidentImpl I FFDC1015I: An FFDC Incident has been created: "org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'storeResource': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [com.mycompany.search.rest.StoreResource] from ClassLoader [com.ibm.ws.classloading.internal.AppClassLoader#7a84a757] com.ibm.ws.webcontainer.osgi.DynamicVirtualHost startWebApp" at ffdc_20.09.28_13.43.04.0.log
Below is the output for jar -tf ESExt.jar
META-INF/
META-INF/MANIFEST.MF
com/
com/mycompany/
com/mycompany/search/
com/mycompany/search/rest/
com/mycompany/search/rest/StoreResource.class
What does this exception IllegalStateException: Failed to introspect Class even mean? I cannot even find anything about it in the internet.
Solved it by changing the server.xml as below
<library id="extension">
<fileset dir="${server.config.dir}/ext" includes="*.jar" scanInterval="5s" />
</library>
<webApplication id="Myapp" location="Myapp.war" type="war" name="Myapp" contextRoot="/resources">
<classloader commonLibraryRef="extension" delegation="parentFirst"/>
</webApplication>

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>

Unable to use JCA CICS resource with IBM WebSphere Application Server Liberty Profile

I'm trying to setup WLP for an existing EAR application.
This setup works fine with WAS 9 traditional.
The problem is the JCA CICS Resource Adapter call.
The server.xml :
<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>javaee-7.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"
host="*"
httpPort="9080"
httpsPort="9443" />
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>
<library id="sharedLibs">
<fileset dir="/work/sharedlibs" includes="*.jar"/>
<folder dir="/work" />
</library>
<resourceAdapter
autoStart="true"
id="eciResourceAdapter"
location="/work/cicseci.rar">
</resourceAdapter>
<connectionFactory id="CTGDV06" jndiName="jca/CTGDV06" >
<properties.eciResourceAdapter.javax.resource.cci.ConnectionFactory
connectionUrl="tcp://*******"
serverName="*******"
userName="*******"
portNumber="2006"
/>
</connectionFactory>
<application type="ear" id="app" location="app.ear" name="app">
<classloader
commonLibraryRef="sharedLibs"
classProviderRef="eciResourceAdapter" />
</application>
</server>
in ibm-web-bnd.xml :
<resource-ref name="cicsjca" binding-name="jca/CTGDV06"></resource-ref>
in web.xml :
<resource-ref id="ResourceRef_Cics_Jca">
<description>Acces CICS</description>
<res-ref-name>cicsjca</res-ref-name>
<res-type>javax.resource.cci.ConnectionFactory</res-type>
<res-auth>Application</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
Startup is Ok, but access to JCA fail with :
java.lang.Exception: Lookup for java:comp/env/cicsjca failed. Exception: javax.naming.NamingException: CWNEN1001E: The object referenced by the java:comp/env/cicsjca JNDI name could not be instantiated. If the reference name maps to a JNDI name in the deployment descriptor bindings for the application performing the JNDI lookup, make sure that the JNDI name mapping in the deployment descriptor binding is correct. If the JNDI name mapping is correct, make sure the target resource can be resolved with the specified name relative to the default initial context.
[Root exception is com.ibm.wsspi.injectionengine.InjectionException: CWNEN0030E: The server was unable to obtain an object instance for the java:comp/env/cicsjca reference. The exception message was: CWNEN1003E: The server was unable to find the jca/CTGDV06 binding with the javax.resource.cci.ConnectionFactory type for the java:comp/env/cicsjca reference.]
I don't understand what's wrong with this setup, any help would be apreciated !
The correct configuration depends on how many connection factory implementations are provided by the resource adapter.
If the resource adapter provides only a single connection factory (which is commonly the case for many resource adapters), then configuration would be:
<connectionFactory id="CTGDV06" jndiName="jca/CTGDV06" >
<properties.eciResourceAdapter
connectionUrl="tcp://*******"
serverName="*******"
userName="*******"
portNumber="2006"
/>
</connectionFactory>
Full detail on how to specify configuration for JCA resource adapters in Liberty can be found here in the knowledge center.

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

Resources