2 Replies Latest reply on Dec 19, 2007 2:11 AM by jaikiran pai

    Call an ejb from Servlet in different application

    Bob Petry Newbie

      Has anyone been able to successfully call an ejb from a servlet that is deployed in a separate ear file, where both are deployed via JBoss.

      I have ServletA that is deployed in app1.ear and EJB1 that is deployed in app2.ear.

      I attempt to lookup the ejb from ServletA, but it fails and the following exception is caught
      SEVERE: object is not an instance of declaring class
      java.lang.IllegalArgumentException: object is not an instance of declaring class

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.jboss.ha.framework.interfaces.HARMIClient.invoke(HARMIClient.java
      :258)
      at $Proxy262.lookup(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
      at javax.naming.InitialContext.lookup(InitialContext.java:351)
      at mil.navy.admacs.DiscoveryManager.discover(DiscoveryManager.java:107)

      web.xml for servlet which resides in app2.ear



      <ejb-ref>
      <ejb-ref-name>ejb/User/EJB1</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      com.ssi.ejb.EJB1Home
      mil com.ssi.ejb.EJB1
      </ejb-ref>



      jboss-web.xml for servlet which resides in app2.ear


      <ejb-ref>
      <ejb-ref-name>ejb/User/EJB1</ejb-ref-name>
      <jndi-name>ejb/User/EJB1</jndi-name>
      </ejb-ref>
      ejb-jar.xml file for EJB resides in app1.ear:


      UserBeanSession
      <display-name>UserBeanSession</display-name>
      <ejb-name>UserBean</ejb-name>
      com.ssi.ejb.EJB1Home
      com.ssi.ejb.EJB1
      <ejb-class>com.ssi.ejb.EJB1Session</ejb-class>
      <session-type>Stateless</session-type>


      Any ideas, thanks in advance!

      Bob

        • 1. Re: Call an ejb from Servlet in different application
          Bob Petry Newbie

          Anyone out there, Hello.

          Anyway, here is my latest progress, I have added the lookup code and the exception that I am now getting. The exception is encountered at

          obj = ctx.lookup("ejb/UserAdmin/UserBean);

          Is this a classloading issue?

          Thanks in advance, hopefully someone has a clue as to what this problem is.

          Bob

          Lookup code

          InitialContext ctx = new InitialContext();
          Object obj = null;
          try {
          obj = ctx.lookup("ejb/UserAdmin/UserBean);
          } catch (Exception e) {
          logger.log(Level.ERROR, e.getMessage(), e);
          } }
          UserBeanHome home = (UserBeanHome)obj;
          UserBean remote = (UserBean) home.create();


          Exception

          java.lang.ClassCastException: org.jboss.util.id.GUID cannot be cast to org.jboss
          .util.id.GUID
          at org.jboss.invocation.InvokerInterceptor.readExternal(InvokerInterceptor.java:358)
          at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1792)
          at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751)
          at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
          at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
          at org.jboss.proxy.Interceptor.readExternal(Interceptor.java:80)
          at org.jboss.proxy.ejb.RetryInterceptor.readExternal(RetryInterceptor.java:291)
          at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1792)
          at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751)
          at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
          at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
          at org.jboss.proxy.Interceptor.readExternal(Interceptor.java:80)
          at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1792)
          at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751)
          at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
          at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
          at org.jboss.proxy.Interceptor.readExternal(Interceptor.java:80)
          at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1792)
          at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751)
          at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
          at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
          at org.jboss.proxy.Interceptor.readExternal(Interceptor.java:80)
          at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1792)
          at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751)
          at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
          at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
          at org.jboss.proxy.ClientContainer.readExternal(ClientContainer.java:156)
          at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1792)
          at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751)
          at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
          at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1945)
          at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1869)

          • 2. Re: Call an ejb from Servlet in different application
            jaikiran pai Master

            bpet36,

            You seem to have made progress and appear to be running into a different exception now. Let's continue this discussion in your other thread which you started at http://www.jboss.com/index.html?module=bb&op=viewtopic&t=126192