javacorbaiiop

Getting errors while converting a string back to CORBA object reference


This is my server class :

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();
    }

}

My client:

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();

    }

}

The error I am getting:

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)

I've looked at the other questions posted on this problem but it doesn't help me. Looked up these: Bad_Param in java CORBA Tried initializing my ORB Orb Initialization


Solution

  • ior is null, which implies that oir.txt is empty, which is caused by failing to close the file when you wrote it. Add a close() after the println().