JNDI binding in JBoss (LiveCycle turnkey) - java

I am using Adobe LiveCycle ES 2 turnkey project, which runs on JBoss AS 4.2.1.GA. I am having a problem getting a JNDI binding to work in JBoss. It seems eerily similar to an earlier post, problem configure JBoss to work with JNDI, but I certainly have found no solution.
This is my setup. I have a -ds.xml file in place:
C:\Adobe\Adobe LiveCycle ES2\jboss\server\lc_turnkey\deploy\rmb-ds.xml
The contents of that file are as follows:
<datasources>
<local-tx-datasource>
<jndi-name>RMB_DS</jndi-name>
<connection-url>jdbc:sqlserver://localhost\SQLEXPRESS;DatabaseName=rmb</connection-url>
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
<user-name>sa</user-name>
<password>password</password>
<check-valid-connection-sql>SELECT 1 FROM sysobjects</check-valid-connection-sql>
<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<metadata>
<type-mapping>MS SQLSERVER2000</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
I have a Java project, whose /RMB/WebContent/WEB-INF/web.xml contains the following:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>java:RMB_DS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Now, every time I deploy the WAR, it fails with the following error:
2011-09-06 15:44:17,786 ERROR [org.jboss.deployment.MainDeployer] Could not start deployment: file:/C:/Adobe/Adobe LiveCycle ES2/jboss/server/lc_turnkey/deploy/RMB.war
org.jboss.deployment.DeploymentException: Error during deploy; - nested throwable: (javax.naming.NamingException: resource-ref: java:RMB_DS has no valid JNDI binding. Check the jboss-web/resource-ref.)
at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:384)
...
Caused by: javax.naming.NamingException: resource-ref: java:RMB_DS has no valid JNDI binding. Check the jboss-web/resource-ref.
at org.jboss.web.AbstractWebDeployer.linkResourceRefs(AbstractWebDeployer.java:623)
I am 100% positive that the JNDI binding itself is correct. I can see the following in web console > System > JMX Beans > jboss.jdbc > jboss.jdbc:service=metadata,datasource=RMB_DS
MBean Name: Domain Name: jboss.jdbc
service: metadata
datasource: RMB_DS
MBean Java Class: org.jboss.ejb.plugins.cmp.jdbc.metadata.DataSourceMetaData
Also, using LiveCycle workbench I can make a process that hits this service and runs some SQL against datasource java:/RMB_DS..
SO, there has to be something wrong with my WAR or web.xml right? Am I missing something obvious?

Thanks to Ketan, who is awesome!
Needed a jboss-web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<resource-ref>
<res-ref-name>RMB_DS</res-ref-name>
<jndi-name>java:/RMB_DS</jndi-name>
</resource-ref>
</jboss-web>
And changed the original web.xml to have:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>RMB_DS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Which matches rmb-ds.xml
<datasources>
<local-tx-datasource>
<jndi-name>RMB_DS</jndi-name>
<connection-url>jdbc:sqlserver://localhost\SQLEXPRESS;DatabaseName=RMB</connection-url>
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
<user-name>sa</user-name>
<password>password</password>
<check-valid-connection-sql>SELECT 1 FROM sysobjects</check-valid-connection-sql>
<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<metadata>
<type-mapping>MS SQLSERVER2000</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>

Related

defining a datasource in JBoss standalone.xml vs. in the web.xml in a container-agnostic way

