Loading ...
Sorry, an error occurred while loading the content.

Re: [json] JSON RPC

Expand Messages
  • Michal Migurski
    ... I don t think this can be resolved in the spec - it would require a way to reference object in JSON, and some concept of object equivalence between the
    Message 1 of 3 , Mar 12, 2006
    • 0 Attachment
      > One oversight in the spec is that there appears to be no way of
      > specifying invoking a object method.
      >
      > I've worked around it by adding a "object" parameter to the RPC call,
      > where object is a object ref that can be resolved by the server or the
      > client (depending on the direction of the call).
      >
      > Is this something that should be added to the spec ? or resolved in
      > another way ?

      I don't think this can be resolved in the spec - it would require a
      way to reference object in JSON, and some concept of object
      equivalence between the client & server. A lot of apps don't have
      this, so baking it into the spec may be overkill. Can you post your
      workaround here? Maybe I'm misunderstanding what you mean.

      ----------------------------------------------------------------
      michal migurski- contact info and pgp key:
      sf/ca http://mike.teczno.com/contact.html
    • Lindsay
      ... I was just adding a extra attribute (object) to the RPC object, e.g. { object : S12 , method : echo , params : [ Hello JSON-RPC ], id : 1} The object
      Message 2 of 3 , Mar 12, 2006
      • 0 Attachment
        Michal Migurski wrote:
        > I don't think this can be resolved in the spec - it would require a
        > way to reference object in JSON, and some concept of object
        > equivalence between the client & server. A lot of apps don't have
        > this, so baking it into the spec may be overkill. Can you post your
        > workaround here? Maybe I'm misunderstanding what you mean.
        >

        I was just adding a extra attribute (object) to the RPC object, e.g.

        { "object": "S12",
        "method": "echo", "params": ["Hello JSON-RPC"], "id": 1}

        The object value ("S12") is a ref to a object on the server which my PHP
        script would resolve to the real object, something like this:


        //////////////////////////////////////////////////////////////
        // object or procedure ?
        if (isset($rpc->object))
        {
        // object call
        $obj_ses_id = "obj_" . $rpc->object;

        $obj = null;
        if (array_key_exists($obj_ses_id, $_SESSION))
        {
        $obj = unserialize($_SESSION[$obj_ses_id]);
        if (method_exists($obj, $rpc->method))
        {
        call_user_func_array(array(&$obj, $rpc->method), $args);
        $_SESSION[$obj_ses_id] = serialize($obj);
        }
        else
        BW_AddLog("object " . $rpc->method . " does not exist");
        }
        else
        BW_AddLog("Event for non existant object !");
        }
        else
        {
        // function call
        if (function_exists($rpc->method))
        call_user_func_array($rpc->method, $args);
        else
        BW_AddLog($rpc->method . " does not exist");
        }



        ///////////////////////////////////////////////////////////////////////////////////
        Obviously the object ref only has meaning to my code.

        I don't think the JSONRPC spec needs to specify how a object ref works -
        that's a implementation detail, its sufficient to say the object
        attribute contains a reference to a object. After al the spec doesn't
        say how a method is resolved to a real function on the server - that's
        up to the implementation.

        --
        Lindsay



        [Non-text portions of this message have been removed]
      Your message has been successfully submitted and would be delivered to recipients shortly.