2 Replies Latest reply on Aug 6, 2006 8:50 AM by Flavio Pompermaier

    HELP: Looking up to java:comp namespace problem!!

    Flavio Pompermaier Newbie

      Hi to all!
      I hope someone can help me!
      I've read a lot of threads similar to mine, but none solved my question..

      In my project, as specified by socumentation, only Global JNDI Namespaces are visible from remote client., whereas java: are not.
      But now, I would try to access from my Message-driven bean to the Java Mail Service of JBoss, located ad java:/Mail.

      From what I read I must istantiate a new void Initial context and lookup to java:comp/env/mail/Mail, but if I do so it seems that no-lookup can be done!!
      In fact this is the error output, that is given when i lookup also to "":

      javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
       at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
       at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247) .....


      So, I turn around the problem binding the javaMail service to Mail (I moved its name to the global JNDI namespace).
      If I do so now I can lookup the resource, but now I get an error when I try to bound it because i do

      session = (javax.mail.Session)PortableRemoteObject.narrow(
       c.lookup("Mail"), javax.mail.Session.class);

      and the system give me the sequent error:

      Exception in thread "main" java.lang.ClassCastException...........
      Caused by: java.lang.ClassCastException: Class javax.mail.Session is not a valid remote interface
       at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:225)
       ... 3 more

      I think that even if I solve the first problem remains out the second...Does anybody know hot to get it out?

      Please someone help me!!

        • 1. Re: HELP: Looking up to java:comp namespace problem!!
          Frank Langelage Master

          To get a mail session via "java:comp/env/Mail" I declared this tags for xdoclet:

           * @ejb.resource-ref
           * res-ref-name="Mail"
           * res-type="javax.mail.Session"
           * res-auth="Container"
           * @jboss.resource-ref
           * res-ref-name="Mail"
           * jndi-name="java:/Mail"

          Using the global namespace you simply do a lookup of "java:/Mail".
          No narrowing.

          • 2. Re: HELP: Looking up to java:comp namespace problem!!
            Flavio Pompermaier Newbie

            Thanks for the reply, but I solved the problem myself!
            The problem was that I was trying to access the java: namespace from outside a bean and my descriptor file was wrong!

            With the following all goes right:

            For example, in my entity bean I want to refer at java:/Mail so I must declare in the ejb-jar the following:


            and in the file jboss.xml:


            So in my entyty bean (LineOrderBean.java for example) I can do:

             session = (javax.mail.Session) c.lookup("java:comp/env/mail/Mail");

            I hope this can be helpful for somebody..