jnan77 / jsonrpc4j

Automatically exported from code.google.com/p/jsonrpc4j
0 stars 0 forks source link

Add ability to send single object param, instead of it always being an array. #17

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Find a service that require a single object param, ex. Zabbix API host.get
2. Try to make a json-rpc call to the function

What is expected? 
Call should succeed.

What do you see instead?
Call fails because param expected by the function is an object not an array of 
objects.

What version of the product are you using? 
0.19

On what operating system?
Linux/Ubuntu

Fore more information, refer to the group discussion here:
http://groups.google.com/group/jsonrpc4j/browse_thread/thread/3b05d39638389442

Original issue reported on code.google.com by subp...@gmail.com on 23 Feb 2012 at 8:41

GoogleCodeExporter commented 8 years ago
I'll need to add an invoke method to the rpc clients.

Original comment by brian.di...@gmail.com on 24 Feb 2012 at 6:01

GoogleCodeExporter commented 8 years ago
When do you think this will be implemented? It's a blocker for me at the moment 
and I might look for alternative libraries if the resolution time will be too 
long..

Original comment by francesc...@gmail.com on 4 May 2012 at 10:07

GoogleCodeExporter commented 8 years ago
This is complete, please try the latest SNAPSHOT version and report back.  I'll 
cut a release after you've tested it.

Original comment by brian.di...@gmail.com on 21 May 2012 at 9:18

GoogleCodeExporter commented 8 years ago
Will test tomorrow first thing. Thank you.

Original comment by francesc...@gmail.com on 21 May 2012 at 10:07

GoogleCodeExporter commented 8 years ago
After testing I have discovered that this is not what I was looking for.

I have put in a quick and dirty hack to make it work the way I have intended. 
Only one line is changed. Of course this breaks the library but it explains my 
point.

I'll post as a comment:
public void writeRequest(
        String methodName, Object[] arguments, OutputStream ops, String id)
        throws IOException {

        // create the request
        ObjectNode request = mapper.createObjectNode();
        request.put("id", id);
        request.put("jsonrpc", JSON_RPC_VERSION);
        request.put("method", methodName);
                //Hacking in here
        //request.put("params", mapper.valueToTree(arguments));
        request.put("params", mapper.valueToTree(arguments[0]));

        // show to listener
        if (this.requestListener!=null) {
            this.requestListener.onBeforeRequestSent(this, request);
        }
        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.log(Level.FINE, "JSON-PRC Request: "+request.toString());
        }

        // post the json data;
        writeAndFlushValue(ops, request);
    }

Original comment by francesc...@sumup.com on 22 May 2012 at 1:11

GoogleCodeExporter commented 8 years ago
What you've described is possible with what is in the latest snapshot.

you would do the following:

Object[] myArrayOfArguments = ...;

Map<String, Object> args = new HashMap<String, Object>();
args.put("params", myArrayOfArguments[0]);

client.writeRequest("method", args, ops, id);

Original comment by brian.di...@gmail.com on 25 May 2012 at 2:50

GoogleCodeExporter commented 8 years ago

Original comment by brian.di...@gmail.com on 25 May 2012 at 2:51

GoogleCodeExporter commented 8 years ago
Oh wait, i think i see what you're doing there.  I'll make a change right now 
for ya.

Original comment by brian.di...@gmail.com on 25 May 2012 at 2:53

GoogleCodeExporter commented 8 years ago
ok, take a look now.  you'll notice that there is only one writeRequest now.  
It accepts an Object for the argument.

Original comment by brian.di...@gmail.com on 25 May 2012 at 3:45

GoogleCodeExporter commented 8 years ago
Thanks for the fix! Problem is: it does not work with proxies. I guess (by 
looking at proxy code) that it always uses the invoke with a Object[] param.

Can this enhancement be ported in the Proxy code as well?

Thanks!

Original comment by francesc...@sumup.com on 4 Jun 2012 at 9:03

GoogleCodeExporter commented 8 years ago
This is what I get from the logging while using the proxy:
Jun 4, 2012 10:57:00 AM com.googlecode.jsonrpc4j.JsonRpcClient 
internalWriteRequest
FINE: JSON-PRC Request: 
{"id":"-7242475462679936753","jsonrpc":"2.0","method":"login","params":[{"userna
me":.....}]}

Original comment by francesc...@sumup.com on 4 Jun 2012 at 9:12

GoogleCodeExporter commented 8 years ago
Yeah, I could make that happen.  I'll ping this issue back after I've done it.

Original comment by br...@shopnation.com on 4 Jun 2012 at 6:49