2 Replies Latest reply on Jun 6, 2009 2:46 PM by Dee Kay

    JNDI-lookup returns

    Dee Kay Newbie

      hi all,

      i'm developing an application under JBoss 5.0.0 with EJB3.
      I'm using stateful EJBs, what works really fine inside the AS (i'm calling them from a deployed web-app).
      All JNDI lookups from the webapp do return Proxy-interfaces as expected.

      I also try to get my EJBs from an J2SE-client.
      But here i get only references to "javax.naming.Reference"-objects.
      Where's my fault?


      Output of my J2SE-application:

      Context <javax.naming.InitialContext@6d632c2d>
      >>>> jndi.properties
      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.provider.url=localhost:1099
      java.naming.factory.url.pkgs=org.jnp.interfaces
      <<<<<
      
      Proxy</CSDatabase/ServerWebClientRemote/remote> class<javax.naming.Reference>
      


      JNDI-View (Extract):
      java:comp namespace of the component jboss.j2ee:ear=CSDatabase.ear,jar=CSDatabaseEJB.jar,name=ServerWebClientRemote,service=EJB3 :
       +- EJBContext (class: javax.ejb.EJBContext)
       +- TransactionSynchronizationRegistry[link -> java:TransactionSynchronizationRegistry] (class: javax.naming.LinkRef)
       +- UserTransaction (class: org.jboss.ejb3.tx.UserTransactionImpl)
       +- env (class: org.jnp.interfaces.NamingContext)
       | +- entityManager (class: org.jboss.jpa.tx.TransactionScopedEntityManager)
       | +- de.myapplication.general.database.server.services.ServerWebClientRemote (class: org.jnp.interfaces.NamingContext)
       | | +- entityManager (class: org.jboss.jpa.tx.TransactionScopedEntityManager)
       +- ORB[link -> java:/JBossCorbaORB] (class: javax.naming.LinkRef)
      
      
      
      Global JNDI Namespace
      
      +- CSDatabase (class: org.jnp.interfaces.NamingContext)
       | +- ServerWebClientRemote (class: org.jnp.interfaces.NamingContext)
       | | +- remote (class: Proxy for: de.myapplication.general.database.server.services.IServerWebClientRemote)
       | | +- remote-de.myapplication.general.database.server.services.IServerWebClientRemote (class: Proxy for: de.myapplication.general.database.server.services.IServerWebClientRemote)
      




      J2SE-Clientapp (see jndi.properties in Output above):
      import java.util.Properties;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      
      
      public class JNDITest {
      
       private Context context = null;
       private Properties contextProperties = null;
      
       public JNDITest() {
       }
      
       public void connect() throws Exception {
       if(context == null) {
       context = contextProperties == null ? new InitialContext() : new InitialContext(contextProperties);
       System.out.println("Context <"+context+">");
       System.out.println(">>>> jndi.properties");
       for(Object key : context.getEnvironment().keySet()) {
       System.out.println(key+"="+context.getEnvironment().get(key));
       }
       System.out.println("<<<<<");
       System.out.println("");
       }
       }
      
       public Object loadBean(String key) throws Exception {
       Object proxy = null;
       try {
       proxy = context.lookup(key);
       } catch(Exception excp) {
       System.out.println("Key<"+key+"> Proxy<"+proxy+"> Exception<"+excp.getMessage()+">");
       throw excp;
       }
       System.out.println("Proxy<"+key+"> class<"+proxy.getClass().getName()+">");
       return proxy;
       }
      
      
       public static void main(String[] args) throws Exception {
       JNDITest test = new JNDITest();
       test.connect();
       test.loadBean("/CSDatabase/ServerWebClientRemote/remote");
       }
      }
      




      Additional information:

      - My EAR does not use JBoss-specific JARs (i want to stay portable).
       hibernate-annotations.jar (for setting indexes)
       log4j.jar
       commons-beanutils-1.8.0.jar
       javaee.jar
       jsf-impl.jar
       jsf-api.jar
       jstl-1.2.jar
      


      - My J2SE client only imports the necessary jars
       jnp-client.jar
       commons-logging.jar
       jboss-logging-spi.jar
       log4j.jar
       slf4j-jboss-logging.jar
       jboss-messaging-client.jar
       jboss-javaee.jar
       jboss-aop-client.jar
       jboss-mdr.jar
      




      Thanks in advance

        • 1. Re: JNDI-lookup returns
          Peter Johnson Master

          I will go out on a limb (because I have not run you code that prints out the class for the looked-up EJB) and declare that this is not a problem. When accessing an EJB remotely, you get a proxy to the EJB. You should be able to cast the resulting object to the remote interface.

          • 2. Re: JNDI-lookup returns
            Dee Kay Newbie

            Casting to my the underlying remote-interface results in a class-cast exception (that was the primary motivation for this thread....).

            Adding all client libs from 5.10GA did solve the problem but adding always all libs in my J2SE-client-application is not my aim because i'll distribute it using JNLP (it's about 40MB).

            But nevertheless it's really curious that my primary JAR-combination works fine but returns wrong interfaces.

            Thanks

            Daniel