2 Replies Latest reply: Apr 5, 2013 9:07 AM by jtahlborn RSS

    EJB Junits failing for methods returning java.util.List

    Jaspal Singh Saluja
      Hello,

      We started a pilot of automated testing of EJB methods using Junit
      We are using JDK 6, EJB 3.0 and Jdev 11.1.1.4

      Our Junit code is pretty straightforward

      EJB1 ejbHandle = (EJB1 )getEJBHandle( "EJB1 ", "com.abc.xyz", "EJB1" );
      ejbHandle.getMethod1();

      The approach works fine for EJB methods returning other datatypes like String, or void
      But generates this exception for methods returning java.util.List

      As an example

      public List<myDTO> getMethod1()
      {
      List<myDTO> l = new LinkedList<myDTO>();
      ...
      ...

      return l;
      }

      This generates the below exception
      javax.ejb.EJBException: error marshalling return; nested exception is:
           java.io.NotSerializableException: com.abc.xys.myDTO; nested exception is: java.io.NotSerializableException: com.abc.xys.myDTO

      myDTO class is pretty simple

      public class CategoriesDetailsDTO {

      private String key;
      private String value;

      public String getKey() ;

      public String getValue();

      }

      On debugging, I noticed that EJB method code is correctly invoked and control comes upto the return statement
      The return statement on the method generates the stack trace

      javax.ejb.EJBException: error marshalling return; nested exception is:
           java.io.NotSerializableException: com.abc.xys.myDTO; nested exception is: java.io.NotSerializableException: com.abc.xys.myDTO

      weblogic.ejb.container.internal.RemoteBusinessIntfProxy.unwrapRemoteException(RemoteBusinessIntfProxy.java:121)
      weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:96)

      $Proxy4.getMethod1(Unknown Source)
      .......
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      java.lang.reflect.Method.invoke(Method.java:597)
      org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
      org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
      org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
      org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
      org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
      org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
      org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
      org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
      org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
      org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
      org.junit.runners.ParentRunner.run(ParentRunner.java:292)
      Caused by: java.io.NotSerializableException: com.abc.xys.myDTO
      java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
      java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
      java.util.LinkedList.writeObject(LinkedList.java:943)
      java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
      java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)
      java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
      java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
      weblogic.rjvm.MsgAbbrevOutputStream.writeObject(MsgAbbrevOutputStream.java:618)
      weblogic.utils.io.ChunkedObjectOutputStream.writeObject(ChunkedObjectOutputStream.java:63)
      com.avocent.trellis.apps.inventory.ejb.UDPServiceEJB_fx0c4w_UDPServiceEJBRemoteImpl_WLSkel.invoke(Unknown Source)
      weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:667)
      weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:230)
      weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:522)
      weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
      weblogic.security.service.SecurityManager.runAs(SecurityManager.java:146)
      weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:518)
      weblogic.rmi.internal.wls.WLSExecuteRequest.run(WLSExecuteRequest.java:118)
      weblogic.work.ExecuteThread.execute(ExecuteThread.java:207)
      weblogic.work.ExecuteThread.run(ExecuteThread.java:176)


      Any pointers ?