将字符串转换回 CORBA 对象引用时出错

Posted

技术标签:

【中文标题】将字符串转换回 CORBA 对象引用时出错【英文标题】:Getting errors while converting a string back to CORBA object reference 【发布时间】:2014-11-03 05:04:50 【问题描述】:

这是我的服务器类:

import java.io.FileNotFoundException;
import java.io.PrintWriter;

import org.omg.CORBA.ORB;
import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;
import org.omg.PortableServer.POAManagerPackage.AdapterInactive;
import org.omg.PortableServer.POAPackage.ObjectNotActive;
import org.omg.PortableServer.POAPackage.ServantAlreadyActive;
import org.omg.PortableServer.POAPackage.WrongPolicy;

public class BehaviorServer 

    /**
     * @param args
     * @throws InvalidName 
     * @throws WrongPolicy 
     * @throws ServantAlreadyActive 
     * @throws ObjectNotActive 
     * @throws FileNotFoundException 
     * @throws AdapterInactive 
     */
    public static void main(String[] args) throws InvalidName, ServantAlreadyActive, WrongPolicy, ObjectNotActive, FileNotFoundException, AdapterInactive 
        ORB orb=ORB.init(args,null);
        POA rootPOA=POAHelper.narrow(orb.resolve_initial_references("RootPOA"));

        BehaviorImpl aBehavior=new BehaviorImpl();
        byte[] id=rootPOA.activate_object(aBehavior);
        org.omg.CORBA.Object ref=rootPOA.id_to_reference(id);

        String ior=orb.object_to_string(ref);
        System.out.println(ior);
        PrintWriter file=new PrintWriter("ior.txt");
        file.println(ior);

        rootPOA.the_POAManager().activate();
        orb.run();
    


我的客户:

public class BehaviorClient 

    /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException 
        // TODO Auto-generated method stub
        ORB orb=ORB.init(args,null);
        BufferedReader br=new BufferedReader(new FileReader("ior.txt"));
        String ior=br.readLine();
        br.close();

        org.omg.CORBA.Object o=orb.string_to_object(ior);
        Behavior aBehavior=BehaviorHelper.narrow(o);
        aBehavior.eat();

    


我得到的错误:

Nov 02, 2014 11:58:00 PM com.sun.corba.se.impl.orb.ORBImpl string_to_object
WARNING: "IOP00110201: (BAD_PARAM) Null parameter"
org.omg.CORBA.BAD_PARAM:   vmcid: SUN  minor code: 201  completed: No
    at com.sun.corba.se.impl.logging.ORBUtilSystemException.nullParam(Unknown Source)
    at com.sun.corba.se.impl.logging.ORBUtilSystemException.nullParam(Unknown Source)
    at com.sun.corba.se.impl.orb.ORBImpl.string_to_object(Unknown Source)
    at animal.BehaviorClient.main(BehaviorClient.java:22)

我查看了有关此问题的其他问题,但对我没有帮助。 查了这些: Bad_Param in java CORBA 尝试初始化我的 ORB Orb Initialization

【问题讨论】:

【参考方案1】:

ior为空,表示oir.txt为空,是你写的时候没有关闭文件造成的。在println() 之后添加close()

【讨论】:

以上是关于将字符串转换回 CORBA 对象引用时出错的主要内容,如果未能解决你的问题,请参考以下文章

CORBA IDL 到 C++ - 字符与无符号字符?

C语言将字符串转换为数字出错,请教高手

在 ReactJS 应用程序中将字符串转换为 JSON 对象时出错

损坏的 CORBA 对象引用

json字符串转对象,遇到空字符串会抛异常吗

C++ 我将一个const char*的字符串转换为string出错