A JSON-RPC Client for Java. It uses the HttpClient of JDK11, so requests can be sent either blocking (synchronous) or not blocking (asynchronous)
<dependency>
<groupId>com.emiperez.repeson</groupId>
<artifactId>repeson</artifactId>
<version>0.5.0</version>
</dependency>
- Currently only HTTP/HTTPS Transport has been developed.
- Create a new HttpClient and Configure it with any HTTP related properties (Authentication, Proxy, Cookie Handler, SSL and so on)
- Build a new
HttpTransport
and inject theHttpClient
to it
Transport transport = HttpTransport.builder(httpClient).uri(uri).contentType(contentType).build();
JsonRpcClient jsonRpcClient = JsonRpcClient.builder()
.transport(transport)
.version(JsonRpcVersion.v2_0)
.idGenerator(idGenerator)
.build();
Synchronous or blocking:
JsonRpcResponse<Customer> r = jsonRpcClient.sendRequestWithDefaults("getcustomer", paramsPojo);
r.ifHasResultOrElse(customer -> System.out.println(customer.getName(),
() -> System.out.println("No customer returned"));
or Asynchronous (not blocking)
CompletableFuture<Customer> cc = jsonRpcClient
.sendRequestWithDefaultsAsync("getcustomer", paramsPojo)
.thenApply(JsonRpcResponse::getResult);
If the returned Type uses Generics, for example; ArrayList<Customer>
, to prevent the Type Erasure, a class file, that extends JsonRpcResponse must be created,
public class CustomerListResponse extends JsonRpcResponse<ArrayList<Customer>> {}
and passed as an argument to send methods:
CustomerListResponse r = jsonRpcClient.sendRequestWithDefaults("listcustomers", paramsPojo,
CustomerListResponse.class);
if (r.hasResult()) {
ArrayList<Customer> cs = r.getResult();
//Do whatever with cs
}