Archived

This forum has been archived. Please start a new discussion on GitHub.

Ice for JavaScript : to get interface from other interface

Hi, I'm new in Ice for JavaScript and I have a question. I have the following file .ice :
#pragma once
module Demo {
	struct Info{
		string str = "String in struct Info";
	};

	interface Master{
		string getMasterString();
	};

	interface Printer{
		void printString(string s);
		string getTest();
		Info getInfo();
		Master* getMaster();
	};
};

I'm attempting to use the "getMasterString" function which belongs to the "Master" interface from other interface ("Printer").

I can retrieve the "Master" but I can't retrieve the string returned by the function "getMasterString".

In the Client.js (after creating the session), I do :
function runWithSession(router, session)
{ 
    var proxy = communicator.stringToProxy("printer -t:tcp -h localhost -p 10000");
    var printer = Demo.PrinterPrx.uncheckedCast(proxy)

    Ice.Promise.all(
	printer.getMaster().then(
	    function(result){
		masterPrx = Demo.MasterPrx.uncheckedCast(result);   
		//console.log(masterPrx.getMasterString().toString());

		masterPrx.getMasterString().then(
		    function(str){
			console.log(str);
		    },
		    function(ex){
			console.log("fail : "+ex);
		    }
		)
		//return result;
	    }
	)/*.then(
	    function(master){
		return master.getMasterString().then(
		    function(str){
			console.log("str : "+str);
		    },
		    function(ex){
			console.log(ex);
		    }
		)       
	    }
	)*/
    );
}

And the result of running the client is :
This Client accepts any user-id / password combination.
user id : user
password : pass
fail : Ice::CommunicatorDestroyedException
    ice_cause: "undefined"

I've attached the files (client, server, config server, config glacier, and .ice).

Comments

  • xdm
    xdm La Coruña, Spain
    in runWithSession you must return the promise returned by Ice.Promise.all, otherwise finally will be executed as runWithSession queue the promises with Ice.Promise.all and finally method will be invoked and destroy the communicator.

    You need something like:
    function runWithSession(router, session)
    { 
        var proxy = communicator.stringToProxy("printer -t:tcp -h localhost -p 10000");
        var printer = Demo.PrinterPrx.uncheckedCast(proxy)
    
        return Ice.Promise.all(
    ....
    
  • Thanks, it works. :)
  • mes
    mes California
    One other minor comment. There's no need for this line:
    masterPrx = Demo.MasterPrx.uncheckedCast(result);
    

    The call to getMaster returns a MasterPrx value.

    Mark