Login Register

RPC

I can hardly say that I have a problem since everything is running OK but still in FireBug I am getting odd results.

I've followed given example with few changes in PHP file. Instead of using call_user_func_array() I've used ReflectionMethod. isDebug set to true and after calling add(131,5) result was 136. So far so good. Then I've turned off dojo debugger and turned on FireBug. The result I got was weird: ReflectionException: Method rpcClass::() does not exist in rpcProcessor.php on line 27 and than just bellow it expected result: result is: 136. Of course my first thought was that I've made some mistake and I've uncommented line $jsonRequest = '{"params":[5,6],"method":"add","id":86}';, commented out header("Content-Type: text/json"); and run script in browser. On my surprise everything was OK. There is no mistake. I've tried every idea that came on my mind but without any success. It looks as if two requests are sent the first one {"params":,"method":"","id":} and than second one {"params":[131,5],"method":"add","id":1}.

Could it be actually a FireBug bug?

P.S. I am getting same results if running script on remote server which is running entirely different configuration (centOS 5, PHP 5.3) so it's highly unlikely that it is configuration problem

That is odd. Can I see the

That is odd. Can I see the tests file on the client and server side?

JSON-RPC

It does not look as dojo problem. Here is part of php code where I've dumped headers data:

if (function_exists('apache_request_headers')) :
$headers = apache_request_headers();
var_dump($headers);
throw new Exception('dumping headers', 33);
if (!empty($headers[$header])) :
return $headers[$header];
endif;
endif;

Result with Firebug enabled:

array
'Host' string'www.walras-developing.org' (length=25)
'User-Agent' => string 
'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9b5) Gecko/2008050509 Firefox/3.0b5' (length=82)
'Accept' string 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' (length=63)
'Accept-Language' string 'en-us,en;q=0.5' (length=14)
'Accept-Encoding' string 'gzip,deflate' (length=12)
'Accept-Charset' string 'ISO-8859-1,utf-8;q=0.7,*;q=0.7' (length=30)
'Keep-Alive' string '300' (length=3)
'Connection' string 'keep-alive' (length=10)
'Cookie' string '98defd6ee70dfb1dea416cecdf391f58=eda6a89d720297e8542472a97abeec80' (length=65)

