Hello,
I'm using
JBoss 3.2.5.
I'm getting a ClassCastException when I do a JNDI lookup (using J2EE-style JNDI ENC names) of a JavaMail Session from an external application client outside the JBoss container.
The JNDI lookup for the JavaMail Session was successful, but the cast failed. Because I was getting a ClassCastException, I checked the Class Name and Package of the Object that I looked up:
org.jnp.interfaces.Naming Context
Why don't I get an Object of type: javax.mail.Session?
Please note that I'm able to lookup URLs and Environment Variables using J2EE-style JNDI names and they work properly. JavaMail Sessions are the only things that don't completely work.
Here's the client code sample:
Code:
try {
Context jndiContext = new InitialContext();
// Look up the JavaMail Session.
System.out.println("Looking up " +
"java:comp/env/mail/JavaMailSession" +
" ...\n");
Session javaMailSession = (Session)
jndiContext.lookup("java:comp/env/mail/JavaMailSession");
} catch (NamingException ne) {
System.err.println("Couldn't find " +
"java:comp/env/mail/JavaMailSession:" + ne);
}
Here's application-client.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application-client PUBLIC
"-//Sun Microsystems, Inc.//DTD
J2EE Application Client 1.3//EN"
"http://java.sun.com/dtd/application-client_1_3.dtd">
<application-client>
<display-name>MjwClientJAR</display-name>
<env-entry>
<env-entry-name>var/SalesCommissionPct</env-entry-name>
<env-entry-type>java.lang.Float</env-entry-type>
<env-entry-value>.05</env-entry-value>
</env-entry>
<resource-ref>
<res-ref-name>url/BigAutoManufacturer</res-ref-name>
<res-type>java.net.URL</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
<res-ref-name>mail/JavaMailSession</res-ref-name>
<res-type>javax.mail.Session</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</application-client>
Here's jboss-client.xml:
Code:
<!DOCTYPE jboss-client PUBLIC
"-//JBoss//DTD Application Client 3.2//EN"
"http://www.jboss.org/j2ee/dtd/jboss-client_3_2.dtd">
<jboss-client>
<jndi-name>jndi-client</jndi-name>
<resource-ref>
<res-ref-name>url/BigAutoManufacturer</res-ref-name>
<res-url>
http://www.bigAutoManufacturer.com</res-url>
</resource-ref>
<resource-ref>
<res-ref-name>mail/JavaMailSession</res-ref-name>
<jndi-name>
java:/Mail</jndi-name>
</resource-ref>
</jboss-client>
Here's jndi.properties:
Code:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming.client
rg.jnp.interfaces
java.naming.provider.url=jnp://localhost:1099
j2ee.clientName=jndi-client
Both application-client.xml and jboss-client.xml reside in the META-INF directory of a JAR file. This JAR file is on my CLASSPATH and is also included in my deployed EAR file (and is listed as a module in application.xml).
I'm including mail.jar and activation.jar (from JBoss release), jboss-j2ee.jar, jbossall-client.jar, and the directory path for jndi.properties on the client CLASSPATH.
What am I doing wrong? Does anyone have any ideas? Thanks.
Tom