14

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.

Not Available
  • 3,095
  • 7
  • 27
  • 31
  • 2
    Not sure why this got marked as off topic; it's tagged 'java' and 'json-rpc' and it's a legitimate question. – raner Feb 02 '18 at 21:24

2 Answers2

4

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();
Luciano Fiandesio
  • 10,037
  • 10
  • 48
  • 56
  • 4
    I don't see how this was accepted as an answer, since it refers to Spring RestTemplate. JSON-RPC is, as the name suggests, an RPC protocol, and REST is the very opposite of RPC (the Richardson Maturity Model refers to RPC as Level 0, aka "Swamp of POX"). It's a mystery to me how RestTemplate could be used to create JSON-RPC calls, which might not even run via HTTP but via websockets or plain TCP sockets... – raner Feb 02 '18 at 21:29
1

Check this out: https://code.google.com/p/json-rpc-client/

The above is a JSON RPC client in Java that can talk to a JSON RPC Service.