Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON-RPC client in Java [closed]

Tags:

java

json-rpc

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.

like image 905
Not Available Avatar asked Feb 16 '11 10:02

Not Available


People also ask

What is JSON-RPC client?

JSON-RPC is a simple remote procedure call protocol encoded in JSON (Extensible Markup Language), over the HTTP 1.1 protocol. The Ethereum JSON-RPC API is implemented as a set of Web3 object methods that allow clients to interact with the Ethereum blockchain.

How does JSON-RPC work?

JSON-RPC works by sending a request to a server implementing this protocol. The client in that case is typically software intending to call a single method of a remote system.

What is JSON-RPC endpoint?

JSON-RPC is a stateless, light-weight remote procedure call (RPC) protocol. It defines several data structures and the rules around their processing. It is transport agnostic in that the concepts can be used within the same process, over sockets, over HTTP, or in many various message passing environments.

Is JSON-RPC HTTP?

A JSON-RPC request can be sent by an HTTP POST request to a URL that is served by the Java-based OpenROADJSONRPC servlet. The data of the HTTP POST request must be a JSON-RPC 2.0-conforming request string.


1 Answers

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();
like image 127
Luciano Fiandesio Avatar answered Oct 14 '22 15:10

Luciano Fiandesio