java.rmi.UnmarshalException: error unmarshalling return, java.io

Discussions

EJB design: java.rmi.UnmarshalException: error unmarshalling return, java.io

  1. I am developing an application with Jonas and my environment is as follows:

    -Jonas 4.0.0
    -Tomcat 5.0.19 standalone (my web app uses the remote interfaces).
    -I have amongst others those three jars in my web-inf/lib directory:
    *test_guide.jar(my ejb jar)
    *ejb-2_1-api.jar(from jonas)
    *client.jar(from jonas)


    I come across the following error:
    [code]
    javax.naming.CommunicationException [Root exception is java.rmi.UnmarshalException: error unmarshalling return; nested e
    xception is:
            java.io.StreamCorruptedException]
            at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:92)
            at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:98)
            at javax.naming.InitialContext.lookup(InitialContext.java:347)
            at com.softwareag.test_guide.web.util.PGServiceLocator.getRemoteHome(PGServiceLocator.java:82)
            at com.softwareag.test_guide.web.temp.PGSearch.executeNewSearch(PGSearch.java:25)
            at com.softwareag.test_guide.web.temp.PGSearchManagedBean.newSearchAction(PGSearchManagedBean.java:29)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at net.sourceforge.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:113)
            at net.sourceforge.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:65)
            at javax.faces.component.UICommand.broadcast(UICommand.java:109)
            at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:84)
            at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:142)
            at net.sourceforge.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:254)
            at net.sourceforge.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:85)
            at javax.faces.webapp.FacesServlet.service(FacesServlet.java:97)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:257)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
            at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:184)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
            at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:206)
            at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:833)
            at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:732)
            at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:619)
            at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:688)
            at java.lang.Thread.run(Thread.java:534)
    Caused by: java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
            java.io.StreamCorruptedException
            at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
            at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:88)
            ... 41 more
    Caused by: java.io.StreamCorruptedException
            at java.io.ObjectInputStream$BlockDataInputStream.readBlockHeader(ObjectInputStream.java:2347)
            at java.io.ObjectInputStream$BlockDataInputStream.refill(ObjectInputStream.java:2380)
            at java.io.ObjectInputStream$BlockDataInputStream.skipBlockData(ObjectInputStream.java:2285)
            at java.io.ObjectInputStream.skipCustomData(ObjectInputStream.java:1795)
            at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1772)
            at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
            at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
            at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
            ... 43 more
    -----------------
    com.softwareag.test_guide.web.util.PGServiceLocatorException
            at com.softwareag.test_guide.web.util.PGServiceLocator.getRemoteHome(PGServiceLocator.java:92)
            at com.softwareag.test_guide.web.temp.PGSearch.executeNewSearch(PGSearch.java:25)
            at com.softwareag.test_guide.web.temp.PGSearchManagedBean.newSearchAction(PGSearchManagedBean.java:29)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at net.sourceforge.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:113)
            at net.sourceforge.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:65)
            at javax.faces.component.UICommand.broadcast(UICommand.java:109)
            at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:84)
            at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:142)
            at net.sourceforge.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:254)
            at net.sourceforge.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:85)
            at javax.faces.webapp.FacesServlet.service(FacesServlet.java:97)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:257)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
            at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:184)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
            at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:206)
            at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:833)
            at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:732)
            at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:619)
            at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:688)
            at java.lang.Thread.run(Thread.java:534)
    [/code]

    [code]
    package com.softwareag.test_guide.web.temp;

    import java.rmi.RemoteException;
    import java.util.List;

    import com.softwareag.test_guide.TransferObjects.PGQueryTO;
    import com.softwareag.test_guide.web.util.PGFactory;

    /**
     * @author Julien Martin
     */

    public class PGSearchManagedBean {

    private String category;
    private List postcodes;
    private String name;
    private boolean commentsExist;
    private String sortOrderCriterion;
    private int minimumNote;

    /**
    *
    */
    public String newSearchAction() throws RemoteException { //TODO: Remove that
    System.out.println("----------within new search action--------------");
    PGQueryTO query = PGFactory.getQueryInstance(this);
    PGSearch search = PGFactory.getSearchInstance();
    String results = search.executeNewSearch(query);
    return results;
    }

    /**
    *
    */
    public String nextAction() throws RemoteException { //TODO: Remove that
    PGSearch search = PGFactory.getSearchInstance();
    String issue = search.next();
    return issue;
    }

    /**
    *
    */
    public String previousAction() throws RemoteException { //TODO: Remove that
    PGSearch search = PGFactory.getSearchInstance();
    String issue = search.previous();
    return issue;
    }

    public String getCategory() {
    return category;
    }

    public boolean getCommentsExist() {
    return commentsExist;
    }

    public int getMinimumNote() {
    return minimumNote;
    }

    public String getName() {
    return name;
    }

    public List getPostcodes() {
    return postcodes;
    }

    public String getSortOrderCriterion() {
    return sortOrderCriterion;
    }

    public void setCategory(String string) {
    category = string;
    }

    public void setCommentsExist(boolean bool) {
    commentsExist = bool;
    }

    public void setMinimumNote(int i) {
    minimumNote = i;
    }

    public void setName(String string) {
    name = string;
    }

    public void setPostcodes(List list) {
    postcodes = list;
    }

    public void setSortOrderCriterion(String string) {
    sortOrderCriterion = string;
    }

    }

    [/code]


    [code]
    package com.softwareag.test_guide.web.util;

    import java.util.Collections;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Properties;

    import javax.ejb.EJBHome;
    import javax.ejb.EJBLocalHome;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.rmi.PortableRemoteObject;

    /**
     * @author Julien Martin
     */
    public class PGServiceLocator {

    private InitialContext initialContext;
    private Map cache;
    private Properties props;

    private static PGServiceLocator _instance;

    static {
    try {
    _instance = new PGServiceLocator();
    } catch (PGServiceLocatorException se) {
    System.err.println(se);
    se.printStackTrace(System.err);
    }
    }

    private PGServiceLocator() throws PGServiceLocatorException {
    try {
    props = new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY,PGConstants.INITIAL_CONTEXT_FACTORY);
    props.put(Context.PROVIDER_URL,PGConstants.PROVIDER_URL);
    props.put(Context.SECURITY_PRINCIPAL,PGConstants.SECURITY_PRINCIPAL);
    props.put(Context.SECURITY_CREDENTIALS,PGConstants.SECURITY_CREDENTIALS);
    initialContext = new InitialContext(props);
    cache = Collections.synchronizedMap(new HashMap());
    } catch (NamingException ne) {
    //throw new PGServiceLocatorException(ne);
    throw new PGServiceLocatorException();
    } catch (Exception e) {
    //throw new PGServiceLocatorException(e);
    throw new PGServiceLocatorException();
    }
    }

    static public PGServiceLocator getInstance() {
    return _instance;
    }

    public EJBLocalHome getLocalHome(String jndiHomeName) throws PGServiceLocatorException {
    EJBLocalHome localHome = null;
    try {
    if (cache.containsKey(jndiHomeName)) {
    localHome = (EJBLocalHome) cache.get(jndiHomeName);
    } else {
    localHome = (EJBLocalHome) initialContext.lookup(jndiHomeName);
    cache.put(jndiHomeName, localHome);
    }
    } catch (NamingException nex) {
    //throw new PGServiceLocatorException(nex);
    throw new PGServiceLocatorException();
    } catch (Exception ex) {
    //throw new PGServiceLocatorException(ex);
    throw new PGServiceLocatorException();
    }
    return localHome;
    }

    public EJBHome getRemoteHome(String jndiHomeName, Class homeClassName) throws PGServiceLocatorException {
    EJBHome remoteHome = null;
    try {
    if (cache.containsKey(jndiHomeName)) {
    remoteHome = (EJBHome) cache.get(jndiHomeName);
    } else {
    Object objref = initialContext.lookup(jndiHomeName);
    Object obj = PortableRemoteObject.narrow(objref, homeClassName);
    remoteHome = (EJBHome) obj;
    cache.put(jndiHomeName, remoteHome);
    }
    } catch (NamingException nex) {
    //throw new PGServiceLocatorException(nex);
    System.out.println("-----------------");
    nex.printStackTrace();
    System.out.println("-----------------");
    throw new PGServiceLocatorException();
    } catch (Exception ex) {
    //throw new PGServiceLocatorException(ex);
    throw new PGServiceLocatorException();
    }
    return remoteHome;
    }

    }

    [/code]


    [code]
    package com.softwareag.test_guide.web.temp;

    import java.rmi.RemoteException;
    import java.util.List;

    import javax.ejb.CreateException;

    import com.softwareag.test_guide.TransferObjects.PGQueryTO;
    import com.softwareag.test_guide.searchEngineEJB.PGSearchEngineListHandlerException;
    import com.softwareag.test_guide.searchEngineEJB.PGSearchEngineValueListHandler;
    import com.softwareag.test_guide.searchEngineEJB.PGSearchEngineValueListHandlerHome;
    import com.softwareag.test_guide.web.util.PGServiceLocator;
    import com.softwareag.test_guide.web.util.PGServiceLocatorException;
    import com.softwareag.test_guide.web.util.PGSessionUtil;

    /**
     * @author Julien Martin
     */
    public class PGSearch {

    public String executeNewSearch(PGQueryTO query) throws RemoteException { //TODO: remove that exception
    try {
    //We retrieve the local home object
    //keep/PGSearchEngineValueListHandlerLocalHome pGSearchEngineHome = (PGSearchEngineValueListHandlerLocalHome) PGServiceLocator.getInstance().getLocalHome("PGSearchEngineValueListHandlerEJBHome_L");
    PGSearchEngineValueListHandlerHome pGSearchEngineHome = (PGSearchEngineValueListHandlerHome) PGServiceLocator.getInstance().getRemoteHome("PGSearchEngineValueListHandlerEJBHome", PGSearchEngineValueListHandlerHome.class);
    //We obtain a local interface object from the local home object
    //keep/PGSearchEngineValueListHandlerLocal pGSearchEngine = pGSearchEngineHome.create();
    PGSearchEngineValueListHandler pGSearchEngine = pGSearchEngineHome.create();
    //We put the local interface into the session for later use
    PGSessionUtil.putSearchEngineEJBIntoSession(pGSearchEngine);
    //We execute the search
    boolean containsResults = pGSearchEngine.executeSearch(query);
    System.out.println("------containsResults------->" + containsResults);
    //If the search does return results,
    //1. We fetch the first n elements
    //2. We put the results into the session
    //3. We return the following String
    if (containsResults) {
    List firstResults = pGSearchEngine.getNextElements(0, 15);
    PGSessionUtil.putResultsListIntoSession(firstResults);
    return "displayResults";
    }
    //If the search does not return results, we return the following String
    else {
    return "noResults";
    }

    } catch (CreateException e) {
    e.printStackTrace();
    return null;
    } catch (PGServiceLocatorException e) {
    e.printStackTrace();
    return null;
    } catch (PGSearchEngineListHandlerException e) {
    e.printStackTrace();
    return null;

    }
    }

    public String next() {
    try {
    //PGSearchEngineValueListHandlerLocal pGSearchEngine = PGSessionUtil.getSearchEngineEJBFromSession();
    PGSearchEngineValueListHandler pGSearchEngine = PGSessionUtil.getSearchEngineEJBFromSession();
    List list = pGSearchEngine.getNextElements(15, 20);
    if (!list.isEmpty()) {
    return "displayResults";
    } else {
    return "endOfResults";
    }
    } catch (RemoteException e) {
    // TODO Remove that
    e.printStackTrace();
    return null;
    }
    }

    public String previous() {
    try {
    //PGSearchEngineValueListHandlerLocal pGSearchEngine = PGSessionUtil.getSearchEngineEJBFromSession();
    PGSearchEngineValueListHandler pGSearchEngine = PGSessionUtil.getSearchEngineEJBFromSession();
    List list = pGSearchEngine.getPreviousElements(15, 20);
    if (!list.isEmpty()) {
    return "displayResults";
    } else {
    return "endOfResults";
    }
    } catch (RemoteException e) {
    // TODO Remove that
    e.printStackTrace();
    return null;
    }
    }
    }

    [/code]


    Can anybody help please?

    Thanks in advance,

    Julien Martin.
  2. Some things that I have seen that cause these kinds of errors to be thrown:

    1) Non-serializable objects. Are your Transfer Object's serializable? Or, do they contain references to non-Serializable objects?

    2) Overloaded methods. Sometimes having two methods with the same name confuses the IIOP protocol.

    3) Different class versions on client and server.