{"result":null,"error":{"code":-32600,"message":"Invailid request.","data":{"message":"dumping
headers","code":33,"line":526}},"id":null}

Headers shown in Firebug console:

Host	www.walras-developing.org
User-Agent	Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9b5) Gecko/2008050509 Firefox/3.0b5
Accept	application/json-rpc
Accept-Language	 en-us,en;q=0.5
Accept-Encoding  gzip,deflate
Accept-Charset	ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive	300
Connection	keep-alive
Content-Type	application/json-rpc; charset=UTF-8
X-Requested-With	XMLHttpRequest
Referer  https://www.walras-developing.org/index.php/registration/get/employers
Content-Length	94
Cookie	98defd6ee70dfb1dea416cecdf391f58=eda6a89d720297e8542472a97abeec80

Result with Firebug turned off and isDebug set to true:

array
'Host' => string 'www.walras-developing.org' (length=25)
'User-Agent' => string 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9b5) Gecko/2008050509 Firefox/3.0b5' (length=82)
'Accept' => string 'application/json-rpc' (length=20)
'Accept-Language' => string 'en-us,en;q=0.5' (length=14)
'Accept-Encoding' => string 'gzip,deflate' (length=12)
'Accept-Charset' => string 'ISO-8859-1,utf-8;q=0.7,*;q=0.7' (length=30)
'Keep-Alive' => string '300' (length=3)
'Connection' => string 'keep-alive' (length=10)
'Content-Type' => string 'application/json-rpc; charset=UTF-8' (length=35)
'X-Requested-With' => string 'XMLHttpRequest' (length=14)
'Referer' => string 'https://www.walras-developing.org/index.php/registration/get/employers' (length=70)
'Content-Length' => string '94' (length=2)
'Cookie' => string '98defd6ee70dfb1dea416cecdf391f58=28e481d60b9d6a3496e8276d9b7a5a31' (length=65)
'Pragma' => string 'no-cache' (length=8)
'Cache-Control' => string 'no-cache' (length=8)
{"result":null,"error":{"code":-32600,"message":"Invailid request.","data":{"message":"dumping 
headers","code":33,"line":526}},"id":null}

When Firebug is enabled following method throws exception:

public function parseRpcRequest()
{
        if ('POST' !== $this->string('server', 'REQUEST_METHOD')) :
        throw new Exception('RPC Server: No post data', 3001);
        endif;
        /*
         * Konqueror hack
         */

        if (false !== strpos($this->getHeader('User_Agent'), 'Konqueror')) :
        $this->contentType = 'Content-type' ;
        endif;
               
        if (false === strpos($this->getHeader($this->contentType), 'json')) :
        throw new Exception('RPC Server: Invalid content type' , 3002);
        endif;
               
        if (false === strpos($this->getHeader('Accept'), 'json')) :
        throw new Exception('RPC Server: Cannot send accepted data type', 3003);
        endif;
        $this->fetchJsonStr();
        $this->createRpcInput();
}

Of course when Firebug is disabled I got correct result:

id : 1
  result -> [array with 4 slots]
    0 -> {object with 9 items}
      pid -> [array with 1 slots]
        0 : 948
      name -> [array with 1 slots]
        0 : Univerity of Belgrade (BU)
      unit -> [array with 1 slots]
        0 : {}
      department -> [array with 1 slots]
        0 : {}
      weight -> [array with 1 slots]
        0 : 1
      selected -> [array with 1 slots]
        0 : false
    1 -> {object with 9 items}
      pid -> [array with 1 slots]
        0 : 948.931
      name -> [array with 1 slots]
        0 : Univerity of Belgrade (BU)
      unit -> [array with 1 slots]
        0 : Faculty of Economics
      department -> [array with 1 slots]
        0 : {}
      weight -> [array with 1 slots]
        0 : 1
      selected -> [array with 1 slots]
        0 : false
    2 -> {object with 9 items}
      pid -> [array with 1 slots]
        0 : 1006
      name -> [array with 1 slots]
        0 : University of Belgrade (BU)
      unit -> [array with 1 slots]
        0 : {}
      department -> [array with 1 slots]
        0 : {}
      weight -> [array with 1 slots]
        0 : 1
      selected -> [array with 1 slots]
        0 : false
    3 -> {object with 9 items}
      pid -> [array with 1 slots]
        0 : 1006.1002
      name -> [array with 1 slots]
        0 : University of Belgrade (BU)
      unit -> [array with 1 slots]
        0 : Institute of Economic Sciences
      department -> [array with 1 slots]
        0 : {}
      weight -> [array with 1 slots]
        0 : 1
      selected -> [array with 1 slots]
        0 : false

Finally here is the key part of JavaScript:

if(!dojo._hasResource["walras.Core.Rpc"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["walras.Core.Rpc"] = true;
dojo.provide("walras.Core.Rpc");

dojo.declare("walras.Core.Rpc", null, {
       
        service : null,
       
        deferred : null,
       
        fname : '',
       
        constructor : function() {
                dojo.require("dojo.rpc.JsonService");
                this.service = new dojo.rpc.JsonService("/definition.smd");
        },
   
        handleSuccess : function (response) {
                        dojo.publish(this.fname + 'Callback', [response]);
        },
       
        handleError : function(response) {
                        dojo.publish(this.fname + 'Errorback', [response]);
        },
       
        makeCall : function(fname, args) {
                this.fname = fname;
                console.debug(args);
                try {
//                  var something = "this.service[this.fname](";
//                  for( i=1; i < arguments.length; ++i) {
//                        something=something+"arguments[" + i + "]";
//                        if (i < (arguments.length - 1)) something += ", ";
//                  }
//                  something = something + ")";
                        if(dojo.isArray(args)) {
                                this.deferred = this.service[this.fname](args[0], args[1]);
                        } else {
                                this.deferred = this.service[this.fname](args);
                        }
//                  this.defered = eval(something);
                        this.deferred.addCallback(this, 'handleSuccess');
                        this.deferred.addErrback(this, 'handleError');
                } catch(err) {
                                this.handleError(err);
                }

        }

});
}

I guess that there is no need to setup any example. Anyway if you need additional information I would be glad to help.