{8.2.0-new} Custom Call Handlers

The {@link oajr.client2.RestCallHandler} interface provides the ability to provide custom handling of requests.

Example:

// Our custom call handler. public class MyRestCallHandler implements RestCallHandler { private final RestClient client; public MyRestCallHandler(RestClient client) { this.client = client; } @Override public HttpResponse run(HttpHost target, HttpRequest request, HttpContext context) throws IOException { // Insert any special handling here. // The following is the default behavior: if (target == null) return client.execute((HttpUriRequest)request, context); return client.execute(target, request, context); } } // Create a client that uses our custom handler. RestClient client = RestClient() .create() .json() .callHandler(MyCallHandler.class) .build();

Note that there are other ways of accomplishing this such as extending the {@link oajr.client2.RestClient} class and overriding the {@link oaj.rest.client2.RestClient#run(HttpHost,HttpRequest,HttpContext)} method or by defining your own {@link org.apache.http.protocol.HttpRequestExecutor}. Using this interface is often simpler though.