• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ClassCastException - JavaMail & JNDI in Application Client

 
Author
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Tom Marrs
Author
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I can answer my own question. I set everything up correctly (that�s why I could use the Environment Variable and URL with J2EE-style JNDI ENC names) on the client side. However, according to Ingo Kl�ckl, you can't access JNDI resources bound under the java:/ namespace. Here's an excerpt from Ingo Kl�ckl's web page
(http://www.2k-software.de/ingo/jbossjndi.html):



�java: is an ENC which is visible only in the JBoss VM. It holds references to objects which are only [sic] senseful in the JBoss environment, like data sources or other resources.�



So, the short answer is: you can�t access a JavaMail Session (a DataSource) from outside the container because JBoss binds this under its internal java: namespace, so you can�t access outside of JBoss� VM.



Duh! I should've remembered this sooner. If only I�d read my own research more closely and much sooner.



Tom
 
reply
    Bookmark Topic Watch Topic
  • New Topic