jndi jdbc App Server Integration
We are seeing the following error in -
/jes/var/opt/SUNWappserver/domains/domain1/logs/server.log
[#|2007-07-26T10:58:47.790-0400|FINE|sun-appserver-ee8.1_02|
javax.enterprise.resource.resourceadapter|_ThreadID=27;|
RAR5036:Resource reference is not defined for JNDI name [jdbc/MarxDB]|#]
Application server is -
Sun Java System Application Server 8.1_02 (build b21-p10)
Excerpt from our test java class
System.out.println("\n.MARKER2 before dataSource.getConnection().\n");
Above seen in log files.
dbConnection = dataSource.getConnection();
System.out.println("\n.after dataSource.getConnection().\n");
Above never seen in log files.
Excerpt from our server.log.
.MARKER2 before dataSource.getConnection().
|#]
[#|2007-07-26T10:58:47.790-0400|FINE|sun-appserver-ee8.1_02|
javax.enterprise.resource.resourceadapter|_ThreadID=27;|
RAR5036:Resource reference is not defined for JNDI name [jdbc/MarxDB]|#]
Excerpt from /jes/var/opt/SUNWappserver/domains/domain1/config/domain.xml
<jdbc-resource enabled="true" jndi-name="jdbc/MarxDB" object-type="user" pool-name="MARXDB"/>
<jdbc-connection-pool connection-validation-method="auto-commit"
datasource-classname="COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource"
fail-all-connections="true"
idle-timeout-in-seconds="300"
is-connection-validation-required="true"
is-isolation-level-guaranteed="false"
max-pool-size="32"
max-wait-time-in-millis="8000"
name="MARXDB"
pool-resize-quantity="4"
res-type="javax.sql.ConnectionPoolDataSource"
steady-pool-size="8"
validation-table-name="mcs_user_status">
<property name="user" value="IACSTNV"/>
<property name="url" value="jdbc:db2:HCFADB1T"/>
<property name="password" value="CKM349AB"/>
<property name="databaseName" value="HCFADB1T"/>
<property name="portNumber" value="50000"/>
</jdbc-connection-pool>
Here is the java
package gov.hhs.cms.ebs.das;
import gov.hhs.cms.ebs.log.LogManager;
import gov.hhs.cms.ebs.util.PropertiesUtil;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.util.Hashtable;
import java.util.Enumeration;
public class MarxDas {
private static int MARX_COUNTER = 0;
private static Connection getConnection(String MARX_DB_DATASOURCE) {
System.out.println("\nMarxDas cl, getConnection md arg is ." + MARX_DB_DATASOURCE + ".\n");
LogManager.debug("Inside getConnection method of MarxDao");
Connection dbConnection = null;
InitialContext ic = null;
DataSource dataSource = null;
try {
LogManager.debug("getConnection: Trying to establish a DB2 connection");
ic = new InitialContext();
System.out.println("\nMarxDas cl, getConnection md ic.getNameInNamespace is ." + ic.getNameInNamespace() + ".\n");
Hashtable myHashtable = ic.getEnvironment();
System.out.println("\nMarxDas cl, getConnection md myHashtable isEmpty is ." + myHashtable.isEmpty() + ".\n");
Enumeration enum = myHashtable.keys();
while ( enum.hasMoreElements() ) {
Object myKey = enum.nextElement();
System.out.println("\nMarxDas cl, getConnection md Hashtable key is ." + myKey + ".\n");
System.out.println("\nMarxDas cl, getConnection md value is ." + myHashtable.get(myKey) + ".\n");
}
// System.out.println("\nMarxDas cl, ic.lookup(MARX_DB_DATASOURCE) is." + ic.lookup(MARX_DB_DATASOURCE) + ".\n");
if ( (DataSource) ic.lookup(MARX_DB_DATASOURCE) == null ) {
System.out.println("\n (DataSource) ic.lookup(MARX_DB_DATASOURCE) is NULL." );
}
else {
System.out.println("\n (DataSource) ic.lookup(MARX_DB_DATASOURCE) is NOT NULL.\n");
System.out.println("\n (DataSource) ic.lookup(MARX_DB_DATASOURCE) is ." + (DataSource) ic.lookup(MARX_DB_DATASOURCE) + ".\n");
}
if (ic != null) {
dataSource = (DataSource) ic.lookup(MARX_DB_DATASOURCE);
System.out.println("\ndataSource is ." + dataSource + ".\n");
if (dataSource != null) {
System.out.println("\n.before dataSource.getConnection().\n");
System.out.println("\n.MARKER2 before dataSource.getConnection().\n");
// dbConnection = ((com.sun.gjc.spi.DataSource)dataSource).getConnection();
dbConnection = dataSource.getConnection();
System.out.println("\n.after dataSource.getConnection().\n");
}
}
} catch (Exception e) {
LogManager.error(
"getConnection: Exception occurred while getting datasource: "
+ e.getMessage());
}
System.out.println("\nMarxDas cl, getConnection md dbConnection is ." + dbConnection + ".\n");
return dbConnection;
}
public static String checkMarxConnection(String MARX_DB_DATASOURCE) {
System.out.println("\nMarxDas cl, checkMarxConnection md arg is ." + MARX_DB_DATASOURCE + ".\n");
LogManager.debug("Inside checkMarxConnection method of MarxDao");
Connection dbConnection = null;
try {
dbConnection = getConnection(MARX_DB_DATASOURCE);
System.out.println("\n.9.\n");
/*if (dbConnection == null && MARX_COUNTER < 10) {
MARX_COUNTER = MARX_COUNTER+1;
LogManager.debug("MARX COUNTER is "+MARX_COUNTER);
String timeout = PropertiesUtil.getProperty("iacs", "MARX_POLL_WAIT");
Thread.sleep(new Long(timeout).longValue());
LogManager.debug("Returning FALSE");
return "false";
} else {
LogManager.debug("MARX COUNTER is "+MARX_COUNTER);
LogManager.debug("Resetting MARX COUNTER to 0 and returning TRUE");
MARX_COUNTER = 0;
return "true";
}*/
if (dbConnection == null) {
String timeout =
PropertiesUtil.getProperty("iacs", "MARX_POLL_WAIT");
LogManager.debug(
"checkMarxConnection: connection is null; about to enter a sleep");
Thread.sleep(new Long(timeout).longValue());
LogManager.debug("checkMarxConnection: returning FALSE");
return "false";
} else {
LogManager.debug(
"checkMarxConnection: connection is not null; returning TRUE");
return "true";
}
} catch (NumberFormatException e1) {
LogManager.error(
"Check MARX Connection: NumberFormatException occurred: "
+ e1.getMessage());
return "false";
} catch (InterruptedException e2) {
LogManager.error(
"Check MARX Connection: InterruptedException occurred: "
+ e2.getMessage());
return "false";
} finally {
try {
dbConnection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public static String createMarxAccount(
String requesterUserId,
String userIdmId,
String userId,
//This is the RACF ID
String userFirstname,
String userLastname,
String userMiddleInitial,
int roleCount,
String roleData,
int ACSCount,
String ACSData,
int userOrgType,
String userOrgName,
String MARX_DB_DATASOURCE,
String MARX_DB_STORPROC_NAME) {
Connection dbConnection = getConnection(MARX_DB_DATASOURCE);
String replyStatus = "";
CallableStatement callableStatement = null;
String query =
"{call " + MARX_DB_STORPROC_NAME + " (?,?,?,?,?,?,?,?,?,?,?,?,?) }";
try {
LogManager.debug(" After getConnection");
callableStatement = dbConnection.prepareCall(query);
LogManager.debug("preparecall is a success");
callableStatement.setString(1, requesterUserId);
LogManager.debug("requesterUserId is a success");
callableStatement.setString(2, userIdmId);
LogManager.debug("IDMiD is a success");
callableStatement.setString(3, userId);
LogManager.debug("userId is a success");
callableStatement.setString(4, userFirstname);
LogManager.debug("userFirstname is a success");
callableStatement.setString(5, userLastname);
LogManager.debug("userLastname is a success");
callableStatement.setString(
6,
(userMiddleInitial == null) ? "" : userMiddleInitial);
LogManager.debug("userMiddleInitial is a success");
//callableStatement.setShort(7, Short.valueOf(roleCount).shortValue());
callableStatement.setShort(7, (short) roleCount);
LogManager.debug("roleCount is a success");
callableStatement.setString(8, roleData);
LogManager.debug("roleData is a success");
//callableStatement.setShort(9, Short.valueOf(ACSCount).shortValue());
callableStatement.setShort(9, (short) ACSCount);
LogManager.debug("ACSCount is a success");
callableStatement.setString(10, ACSData);
LogManager.debug("ACSData is a success");
callableStatement.setShort(11, (short) userOrgType);
LogManager.debug("userOrgType is a success");
if (userOrgName!=null && userOrgName.length()>20) {
userOrgName = userOrgName.substring(0, 20);
}
callableStatement.setString(12, userOrgName);
LogManager.debug("userOrgName is a success");
LogManager.debug(" input args all success");
callableStatement.registerOutParameter(13, Types.CHAR);
LogManager.debug(" After registerOutParameter");
callableStatement.execute();
LogManager.debug(" execute is a success");
replyStatus = callableStatement.getString(13);
} catch (Exception e) {
replyStatus = "100";
try {
dbConnection.rollback();
} catch (Exception ex) {
}
LogManager.error(
"Exception occurred createMarxAccount: " + e.getMessage());
} finally {
try {
if (callableStatement != null) {
callableStatement.close();
}
if (dbConnection != null) {
dbConnection.close();
}
} catch (Exception e) {
}
}
return replyStatus;
}
}