ClassCastException on DataSource Lookup
fighty Dec 12, 2002 11:48 AMVersions:
JBoss-3.0.3 (with tomcat)
JDK 1.4.1
Oracle 9i
I have the following entry in the oracle-xa-service.xml
================oracle-xa-service.xml==================
<!--make the rar deploy! hack till better deployment-->
jboss.jca:service=RARDeployer
<depends optional-attribute-name="ManagedConnectionFactoryName">
<!--embedded mbean-->
<!--hack-->
<depends optional-attribute-name="OldRarDeployment">jboss.jca:service=RARDeployment,name=Minerva JDBC XATransaction ResourceAdapter
<!--real attributes-->
<config-property name="XADataSourceProperties"
type="java.lang.String">URL=jdbc:oracle:thin:@192.168.217.41:1521:WORKITEM</config-property>
<config-property name="XADataSourceClass"
type="java.lang.String">oracle.jdbc.xa.client.OracleXADataSource</config-property>
<!--set these only if you want only default logins, not through JAAS -->
<config-property name="UserName"
type="java.lang.String"></config-property>
<config-property name="Password"
type="java.lang.String"></config-property>
<!--
Do not try to set transaction isolation level here or you'll get
java.sql.SQLException: ORA-01453: SET TRANSACTION must be first statement of transaction
Read committed is a default isolation level for Oracle, so there
is not real need to set it here. I'll take a look into it later ...maybe.
<config-property name="TransactionIsolation"
type="java.lang.String">TRANSACTION_READ_COMMITTED</config-property>
-->
XAOracleWorkItemDS
<depends optional-attribute-name="ManagedConnectionPool">
<!--embedded mbean-->
0
50
5000
15
<!--criteria indicates if Subject (from security domain) or app supplied
parameters (such as from getConnection(user, pw)) are used to distinguish
connections in the pool. Choices are
ByContainerAndApplication (use both),
ByContainer (use Subject),
ByApplication (use app supplied params only),
ByNothing (all connections are equivalent, usually if adapter supports
reauthentication)-->
ByContainer
<depends optional-attribute-name="CachedConnectionManager">jboss.jca:service=CachedConnectionManager
<!-- Include a login module configuration named InformixXaDbRealm.
Update your login-conf.xml, here is an example for a
ConfiguredIdentityLoginModule:
<application-policy name = "InformixXaDbRealm">
<login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required">
<module-option name = "principal">yourprincipal</module-option>
<module-option name = "userName">yourusername</module-option>
<module-option name = "password">yourpassword</module-option>
<module-option name = "managedConnectionFactoryName">jboss.jca:service=XATxCM,name=InformixXaDS</module-option>
</login-module>
</application-policy>
NOTE: the application-policy name attribute must match SecurityDomainJndiName, and the
module-option name = "managedConnectionFactoryName"
must match the object name of the ConnectionManager you are configuring here.
-->
<!--
WorkItemDbRealm
-->
<depends optional-attribute-name="JaasSecurityManagerService">jboss.security:service=JaasSecurityManager
java:/TransactionManager
============[end]oracle-xa-service.xml[end]==============
and the following in a java class trying to lookup the ds
==================== Java Class =========================
public XAConnection getXAConnection() throws java.rmi.RemoteException {
XAConnection workItemXAConnection = null;
try {
// get the JNDI context
Context ctx = new InitialContext();
if (ctx != null) {
// lookup the resource
OracleXADataSource dsWorkItem = (OracleXADataSource)ctx.lookup("java:/XAOracleWorkItemDS");
if (dsWorkItem != null) {
// Get the xa connection
workItemXAConnection = dsWorkItem.getXAConnection("username", "password");
if (workItemXAConnection == null) {
throw new java.rmi.RemoteException(getClass().getName() +
"getXAConnection()");
}
}
else throw new java.rmi.RemoteException(getClass().getName() +
"getXAConnection()");
}
else throw new java.rmi.RemoteException(getClass().getName() +
"getXAConnection()");
}
catch (NamingException ne) {
throw new java.rmi.RemoteException("error getting context", ne);
}
catch (Exception e) {
throw new java.rmi.RemoteException("error getting XAResource", e);
}
return workItemXAConnection;
}
=================[end]Java Class[end]=====================
This operations fails at runtime because the following line:
---------------------------------------------------
OracleXADataSource dsWorkItem = (OracleXADataSource)ctx.lookup("java:/XAOracleWorkItemDS");
---------------------------------------------------
throws a java.lang.ClassCastException
the following method call shows the return class to be of type com.jboss.resource.adapter.jdbc.JDBCDataSource
---------------------------------------------------
System.out.println("CLASS TYPE " + ctx.lookup("java:/XAOracleWorkItemDS).getClass().getName());
---------------------------------------------------
Im just looking to get a class of type XAOracleWorkItemDS ... If anyone could help that would be great.. if ive omitted any useful info please let me know
Thx
F