repeson

A RPC-JSON Client for Java

License

License

GroupId

GroupId

com.emiperez.repeson
ArtifactId

ArtifactId

repeson
Last Version

Last Version

0.5.0
Release Date

Release Date

Type

Type

jar
Description

Description

repeson
A RPC-JSON Client for Java
Project URL

Project URL

https://github.com/emiperez/repeson
Source Code Management

Source Code Management

https://github.com/emiperez/repeson

Download repeson

How to add to project

<!-- https://jarcasting.com/artifacts/com.emiperez.repeson/repeson/ -->
<dependency>
    <groupId>com.emiperez.repeson</groupId>
    <artifactId>repeson</artifactId>
    <version>0.5.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.emiperez.repeson/repeson/
implementation 'com.emiperez.repeson:repeson:0.5.0'
// https://jarcasting.com/artifacts/com.emiperez.repeson/repeson/
implementation ("com.emiperez.repeson:repeson:0.5.0")
'com.emiperez.repeson:repeson:jar:0.5.0'
<dependency org="com.emiperez.repeson" name="repeson" rev="0.5.0">
  <artifact name="repeson" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.emiperez.repeson', module='repeson', version='0.5.0')
)
libraryDependencies += "com.emiperez.repeson" % "repeson" % "0.5.0"
[com.emiperez.repeson/repeson "0.5.0"]

Dependencies

compile (2)

Group / Artifact Type Version
com.emiperez.commons : idgenerators jar 0.2.0
com.fasterxml.jackson.core : jackson-databind jar 2.12.0

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.18.16

test (1)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter jar 5.7.0

Project Modules

There are no modules declared in this project.

repeson

A JSON-RPC Client for Java. It uses the HttpClient of JDK11, so requests can be sent either blocking (synchronous) or not blocking (asynchronous)

How to use it

1. Adding the dependency to your project

<dependency>
  <groupId>com.emiperez.repeson</groupId>
  <artifactId>repeson</artifactId>
  <version>0.5.0</version>
</dependency>

2. Configuring the Transport

  1. Currently only HTTP/HTTPS Transport has been developed.
  2. Create a new HttpClient and Configure it with any HTTP related properties (Authentication, Proxy, Cookie Handler, SSL and so on)
  3. Build a new HttpTransport and inject the HttpClient to it
Transport transport = HttpTransport.builder(httpClient).uri(uri).contentType(contentType).build();

3. Building the JsonRpcClient

JsonRpcClient jsonRpcClient = JsonRpcClient.builder()
					.transport(transport)
					.version(JsonRpcVersion.v2_0)
					.idGenerator(idGenerator)
					.build();

4.- Sending the Request and getting the Response

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
}

Versions

Version
0.5.0
0.4.2
0.4.1
0.4.0
0.3.0
0.2.0
0.1.0