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.
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.
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.
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.
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.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With