I have successfully configured a JDBC datasource in my JBoss standalone.xml but I am also trying to figure out if it's possible to define the datasource in the web.xml itself, in a standard, container-agnostic way as this answer suggests.
However I am having trouble translating the elements from the JBoss's standalone.xml into what I would need to put in my application's web.xml.
Here's the excerpt from my JBoss standalone.xml:
<datasource jta="false" jndi-name="java:/comp/env/jdbc/sybase/axafusers" pool-name="axafusers" enabled="true" use-ccm="false">
<connection-url>jdbc:jtds:sybase://localhost:12501/axafusers</connection-url>
<driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
<driver>sybasejtds</driver>
<security>
<user-name>username</user-name>
<password>secret</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
Defining the data source in the server as above works. However, the approach to define the data source in the web.xml fails as shown below.
Here's what I have placed in my web.xml:
<data-source>
<name>java:/comp/env/jdbc/sybase/axafusers</name>
<class-name>net.sourceforge.jtds.jdbcx.JtdsDataSource</class-name>
<server-name>localhost</server-name>
<port-number>12501</port-number>
<database-name>axafusers</database-name>
<user>username</user>
<password>secret</password>
<transactional>false</transactional>
</data-source>
Despite my attempt to accurately copy the various parameters in their corresponding elements (the most error-prone part seems to be translating the connection-url) I am consistently getting Could not create connection messages that are ultimately caused by the following:
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method) [rt.jar:1.8.0_111]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) [rt.jar:1.8.0_111]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) [rt.jar:1.8.0_111]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) [rt.jar:1.8.0_111]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) [rt.jar:1.8.0_111]
at java.net.Socket.connect(Socket.java:589) [rt.jar:1.8.0_111]
at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:288) [jtds-1.3.1.jar:1.3.1]
at net.sourceforge.jtds.jdbc.SharedSocket.(SharedSocket.java:251) [jtds-1.3.1.jar:1.3.1]
at net.sourceforge.jtds.jdbc.JtdsConnection.(JtdsConnection.java:331) [jtds-1.3.1.jar:1.3.1]
This exception usually occurs when there is no service listening on the port you are trying to connect to. A couple of things could be happening:
You have not started your server.
Your server is not waiting to accept connections.
You are trying to connect to the wrong port number.
Client and Server, either or both of them are not in the network.
Server is not running
The server is running but not listening on the port, a client is trying to connect.
Firewall is not permitted for host-port combination
Incorrect protocol in Connection String
A JDBC datasource must be mapped to a in jboss-web.xml before it can be used in web.xml. For example, this datasource:
src/main/webapp/WEB-INF/jboss-web.xml:
<jboss-web>
<resource-ref>
<res-ref-name>jdbc/datasource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<jndi-name>java:jboss/datasources/ExampleDS</jndi-name>
</resource-ref>
</jboss-web>
src/main/webapp/WEB-INF/web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>JndiDsTest</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<resource-ref>
<res-ref-name>jdbc/datasource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
You can invoke the datasource by using simple code snippet:
DataSource ds = null;
Context ctx = null;
String strDSName = "java:comp/env/jdbc/datasource";
ctx = new InitialContext();
ds = (javax.sql.DataSource) ctx.lookup(strDSName);

Migrating jboss.xml to jboss-ejb3.xml

I'm currently migrating an Java/EE5 application to run with WildFly-8.0.0.Final. As stated here: https://docs.jboss.org/author/display/WFLY8/How+do+I+migrate+my+application+from+AS5+or+AS6+to+WildFly , the legacy jboss.xml file seems to be ignored by now. Unluckily (for me) I was unable to find a good resource for migrating the session part within enterprise-beans. My current jboss.xml looks like this:
<?xml version='1.0' encoding='UTF-8' ?>
<jboss xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss_5_1.xsd" version="5.1">
<security-domain>java:/jaas/customAdmin</security-domain>
<enterprise-beans>
<session>
<ejb-name>CustomConfigBean</ejb-name>
<pool-config>
<pool-value>StrictMaxPool</pool-value>
<pool-max-size>10</pool-max-size>
<pool-timeout>30002</pool-timeout>
</pool-config>
</session>
</enterprise-beans>
<assembly-descriptor>
<security-role>
<role-name>customUser</role-name>
<principal-name>customUser</principal-name>
</security-role>
<security-role>
<role-name>customAdmin</role-name>
<principal-name>customAdmin</principal-name>
</security-role>
</assembly-descriptor>
</jboss>
What is required to make this run in jboss-ejb3.xml ?
Have you taken a look at the schema? It looks like it has the same elements so it should be rather straightforward to create jboss-ejb3.xml using your existing jboss.xml as a starting point.
Here's the jboss-ejb3.xml Reference.
NOTE: I think the schemaLocation is not correct in the reference. It uses http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd, which does not exist. The correct schema location is http://xmlns.jcp.org/xml/ns/javaee/ejb-jar_3_2.xsd. I just created a discussion in the Wildfly group about the schema location problem.
You don't mention where your jboss.xml is located so for completeness just a reminder that for Wildfly it should be in WEB-INF of a war, or META-INF of an EJB jar.

Tomcat 8 - Virtual Host Not Recompiling JSPs or Recognizing Updated Classes

I've just unpacked and configured Tomcat 8.0.3 on Windows 7 with a virtual host. I've tested it successfully under the default webapps, however, my virtual host is not recognizing changes in JSP files or classes.
Here is my set up:
%CATALINA_HOME%\conf\server.xml
...
<Engine name="Catalina" defaultHost="localhost">
...
<Host name="ww.virtual.com" appBase="vapps" unpackWARs="true" autoDeploy="true">
</Host>
</Engine>
...
%SystemRoot%\system32\drivers\etc\hosts
...
127.0.0.1 ww.virtual.com
%CATALINA_HOME%\vapps\ROOT\META-INF\context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context antiResourceLocking="true" privileged="true" reloadable="true">
<Resource name="jdbc/INVENTORY" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="sqlusr" password="secret1" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://127.0.0.1:1433;instanceName=SQLSERVER;DatabaseName=INVENTORY"/>
</Context>
%CATALINA_HOME%\vapps\ROOT\WEB-INF\web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1"
metadata-complete="true">
<display-name>Test Display</display-name>
<description>Test Description</description>
<resource-ref>
<description>Test DB Connection</description>
<res-ref-name>jdbc/INVENTORY</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
I then have JSP files located in %CATALINA_HOME%\vapps\ROOT\ and classes in %CATALINA_HOME%\vapps\ROOT\WEB-INF\classes\MainPackage\ which are properly loaded when the server is started. But if I make any changes to the JSPs or .class files, the server does not recognize the update. What am I doing wrong?
This is happening because you have enabled anti-resource locking. With that option enable the web application is not deployed from the appBase but from a copy in the work directory. If you edit the copy in the work directory you'll see the changes.
Alternatively, remove the anti-resource locking options and fix whatever bug caused you to need them in the first place.

