javaee-java.rmi.marshalexception发送集合

azpvetkf  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(312)

我正在为分布式系统课程开发一个javaee项目。我想在客户机和ejb之间传递类a的不同示例。在以下情况下一切正常:
向ejb发送类a的示例
从ejb接收类a的示例
从ejb接收set
向ebj发送一组
但是,当我想从客户机向ebj发送一个set时,我会收到org.omg.corba.marshal:警告:00810057:无法加载class rental.a(我在下面附上了日志)。
我不明白为什么它说它不能加载类,因为它只发送一个示例或从ejb接收一组a。
我正在使用以下内容:
java 8
netbeans 8.2版
玻璃鱼4.1.1
这就是我想绕过的物体。

package rental;

import java.io.Serializable;

public class A implements Serializable {

    private String name;

    public A(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

这是ejb方法的接口。

package session;

import java.util.Date;
import java.util.List;
import java.util.Set;
import javax.ejb.Remote;
import rental.A;

@Remote
public interface ReservationSessionRemote {

    public void reveiveA(A a) throws Exception;

    // =========== THIS METHOD FAILS ==============
    public void receiveSetOfA(Set<A> setA) throws Exception;

    public A sendA(String name) throws Exception;

    public void receiveSetOfString(Set<String> setString) throws Exception;

    public Set<A> sendSetA() throws Exception;

}

这是ejb的实现。

import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import rental.A;

@Stateful
public class ReservationSession implements ReservationSessionRemote {

    private static final Logger logger = Logger.getLogger(ReservationSession.class.getName());

    @Override
    public void reveiveA(A a) throws Exception {
        logger.log(Level.INFO, "Received A with value{0}", a.getName());
    }

    @Override
    public A sendA(String name) throws Exception {
        logger.log(Level.INFO, "Sending A with name {0}", name);
        return new A(name);
    }

    // =========== THIS METHOD FAILS ==============
    @Override  
    public void receiveSetOfA(Set<A> setA) throws Exception {
        logger.log(Level.INFO, "Received set of A of size {0}", setA.size());
        setA.forEach((a) -> {
            logger.info(a.getName());
        });
    }

    @Override
    public void receiveSetOfString(Set<String> setString) throws Exception {
        logger.log(Level.INFO, "Received set of String of size {0}", setString.size());
        setString.forEach((s) -> {
            logger.info(s);
        });
    }

    @Override
    public Set<A> sendSetA() throws Exception {
        logger.info("Sending set<A>");
        Set<A> setA = new HashSet<>();
        setA.add(new A("a1-SERVER"));
        setA.add(new A("a2-SERVER"));
        setA.add(new A("a4-SERVER"));
        return setA;
    }
}

这是一个客户端,我在其中运行一个小脚本来测试上面描述的所有场景。

public class Main {

    private static final Logger logger = Logger.getLogger(Main.class.getName());

    public static void main(String[] args) throws Exception {        
        final String scriptFile = "trips1";
        //logger.log(Level.INFO, "Running file {0}", new Object[]{scriptFile});
        new Main().testConnection();
    }

    protected ReservationSessionRemote getNewReservationSession() throws Exception {
        logger.log(Level.INFO, "[CLIENT] Retrieving SESSION");
        InitialContext context = new InitialContext();
        return (ReservationSessionRemote) context.lookup(ReservationSessionRemote.class.getName());
    }

    private void testConnection() throws Exception {
        logger.info("TESTING CONNECTION FOR SERIALIZATION ISSUES");
        ReservationSessionRemote session = getNewReservationSession();
        logger.info("Retrieved ReservationSession");
        session.reveiveA(new A("A-FROM-CLIENT"));
        A a = session.sendA("A-FROM-SERVER");
        logger.log(Level.INFO, "Received A {0}", a.getName());
        try {
            Set<A> setA = new HashSet<>();
            setA.add(new A("a1"));
            setA.add(new A("a2"));
            setA.add(new A("a3"));
            session.receiveSetOfA(setA);  // =========== THIS FAILS ==============
            logger.info("SUCCESSFULY sent set<A>");
        } catch(Exception e) {
            logger.info("COULD NOT SEND set<A>" + e.getMessage());
            //e.printStackTrace();
        }
        try {
            Set<String> setString = new HashSet<>();
            setString.add("s1");
            setString.add("s2");
            setString.add("s3");
            session.receiveSetOfString(setString);
            logger.info("SUCCESSFULY sent set<String>");
        } catch(Exception e) {
            logger.info("COULD NOT SEND set<String>");
        }
        try {
            Set<A> setA = session.sendSetA();
            logger.info("RECEIVED set<A>");
            setA.forEach((x) -> logger.info(x.getName()));
        } catch(Exception e) {
           logger.info("COULD NOT RECEIVE set<A>");
        }
    }
}

这是客户端的日志。

Nov 14, 2020 11:48:00 PM client.Main testConnection
INFO: TESTING CONNECTION FOR SERIALIZATION ISSUES
Nov 14, 2020 11:48:00 PM client.Main getNewReservationSession
INFO: [CLIENT] Retrieving SESSION
Nov 14, 2020 11:48:04 PM client.Main testConnection
INFO: Retrieved ReservationSession
Nov 14, 2020 11:48:04 PM client.Main testConnection
INFO: Received A A-FROM-SERVER
Nov 14, 2020 11:48:04 PM client.Main testConnection
INFO: COULD NOT SEND set<A>java.rmi.MarshalException: CORBA MARSHAL 1330446393 Maybe; nested exception is: 
    org.omg.CORBA.MARSHAL: ----------BEGIN server-side stack trace----------
org.omg.CORBA.MARSHAL: WARNING: 00810057: Could not load class rental.A  vmcid: OMG  minor code: 57 completed: Maybe
    at com.sun.proxy.$Proxy222.couldNotFindClass(Unknown Source)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:983)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:813)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_abstract_interface(CDRInputStream_1_0.java:806)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_abstract_interface(CDRInputStream_1_0.java:796)
    at com.sun.corba.ee.impl.encoding.CDRInputObject.read_abstract_interface(CDRInputObject.java:544)
    at com.sun.corba.ee.impl.io.IIOPInputStream.readObjectDelegate(IIOPInputStream.java:373)
    at com.sun.corba.ee.impl.io.IIOPInputStream.readObjectOverride(IIOPInputStream.java:525)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:425)
    at java.util.HashSet.readObject(HashSet.java:341)
    at sun.reflect.GeneratedMethodAccessor99.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.corba.ee.impl.io.IIOPInputStream.invokeObjectReader(IIOPInputStream.java:1813)
    at com.sun.corba.ee.impl.io.IIOPInputStream.inputObject(IIOPInputStream.java:1195)
    at com.sun.corba.ee.impl.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:407)
    at com.sun.corba.ee.impl.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:307)
    at com.sun.corba.ee.impl.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:273)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.readRMIIIOPValueType(CDRInputStream_1_0.java:893)
    at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:995)
    at com.sun.corba.ee.impl.encoding.CDRInputObject.read_value(CDRInputObject.java:518)
    at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$14.read(DynamicMethodMarshallerImpl.java:383)
    at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.readArguments(DynamicMethodMarshallerImpl.java:450)
    at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:171)
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
    at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)

----------END server-side stack trace----------  vmcid: OMG  minor code: 57 completed: Maybe
Nov 14, 2020 11:48:04 PM client.Main testConnection
INFO: SUCCESSFULY sent set<String>
Nov 14, 2020 11:48:04 PM client.Main testConnection
INFO: RECEIVED set<A>
Nov 14, 2020 11:48:04 PM client.Main lambda$testConnection$0
INFO: a4-SERVER
Nov 14, 2020 11:48:04 PM client.Main lambda$testConnection$0
INFO: a2-SERVER
Nov 14, 2020 11:48:04 PM client.Main lambda$testConnection$0
INFO: a1-SERVER

ejb日志。这里根本没有打印错误。

Info:   Received A with valueA-FROM-CLIENT
Info:   Sending A with name A-FROM-SERVER
Info:   Received set of String of size 3
Info:   s3
Info:   s1
Info:   s2
Info:   Sending set<A>

对不起,如果我没有很好地组织后,这是我第一次张贴一个问题。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题