JSON-RPC client in Java

Not Available picture Not Available · Feb 16, 2011 · Viewed 17.6k times · Source

I'm trying to find a way to write a java application that can communicate with a json-rpc service (The service is a python twisted server).

However I haven't been able to find a decent library with some good examples (I've googled and fiddled around for like 6 hours now).

So are there any libraries for this in Java, or is there a more-cumbersome lower level way.

Answer

Luciano Fiandesio picture Luciano Fiandesio · Feb 16, 2011

You can take a look at Spring and the RestTemplate class (here is a good introduction: http://blog.springsource.com/2009/03/27/rest-in-spring-3-resttemplate/).

Alternatively, you can use Commons HttpClient to post/get your Json payload to the service.

PostMethod post = new PostMethod("http://myservice.com");
// add the payload to the post object
HttpClient client = new HttpClient();
int status = client.executeMethod(post);
String response = post.getResponseBodyAsString();