[jacorb-developer] Interface Repository

Ahmad Hariri ahmadh82 at gmail.com
Thu Dec 5 16:34:32 CET 2013


Hi, I'm fairly new to Jacorb and CORBA in general, I'm working on an Echo
C/S to get familiar with the various ways i can make the client and server
comunicate. Now I'm stuck on how to use the Interface Repository, here's
what I did:
- Recompiled the IDL interface with -ir option
- modified the client so as to access the IR ( here is where i'm having
trouble)
Essentially the client gets the interface but when i create a Request and
use the invoke() method it does not send anything to the server and of
course I don't get the result. I believe i'm missing something really basic
here and if you could please point me to the right direction I'll be very
grateful.

Below is my client code.

Best regards,

Ahmad.

// Initializing the orb
        org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init((String[]) null,
null);

        // Obtaining a reference to the naming service
        org.omg.CORBA.Object tmp_ref =
orb.resolve_initial_references("NameService");

        NamingContextExt default_context =
NamingContextExtHelper.narrow(tmp_ref);

        // Connecting to the echo server
        NameComponent [] server_name = new NameComponent[2];
        server_name[0] = new NameComponent("pippo","");
        server_name[1] = new NameComponent("EchoServer","");

        org.omg.CORBA.Object echo_server =
default_context.resolve(server_name);

        org.omg.CORBA.Object tmp_interfaccia =
echo_server._get_interface_def();
        InterfaceDef interfaccia =
InterfaceDefHelper.narrow(tmp_interfaccia);
        System.out.println(interfaccia.id());
        IdlWriter idlw = new IdlWriter(orb,System.out, null);
        idlw.printInterface(interfaccia, 2);
        //messaggio stub_echo = messaggioHelper.narrow(echo_server);

        boolean repeat = true;

        // While loop that takes the message to send to the server
        while ( repeat ){
            System.out.println("Print the message to send!");
            Scanner s = new Scanner (System.in);
            String msg = s.nextLine();
            String result;

            Request request = interfaccia._request("echo");
            Any arg = request.add_in_arg();
            arg.insert_string(msg);

            request.invoke();
            Any res = request.result().value();
            result = res.extract_string();
            //String result = interfaccia.echo(msg);

            System.out.println("Here's the result: " + result);
            System.out.println("\nDo you wish to send another message? [Y]
or [N]");

            if( s.nextLine().equalsIgnoreCase("Y") ) repeat = true;
            else {
                repeat = false;
                s.close();
            }
        }


More information about the jacorb-developer mailing list