5 Replies Latest reply on Sep 7, 2010 4:07 PM by juankprada

    Client wont connect to remote interface of EJB

    juankprada

      Hi guys, I'm really new to EJB and JEE in general.

      So far im trying to make this EJB to work with no succes til now. I really dont know what is the problem. I'm following this book and I tried the examples and all works fine in a local server, but now, i deployed my beans to an external server, with a public IP, and I cant seem to get things work.

       

      The Bean is this:

       

      package server.ejb.gmail;
      
      import javax.ejb.Stateless;
      import com.google.gdata.data.appsforyourdomain.AppsForYourDomainException;
      import com.google.gdata.client.appsforyourdomain.*;
      import sample.appsforyourdomain.*;
      
      @Stateless
      public class GmailBean implements GmailBeanRemote, GmailBeanLocal {
          
          public void ConexionGmail()
          {
              
              AppsForYourDomainClient client = null;
              try {
                  client = new AppsForYourDomainClient("user@domain.com",
                          "password", "domain.com");
                  
                  System.out.println("Hello world");
              } catch (Exception e) {
      
                  System.out.println("Error conexion gmail:" + e.getMessage());
      
              }
          }
      
      }
      

       

      GmailBeanRemote looks like this:

       

       

      package server.ejb.gmail;
      import javax.ejb.Remote;
      
      @Remote
      public interface GmailBeanRemote {
           public void ConexionGmail();
      }
      

       

      GmailBeanLocal is exactly like the remote counterpart, the only difference is the tag which uses @Local instead of @Remote

       

      The client Im using is this:

       

       

      package client.usuario;
      
      import java.util.Properties;
      
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import javax.rmi.PortableRemoteObject;
      
      import server.ejb.gmail.GmailBeanRemote;
      import server.ejb.usuario.UsuarioBeanRemote;
      
      public class CrearUsuario {
      
         public static void main(String[] args) {
              try {
                  Properties p = new Properties();
                  p.put(Context.INITIAL_CONTEXT_FACTORY,
                          "org.jnp.interfaces.NamingContextFactory");
                  
                  p.put(Context.URL_PKG_PREFIXES,
                          "org.jboss.naming:org.jnp.interfaces");
                  
                  p.put(Context.PROVIDER_URL, "jnp://myhost:1099");
                  
                  Context ctx = new InitialContext(p);
                  
                  Object ref = ctx.lookup("GmailBean/remote");
                  GmailBeanRemote ebr = (GmailBeanRemote) PortableRemoteObject.narrow(ref, GmailBeanRemote.class);
                  ebr.ConexionGmail();
              } catch (NamingException e)
              {
                  e.printStackTrace();
              }
          }
      
      }
      

       

      If there is any way the JNDI output is useful, here it is:

       

       

      +- UserTransactionSessionFactory (proxy: $Proxy112 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
        +- UUIDKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory)
        +- HiLoKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory)
        +- SecureDeploymentManager (class: org.jnp.interfaces.NamingContext)
        |   +- remote[link -> DeploymentManager] (class: javax.naming.LinkRef)
        +- SecureManagementView (class: org.jnp.interfaces.NamingContext)
        |   +- remote[link -> ManagementView] (class: javax.naming.LinkRef)
        +- DeploymentManager (class: org.jboss.aop.generatedproxies.AOPProxy$4)
        +- UsuarioBean (class: org.jnp.interfaces.NamingContext)
        |   +- local (class: Proxy for: server.ejb.usuario.UsuarioBeanLocal)
        |   +- local-server.ejb.usuario.UsuarioBeanLocal (class: Proxy for: server.ejb.usuario.UsuarioBeanLocal)
        |   +- remote-server.ejb.usuario.UsuarioBeanRemote (class: Proxy for: server.ejb.usuario.UsuarioBeanRemote)
        |   +- remote (class: Proxy for: server.ejb.usuario.UsuarioBeanRemote)
        +- XAConnectionFactory (class: org.hornetq.jms.client.HornetQConnectionFactory)
        +- ProfileService (class: org.jboss.aop.generatedproxies.AOPProxy$2)
        +- SecureProfileService (class: org.jnp.interfaces.NamingContext)
        |   +- remote[link -> ProfileService] (class: javax.naming.LinkRef)
        +- queue (class: org.jnp.interfaces.NamingContext)
        |   +- DLQ (class: org.hornetq.jms.client.HornetQQueue)
        |   +- ExpiryQueue (class: org.hornetq.jms.client.HornetQQueue)
        +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
        +- ConnectionFactory (class: org.hornetq.jms.client.HornetQConnectionFactory)
        +- jmx (class: org.jnp.interfaces.NamingContext)
        |   +- invoker (class: org.jnp.interfaces.NamingContext)
        |   |   +- RMIAdaptor (class: javax.management.MBeanServerConnection)
        |   +- rmi (class: org.jnp.interfaces.NamingContext)
        |   |   +- RMIAdaptor (class: javax.management.MBeanServerConnection)
        +- ProxyFactory (class: org.jnp.interfaces.NamingContext)
        |   +- UsuarioUnico (class: org.jnp.interfaces.NamingContext)
        |   |   +- UsuarioBean (class: org.jnp.interfaces.NamingContext)
        |   |   |   +- UsuarioBean (class: org.jnp.interfaces.NamingContext)
        |   |   |   |   +- remote (proxy: $Proxy197 implements interface org.jboss.ejb3.proxy.impl.factory.session.SessionSpecProxyFactory,interface org.jboss.ejb3.proxy.impl.factory.session.SessionProxyFactory,interface org.jboss.ejb3.proxy.impl.factory.ProxyFactory)
        |   |   +- GmailBean (class: org.jnp.interfaces.NamingContext)
        |   |   |   +- GmailBean (class: org.jnp.interfaces.NamingContext)
        |   |   |   |   +- remote (proxy: $Proxy197 implements interface org.jboss.ejb3.proxy.impl.factory.session.SessionSpecProxyFactory,interface org.jboss.ejb3.proxy.impl.factory.session.SessionProxyFactory,interface org.jboss.ejb3.proxy.impl.factory.ProxyFactory)
        +- BeanValidatorFactories (class: org.jnp.interfaces.NamingContext)
        +- persistence.unit:unitName=#timerdb (class: org.hibernate.impl.SessionFactoryImpl)
        +- TomcatAuthenticators (class: java.util.Properties)
        +- GmailBean (class: org.jnp.interfaces.NamingContext)
        |   +- local (class: Proxy for: server.ejb.gmail.GmailBeanLocal)
        |   +- remote (class: Proxy for: server.ejb.gmail.GmailBeanRemote)
        |   +- local-server.ejb.gmail.GmailBeanLocal (class: Proxy for: server.ejb.gmail.GmailBeanLocal)
        |   +- remote-server.ejb.gmail.GmailBeanRemote (class: Proxy for: server.ejb.gmail.GmailBeanRemote)
        +- XAThroughputConnectionFactory (class: org.hornetq.jms.client.HornetQConnectionFactory)
        +- ManagementView (class: org.jboss.aop.generatedproxies.AOPProxy$3)
        +- ThroughputConnectionFactory (class: org.hornetq.jms.client.HornetQConnectionFactory)
      
      
      

       

      I dont know what to do to make it work, so any help would be really appreciated.

       

      Thanks

        • 1. Re: Client wont connect to remote interface of EJB
          jaikiran

          Juan, welcome to the forums!

           

          What error or exception do you get when you run that program? Please post the entire exception stacktrace. Also which version of JBoss AS are you using?

          • 2. Re: Client wont connect to remote interface of EJB
            juankprada

            jaikirian, thanks for your quick response,

             

            The complete exception stack trace output in the console is this:

             

             

            javax.naming.NamingException: Could not dereference object [Root exception is java.lang.reflect.UndeclaredThrowableException]
                at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1508)
                at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:824)
                at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688)
                at javax.naming.InitialContext.lookup(Unknown Source)
                at client.usuario.CrearUsuario.main(CrearUsuario.java:31)
            Caused by: java.lang.reflect.UndeclaredThrowableException
                at $Proxy0.createProxyBusiness(Unknown Source)
                at org.jboss.ejb3.proxy.impl.objectfactory.session.SessionProxyObjectFactory.createProxy(SessionProxyObjectFactory.java:129)
                at org.jboss.ejb3.proxy.impl.objectfactory.session.stateless.StatelessSessionProxyObjectFactory.getProxy(StatelessSessionProxyObjectFactory.java:79)
                at org.jboss.ejb3.proxy.impl.objectfactory.ProxyObjectFactory.getObjectInstance(ProxyObjectFactory.java:161)
                at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
                at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1483)
                at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1500)
                ... 4 more
            Caused by: java.lang.ClassNotFoundException: org.jboss.ejb3.async.impl.interceptor.AsynchronousInterceptor
                at org.jboss.remoting.serialization.ClassLoaderUtility.loadClass(ClassLoaderUtility.java:103)
                at org.jboss.remoting.loading.RemotingClassLoader.loadClass(RemotingClassLoader.java:86)
                at java.lang.Class.forName0(Native Method)
                at java.lang.Class.forName(Unknown Source)
                at org.jboss.remoting.loading.ObjectInputStreamWithClassLoader.resolveClass(ObjectInputStreamWithClassLoader.java:179)
                at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
                at java.io.ObjectInputStream.readClassDesc(Unknown Source)
                at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
                at java.io.ObjectInputStream.readObject0(Unknown Source)
                at java.io.ObjectInputStream.readArray(Unknown Source)
                at java.io.ObjectInputStream.readObject0(Unknown Source)
                at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
                at java.io.ObjectInputStream.readSerialData(Unknown Source)
                at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
                at java.io.ObjectInputStream.readObject0(Unknown Source)
                at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
                at java.io.ObjectInputStream.readSerialData(Unknown Source)
                at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
                at java.io.ObjectInputStream.readObject0(Unknown Source)
                at java.io.ObjectInputStream.readObject(Unknown Source)
                at org.jboss.aop.joinpoint.InvocationResponse.readExternal(InvocationResponse.java:119)
                at java.io.ObjectInputStream.readExternalData(Unknown Source)
                at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
                at java.io.ObjectInputStream.readObject0(Unknown Source)
                at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
                at java.io.ObjectInputStream.readSerialData(Unknown Source)
                at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
                at java.io.ObjectInputStream.readObject0(Unknown Source)
                at java.io.ObjectInputStream.readObject(Unknown Source)
                at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObjectVersion2_2(JavaSerializationManager.java:238)
                at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObject(JavaSerializationManager.java:138)
                at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:123)
                at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.versionedRead(MicroSocketClientInvoker.java:1299)
                at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.transport(MicroSocketClientInvoker.java:907)
                at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:167)
                at org.jboss.remoting.Client.invoke(Client.java:1927)
                at org.jboss.remoting.Client.invoke(Client.java:770)
                at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:60)
                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                at org.jboss.ejb3.proxy.impl.remoting.IsLocalProxyFactoryInterceptor.invoke(IsLocalProxyFactoryInterceptor.java:104)
                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)
                at $Proxy0.createProxyBusiness(Unknown Source)
                at org.jboss.ejb3.proxy.impl.objectfactory.session.SessionProxyObjectFactory.createProxy(SessionProxyObjectFactory.java:129)
                at org.jboss.ejb3.proxy.impl.objectfactory.session.stateless.StatelessSessionProxyObjectFactory.getProxy(StatelessSessionProxyObjectFactory.java:79)
                at org.jboss.ejb3.proxy.impl.objectfactory.ProxyObjectFactory.getObjectInstance(ProxyObjectFactory.java:161)
                at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
                at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1483)
                at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1500)
                at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:824)
                at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688)
                at javax.naming.InitialContext.lookup(Unknown Source)
                at client.usuario.CrearUsuario.main(CrearUsuario.java:31)
                at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:72)
                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                at org.jboss.ejb3.proxy.impl.remoting.IsLocalProxyFactoryInterceptor.invoke(IsLocalProxyFactoryInterceptor.java:104)
                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)
                ... 11 more
            

             

             

            -- UPDATE --

             

            I forgot to say that I'm using JBoss AS 6.0

            • 3. Re: Client wont connect to remote interface of EJB
              jaikiran

              Have you included the JBOSS_HOME/client/jbossall-client.jar (and all other jars that are referenced in it's META-INF/MANIFEST.MF) in your client classpath? Make sure you include the exact same jars that are shipped in the AS version that you are using.

              1 of 1 people found this helpful
              • 4. Re: Client wont connect to remote interface of EJB
                juankprada

                Yes, all JBoss jars are included. I'm using JBoss Tools with in Eclipse, and everything works just fine when I test un a local server (i.e, using jnp://localhost:1099 for PROVIDER_URL)

                 

                So far I've seen that the error trace makes references to the following line:

                 

                 

                Object ref = ctx.lookup("GmailBean/remote");
                

                 

                As I said, things work locally, but when deploying the beans to a remote server it doesnt work.

                 

                 

                thanks

                • 5. Re: Client wont connect to remote interface of EJB
                  juankprada

                  Ok so I got it working. Apparently server admins changed JBoss AS to a different version used in the development departmen. We synced versions in all departments and now things are working just fine.

                   

                  Thanks jaikiran pai for your answer, it was what lead me to figure out this thing.