JNDI name not found - how to use JNDI in WCM workflow plugin?

I'm using Rational Application Developer 8.5 to develop a custom workflow action plugin for IBM Web Content Manager (WCM) in WebSphere Portal 7.0.
The plugin needs to get a JDBC data source with JNDI, but all my attempts to do so produce this error:
javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".
A data source named "jdbc/wcmbulletins" is defined in the WebSphere Application Server.
Here's the java code to get the data source:
javax.naming.InitialContext ctx=new javax.naming.InitialContext();
javax.sql.DataSource ds=(javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/wcmbulletins");
The RAD project contains the following XML files only. There's no "persistence.xml" or any other files I've seen mentioned in similar SO questions.
There are also some JSP files referenced by WCM JSP components. The JSP files have no connection with the plugin and don't use JNDI or JDBC.
ibm-web-bnd.xml:
<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="default_host"/>
<resource-ref name="jdbc/wcmbulletins" binding-name="jdbc/wcmbulletins"/>
</web-bnd>
ibm-web-ext.xml:
<web-ext
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-ext_1_0.xsd"
version="1.0">
<jsp-attribute name="reloadEnabled" value="false"/>
<jsp-attribute name="reloadInterval" value="10"/>
<reload-interval value="3"/>
<enable-directory-browsing value="false"/>
<enable-file-serving value="true"/>
<enable-reloading value="true"/>
<enable-serving-servlets-by-class-name value="true"/>
</web-ext>
plugin.xml:
<plugin id="com.company.wcm.CompanyWCMPlugins"
name="Company WCM Plugins"
version="1.0.0"
provider-name="Company Name Australia">
<extension
point="com.ibm.workplace.wcm.api.CustomWorkflowActionFactory"
id="CompanyWorkflowActionFactory">
<provider class="com.company.wcm.workflow.CompanyWorkflowActionFactory"/>
</extension>
</plugin>
web.xml:
<web-app id="WebApp_ID" version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>CompanyWCM_JSPs</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<resource-ref id="ResourceRef_1377568155870">
<description/>
<res-ref-name>jdbc/wcmbulletins</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>
What do I need to make the JNDI lookup work?
What happens if you change the code to bypass the resource reference and use the name jdbc/wcmbulletins instead?
Also - at what scope is the DS defined? If at cluster level try the name cell/persistent/jdbc/wcmbulletins and see what you get.
Lastly - there is always the WebSphere naming trace. You can enable them via Naming=all, re-run your app, and check trace.log for insight as to what might be going on.
Hope this helps,
ScottH
From my experience, wcm plugins are somewhat independent from the web-application they are contained in (they are more related to OSGI or so). For example during server startup plugins are instantiated, before the web-application itself is, so it might not even be possible to reliably lookup resources from the web-app.

How can I use Java console app and Hibernate using Tomcat Context?

I have some Java-console-apps. which are using Hibernate to take care some database stuff (I use MySQL). Now, I want Hibernate to use datasource from Tomcat Context. Could anyone tell me how?
Tomcat wiki contains the needed configuration.
in context.xml:
<?xml version="1.0" encoding="UTF-8"?> <Context antiJARLocking="true" path="/DVDStore">
<Resource auth="Container"
driverClassName="com.mysql.jdbc.Driver" maxActive="30" maxIdle="10" maxWait="10000" name="jdbc/sakila" password="*****"
type="javax.sql.DataSource" url="jdbc:mysql://localhost/sakila" username="*****"/>
</Context>
In WEB-INF/web.xml .
<resource-ref>
<description>This is a MySQL database connection</description>
<res-ref-name>jdbc/sakila</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
In hibernate.cfg.xml:
<!-- using container-managed JNDI -->
<propertyname="hibernate.connection.datasource">
java:comp/env/jdbc/sakila
</property>
You can find more in The TomcatHibernate Wiki
Edit:
In case you want to access the context directly, this is the way to do it problematically
ServletContext sc = getServletContext();
String parameterValue = sc.getInitParameter("parameterName");

Categories

Resources