1 Reply Latest reply on Nov 14, 2004 3:40 PM by Tom Marrs

    ClassCastException - JavaMail & JNDI in Application Client

    Tom Marrs Newbie

      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:

       try {
       Context jndiContext = new InitialContext();
       // Look up the JavaMail Session.
       System.out.println("Looking up " +
       "java:comp/env/mail/JavaMailSession" +
       " ...\n");
       Session javaMailSession = (Session)
       } catch (NamingException ne) {
       System.err.println("Couldn't find " +
       "java:comp/env/mail/JavaMailSession:" + ne);

      Here's application-client.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE application-client PUBLIC
       "-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.3//EN"

      Here's jboss-client.xml:
      <!DOCTYPE jboss-client PUBLIC
       "-//JBoss//DTD Application Client 3.2//EN"

      Here's jndi.properties:

      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.


        • 1. Re: ClassCastException - JavaMail & JNDI in Application Clie
          Tom Marrs Newbie

          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

          ?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.