public class RestClient extends Object implements AutoCloseable
A REST client that can make synchronous and asynchronous calls.
For asynchronous call, please refer to https://dennis-xlc.gitbooks.io/restful-java-with-jax-rs-2-0-2rd-edition/en/part1/chapter13/async_invoker_client_api.html
to understand why we’d better not mix to using callback or Java Future.
Constructor and Description |
---|
RestClient(@NonNull javax.ws.rs.client.Client client,
@NonNull EntityFactory entityFactory,
JaxRsCircuitBreaker circuitBreaker)
Create a new client that uses a provided client to make all its requests.
|
RestClient(@NonNull javax.ws.rs.client.Client client,
@NonNull EntityFactory entityFactory,
JaxRsCircuitBreaker circuitBreaker,
boolean isApacheNonBufferingClient)
Create a new client that uses a provided client to make all its requests.
|
RestClient(@NonNull javax.ws.rs.client.Client client,
@NonNull EntityFactory entityFactory,
JaxRsCircuitBreaker circuitBreaker,
boolean isApacheNonBufferingClient,
ClientConfigurator clientConfigurator)
Create a new client that uses a provided client to make all its requests.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
<T extends BmcRequest> |
delete(@NonNull WrappedInvocationBuilder ib,
T request)
Execute a delete on a resource and get the response.
|
<T extends BmcRequest> |
delete(@NonNull WrappedInvocationBuilder ib,
T request,
Consumer<javax.ws.rs.core.Response> onSuccess,
Consumer<Throwable> onError)
Execute a delete on a resource asynchronously and get the response.
|
<B,REQUEST extends BmcRequest<B>,RESPONSE> |
deleteFutureSupplier(REQUEST interceptedRequest,
WrappedInvocationBuilder ib,
com.google.common.base.Function<javax.ws.rs.core.Response,RESPONSE> transformer)
Return the function that, given an
AsyncHandler , makes the delete request and returns the future. |
<T extends BmcRequest> |
get(@NonNull WrappedInvocationBuilder ib,
T request)
Request a resource.
|
<T extends BmcRequest> |
get(@NonNull WrappedInvocationBuilder ib,
T request,
Consumer<javax.ws.rs.core.Response> onSuccess,
Consumer<Throwable> onError)
Request a resource asynchronously.
|
WrappedWebTarget |
getBaseTarget()
Gets the target (endpoint) for this client.
|
JaxRsCircuitBreaker |
getCircuitBreaker()
Gets the underlying circuitBreaker implementation for this client
|
ClientConfigurator |
getClientConfigurator()
The client configurator used for configuring the client.
|
<B,REQUEST extends BmcRequest<B>,RESPONSE> |
getFutureSupplier(REQUEST interceptedRequest,
WrappedInvocationBuilder ib,
com.google.common.base.Function<javax.ws.rs.core.Response,RESPONSE> transformer)
Return the function that, given an
AsyncHandler , makes the get request and returns the future. |
<T extends BmcRequest> |
head(@NonNull WrappedInvocationBuilder ib,
T request)
Execute a head request for a resource and return the response.
|
<T extends BmcRequest> |
head(@NonNull WrappedInvocationBuilder ib,
T request,
Consumer<javax.ws.rs.core.Response> onSuccess,
Consumer<Throwable> onError)
Execute a head request for a resource asynchronously and return the
response.
|
<B,REQUEST extends BmcRequest<B>,RESPONSE> |
headFutureSupplier(REQUEST interceptedRequest,
WrappedInvocationBuilder ib,
com.google.common.base.Function<javax.ws.rs.core.Response,RESPONSE> transformer)
Return the function that, given an
AsyncHandler , makes the head request and returns the future. |
<T extends BmcRequest> |
patch(@NonNull WrappedInvocationBuilder ib,
Object body,
T request)
Patch a request object to the endpoint represented by the web target and
get the response.
|
<T extends BmcRequest> |
patch(@NonNull WrappedInvocationBuilder ib,
Object body,
T request,
Consumer<javax.ws.rs.core.Response> onSuccess,
Consumer<Throwable> onError)
Patch a request object to the endpoint represented by the web target
asynchronously and get the response.
|
<T extends BmcRequest> |
patch(@NonNull WrappedInvocationBuilder ib,
T request)
Patch a request object without body to the endpoint represented by the web target and
get the response.
|
<T extends BmcRequest> |
patch(@NonNull WrappedInvocationBuilder ib,
T request,
Consumer<javax.ws.rs.core.Response> onSuccess,
Consumer<Throwable> onError)
Patch a request object without body to the endpoint represented by the web target
asynchronously and get the response.
|
<B,REQUEST extends BmcRequest<B>,RESPONSE> |
patchFutureSupplier(REQUEST interceptedRequest,
Object body,
WrappedInvocationBuilder ib,
com.google.common.base.Function<javax.ws.rs.core.Response,RESPONSE> transformer)
Return the function that, given an
AsyncHandler , makes the patch request and returns the future |
<B,REQUEST extends BmcRequest<B>,RESPONSE> |
patchFutureSupplier(REQUEST interceptedRequest,
WrappedInvocationBuilder ib,
com.google.common.base.Function<javax.ws.rs.core.Response,RESPONSE> transformer)
Return the function that, given an
AsyncHandler , makes the patch request and returns the future |
<T extends BmcRequest> |
post(@NonNull WrappedInvocationBuilder ib,
Object body,
T request)
Post a request object to the endpoint represented by the web target and
get the response.
|
<T extends BmcRequest> |
post(@NonNull WrappedInvocationBuilder ib,
Object body,
T request,
Consumer<javax.ws.rs.core.Response> onSuccess,
Consumer<Throwable> onError)
Post a request object to the endpoint represented by the web target
asynchronously and get the response.
|
<T extends BmcRequest> |
post(@NonNull WrappedInvocationBuilder ib,
T request)
Post an empty body to the endpoint represented by the web target and get
the response.
|
<T extends BmcRequest> |
post(@NonNull WrappedInvocationBuilder ib,
T request,
Consumer<javax.ws.rs.core.Response> onSuccess,
Consumer<Throwable> onError)
Post an empty body to the endpoint represented by the web target
asynchronously and get the response.
|
<B,REQUEST extends BmcRequest<B>,RESPONSE> |
postFutureSupplier(REQUEST interceptedRequest,
Object body,
WrappedInvocationBuilder ib,
com.google.common.base.Function<javax.ws.rs.core.Response,RESPONSE> transformer)
Return the function that, given an
AsyncHandler , makes the post request and returns the future |
<B,REQUEST extends BmcRequest<B>,RESPONSE> |
postFutureSupplier(REQUEST interceptedRequest,
WrappedInvocationBuilder ib,
com.google.common.base.Function<javax.ws.rs.core.Response,RESPONSE> transformer)
Return the function that, given an
AsyncHandler , makes the post request and returns the future |
<T extends BmcRequest> |
put(@NonNull WrappedInvocationBuilder ib,
Object body,
T request)
Put a request object to the endpoint represented by the web target and
get the response.
|
<T extends BmcRequest> |
put(@NonNull WrappedInvocationBuilder ib,
Object body,
T request,
Consumer<javax.ws.rs.core.Response> onSuccess,
Consumer<Throwable> onError)
Put a request object to the endpoint represented by the web target
asynchronously and get the response.
|
<T extends BmcRequest> |
put(@NonNull WrappedInvocationBuilder ib,
T request)
Put a request object without body to the endpoint represented by the web target and
get the response.
|
<T extends BmcRequest> |
put(@NonNull WrappedInvocationBuilder ib,
T request,
Consumer<javax.ws.rs.core.Response> onSuccess,
Consumer<Throwable> onError)
Put a request object without body to the endpoint represented by the web target
asynchronously and get the response.
|
<B,REQUEST extends BmcRequest<B>,RESPONSE> |
putFutureSupplier(REQUEST interceptedRequest,
Object body,
WrappedInvocationBuilder ib,
com.google.common.base.Function<javax.ws.rs.core.Response,RESPONSE> transformer)
Return the function that, given an
AsyncHandler , makes the put request and returns the future |
<B,REQUEST extends BmcRequest<B>,RESPONSE> |
putFutureSupplier(REQUEST interceptedRequest,
WrappedInvocationBuilder ib,
com.google.common.base.Function<javax.ws.rs.core.Response,RESPONSE> transformer)
Return the function that, given an
AsyncHandler , makes the put request and returns the future |
void |
setEndpoint(@NonNull String endpoint)
Sets the endpoint that this client should talk to.
|
public RestClient(@NonNull @NonNull javax.ws.rs.client.Client client, @NonNull @NonNull EntityFactory entityFactory, JaxRsCircuitBreaker circuitBreaker)
Create a new client that uses a provided client to make all its requests. It’s up to the caller to properly configure the client.
client
- A HTTP client to make all requests with.entityFactory
- An entity factory to create entities for POST/PUT operations.circuitBreaker
- A circuit breaker instance to decorate http clientpublic RestClient(@NonNull @NonNull javax.ws.rs.client.Client client, @NonNull @NonNull EntityFactory entityFactory, JaxRsCircuitBreaker circuitBreaker, boolean isApacheNonBufferingClient)
Create a new client that uses a provided client to make all its requests. It’s up to the caller to properly configure the client.
client
- A HTTP client to make all requests with.entityFactory
- An entity factory to create entities for POST/PUT operations.circuitBreaker
- A circuit breaker instance to decorate http clientisApacheNonBufferingClient
- A boolean value to disable buffering of entities in memory for Apache clientpublic RestClient(@NonNull @NonNull javax.ws.rs.client.Client client, @NonNull @NonNull EntityFactory entityFactory, JaxRsCircuitBreaker circuitBreaker, boolean isApacheNonBufferingClient, ClientConfigurator clientConfigurator)
Create a new client that uses a provided client to make all its requests. It’s up to the caller to properly configure the client.
client
- A HTTP client to make all requests with.entityFactory
- An entity factory to create entities for POST/PUT operations.circuitBreaker
- A circuit breaker instance to decorate http clientisApacheNonBufferingClient
- A boolean value to disable buffering of entities in memory for Apache clientclientConfigurator
- The client configurator used when creating the clientpublic void setEndpoint(@NonNull @NonNull String endpoint)
Sets the endpoint that this client should talk to.
endpoint
- The endpoint.public void close()
close
in interface AutoCloseable
public WrappedWebTarget getBaseTarget()
Gets the target (endpoint) for this client.
public JaxRsCircuitBreaker getCircuitBreaker()
Gets the underlying circuitBreaker implementation for this client
public <T extends BmcRequest> javax.ws.rs.core.Response get(@NonNull @NonNull WrappedInvocationBuilder ib, @NonNull T request) throws BmcException
Request a resource.
ib
- The invocation builder to use when making the request.request
- The original client request object given to the service
client.Response
object.BmcException
- If an error was encountered while invoking the request.public <T extends BmcRequest> Future<javax.ws.rs.core.Response> get(@NonNull @NonNull WrappedInvocationBuilder ib, @NonNull T request, @Nullable Consumer<javax.ws.rs.core.Response> onSuccess, @Nullable Consumer<Throwable> onError)
Request a resource asynchronously.
ib
- The invocation builder to use when making the request.request
- The original client request object given to the service
client.onSuccess
- The callback to invoke on success.onError
- The callback to invoke on failure.public <B,REQUEST extends BmcRequest<B>,RESPONSE> Function<AsyncHandler<REQUEST,RESPONSE>,Future<RESPONSE>> getFutureSupplier(REQUEST interceptedRequest, WrappedInvocationBuilder ib, com.google.common.base.Function<javax.ws.rs.core.Response,RESPONSE> transformer)
Return the function that, given an AsyncHandler
, makes the get request and returns the future.
B
- type of the bodyREQUEST
- type of the requestRESPONSE
- type of the responseinterceptedRequest
- intercepted requestib
- invocation buildertransformer
- transformer from JAX-RS response to model responsepublic <T extends BmcRequest> javax.ws.rs.core.Response post(@NonNull @NonNull WrappedInvocationBuilder ib, @Nullable Object body, @NonNull T request) throws BmcException
Post a request object to the endpoint represented by the web target and get the response.
ib
- An invocation builder to execute requests with.body
- The content body to post to the web target.request
- The original client request object given to the service
client.Response
object.BmcException
- If an error was encountered while invoking the request.public <T extends BmcRequest> Future<javax.ws.rs.core.Response> post(@NonNull @NonNull WrappedInvocationBuilder ib, @Nullable Object body, @NonNull T request, @Nullable Consumer<javax.ws.rs.core.Response> onSuccess, @Nullable Consumer<Throwable> onError)
Post a request object to the endpoint represented by the web target asynchronously and get the response.
ib
- An invocation builder to execute requests with.body
- The content body to post to the web target.request
- The original client request object given to the service
client.onSuccess
- The callback to invoke on success.onError
- The callback to invoke on failure.public <B,REQUEST extends BmcRequest<B>,RESPONSE> Function<AsyncHandler<REQUEST,RESPONSE>,Future<RESPONSE>> postFutureSupplier(REQUEST interceptedRequest, Object body, WrappedInvocationBuilder ib, com.google.common.base.Function<javax.ws.rs.core.Response,RESPONSE> transformer)
Return the function that, given an AsyncHandler
, makes the post request and returns the future
B
- type of the bodyREQUEST
- type of the requestRESPONSE
- type of the responseinterceptedRequest
- intercepted requestbody
- the body of the requestib
- invocation buildertransformer
- transformer from JAX-RS response to model responsepublic <B,REQUEST extends BmcRequest<B>,RESPONSE> Function<AsyncHandler<REQUEST,RESPONSE>,Future<RESPONSE>> postFutureSupplier(REQUEST interceptedRequest, WrappedInvocationBuilder ib, com.google.common.base.Function<javax.ws.rs.core.Response,RESPONSE> transformer)
Return the function that, given an AsyncHandler
, makes the post request and returns the future
B
- type of the bodyREQUEST
- type of the requestRESPONSE
- type of the responseinterceptedRequest
- intercepted requestib
- invocation buildertransformer
- transformer from JAX-RS response to model responsepublic <T extends BmcRequest> javax.ws.rs.core.Response post(@NonNull @NonNull WrappedInvocationBuilder ib, @NonNull T request)
Post an empty body to the endpoint represented by the web target and get the response.
ib
- An invocation builder to execute requests with.request
- The original client request object given to the service
client.Response
object.BmcException
- If an error was encountered while invoking the request.public <T extends BmcRequest> Future<javax.ws.rs.core.Response> post(@NonNull @NonNull WrappedInvocationBuilder ib, @NonNull T request, @Nullable Consumer<javax.ws.rs.core.Response> onSuccess, @Nullable Consumer<Throwable> onError)
Post an empty body to the endpoint represented by the web target asynchronously and get the response.
ib
- An invocation builder to execute requests with.request
- The original client request object given to the service
client.onSuccess
- The callback to invoke on success.onError
- The callback to invoke on failure.public <T extends BmcRequest> javax.ws.rs.core.Response patch(@NonNull @NonNull WrappedInvocationBuilder ib, @NonNull T request)
Patch a request object without body to the endpoint represented by the web target and get the response.
ib
- An invocation builder to execute requests with.request
- The original client request object given to the service
client.Response
object.BmcException
- If an error was encountered while invoking the request.public <T extends BmcRequest> javax.ws.rs.core.Response patch(@NonNull @NonNull WrappedInvocationBuilder ib, @Nullable Object body, @NonNull T request) throws BmcException
Patch a request object to the endpoint represented by the web target and get the response.
ib
- An invocation builder to execute requests with.body
- The content body to post to the web target.request
- The original client request object given to the service
client.Response
object.BmcException
- If an error was encountered while invoking the request.public <T extends BmcRequest> Future<javax.ws.rs.core.Response> patch(@NonNull @NonNull WrappedInvocationBuilder ib, @NonNull T request, @Nullable Consumer<javax.ws.rs.core.Response> onSuccess, @Nullable Consumer<Throwable> onError)
Patch a request object without body to the endpoint represented by the web target asynchronously and get the response.
ib
- An invocation builder to execute requests with.request
- The original client request object given to the service
client.onSuccess
- The callback to invoke on success.onError
- The callback to invoke on failure.public <T extends BmcRequest> Future<javax.ws.rs.core.Response> patch(@NonNull @NonNull WrappedInvocationBuilder ib, @Nullable Object body, @NonNull T request, @Nullable Consumer<javax.ws.rs.core.Response> onSuccess, @Nullable Consumer<Throwable> onError)
Patch a request object to the endpoint represented by the web target asynchronously and get the response.
ib
- An invocation builder to execute requests with.body
- The content body object to post to the web target.request
- The original client request object given to the service
client.onSuccess
- The callback to invoke on success.onError
- The callback to invoke on failure.public <B,REQUEST extends BmcRequest<B>,RESPONSE> Function<AsyncHandler<REQUEST,RESPONSE>,Future<RESPONSE>> patchFutureSupplier(REQUEST interceptedRequest, WrappedInvocationBuilder ib, com.google.common.base.Function<javax.ws.rs.core.Response,RESPONSE> transformer)
Return the function that, given an AsyncHandler
, makes the patch request and returns the future
B
- type of the bodyREQUEST
- type of the requestRESPONSE
- type of the responseinterceptedRequest
- intercepted requestib
- invocation buildertransformer
- transformer from JAX-RS response to model responsepublic <B,REQUEST extends BmcRequest<B>,RESPONSE> Function<AsyncHandler<REQUEST,RESPONSE>,Future<RESPONSE>> patchFutureSupplier(REQUEST interceptedRequest, Object body, WrappedInvocationBuilder ib, com.google.common.base.Function<javax.ws.rs.core.Response,RESPONSE> transformer)
Return the function that, given an AsyncHandler
, makes the patch request and returns the future
B
- type of the bodyREQUEST
- type of the requestRESPONSE
- type of the responseinterceptedRequest
- intercepted requestbody
- the body of the requestib
- invocation buildertransformer
- transformer from JAX-RS response to model responsepublic <T extends BmcRequest> javax.ws.rs.core.Response put(@NonNull @NonNull WrappedInvocationBuilder ib, @NonNull T request)
Put a request object without body to the endpoint represented by the web target and get the response.
ib
- An invocation builder to execute requests with.request
- The original client request object given to the service
client.Response
object.BmcException
- If an error was encountered while invoking the request.public <T extends BmcRequest> javax.ws.rs.core.Response put(@NonNull @NonNull WrappedInvocationBuilder ib, @Nullable Object body, @NonNull T request) throws BmcException
Put a request object to the endpoint represented by the web target and get the response.
ib
- An invocation builder to execute requests with.body
- The content body to post to the web target.request
- The original client request object given to the service
client.Response
object.BmcException
- If an error was encountered while invoking the request.public <T extends BmcRequest> Future<javax.ws.rs.core.Response> put(@NonNull @NonNull WrappedInvocationBuilder ib, @NonNull T request, @Nullable Consumer<javax.ws.rs.core.Response> onSuccess, @Nullable Consumer<Throwable> onError)
Put a request object without body to the endpoint represented by the web target asynchronously and get the response.
ib
- An invocation builder to execute requests with.request
- The original client request object given to the service
client.onSuccess
- The callback to invoke on success.onError
- The callback to invoke on failure.public <T extends BmcRequest> Future<javax.ws.rs.core.Response> put(@NonNull @NonNull WrappedInvocationBuilder ib, @Nullable Object body, @NonNull T request, @Nullable Consumer<javax.ws.rs.core.Response> onSuccess, @Nullable Consumer<Throwable> onError)
Put a request object to the endpoint represented by the web target asynchronously and get the response.
ib
- An invocation builder to execute requests with.body
- The content body to post to the web target.request
- The original client request object given to the service
client.onSuccess
- The callback to invoke on success.onError
- The callback to invoke on failure.public <B,REQUEST extends BmcRequest<B>,RESPONSE> Function<AsyncHandler<REQUEST,RESPONSE>,Future<RESPONSE>> putFutureSupplier(REQUEST interceptedRequest, WrappedInvocationBuilder ib, com.google.common.base.Function<javax.ws.rs.core.Response,RESPONSE> transformer)
Return the function that, given an AsyncHandler
, makes the put request and returns the future
B
- type of the bodyREQUEST
- type of the requestRESPONSE
- type of the responseinterceptedRequest
- intercepted requestib
- invocation buildertransformer
- transformer from JAX-RS response to model responsepublic <B,REQUEST extends BmcRequest<B>,RESPONSE> Function<AsyncHandler<REQUEST,RESPONSE>,Future<RESPONSE>> putFutureSupplier(REQUEST interceptedRequest, Object body, WrappedInvocationBuilder ib, com.google.common.base.Function<javax.ws.rs.core.Response,RESPONSE> transformer)
Return the function that, given an AsyncHandler
, makes the put request and returns the future
B
- type of the bodyREQUEST
- type of the requestRESPONSE
- type of the responseinterceptedRequest
- intercepted requestbody
- the body of the requestib
- invocation buildertransformer
- transformer from JAX-RS response to model responsepublic <T extends BmcRequest> javax.ws.rs.core.Response delete(@NonNull @NonNull WrappedInvocationBuilder ib, @NonNull T request) throws BmcException
Execute a delete on a resource and get the response.
ib
- An invocation builder to execute requests with.request
- The original client request object given to the service
client.Response
object.BmcException
- If an error was encountered while invoking the request.public <T extends BmcRequest> Future<javax.ws.rs.core.Response> delete(@NonNull @NonNull WrappedInvocationBuilder ib, @NonNull T request, @Nullable Consumer<javax.ws.rs.core.Response> onSuccess, @Nullable Consumer<Throwable> onError)
Execute a delete on a resource asynchronously and get the response.
ib
- An invocation builder to execute requests with.request
- The original client request object given to the service
client.onSuccess
- The callback to invoke on success.onError
- The callback to invoke on failure.public <B,REQUEST extends BmcRequest<B>,RESPONSE> Function<AsyncHandler<REQUEST,RESPONSE>,Future<RESPONSE>> deleteFutureSupplier(REQUEST interceptedRequest, WrappedInvocationBuilder ib, com.google.common.base.Function<javax.ws.rs.core.Response,RESPONSE> transformer)
Return the function that, given an AsyncHandler
, makes the delete request and returns the future.
B
- type of the bodyREQUEST
- type of the requestRESPONSE
- type of the responseinterceptedRequest
- intercepted requestib
- invocation buildertransformer
- transformer from JAX-RS response to model responsepublic <T extends BmcRequest> javax.ws.rs.core.Response head(@NonNull @NonNull WrappedInvocationBuilder ib, @NonNull T request) throws BmcException
Execute a head request for a resource and return the response.
ib
- An invocation builder to execute requests with.request
- The original client request object given to the service
client.Response
object.BmcException
- If an error was encountered while invoking the request.public <T extends BmcRequest> Future<javax.ws.rs.core.Response> head(@NonNull @NonNull WrappedInvocationBuilder ib, @NonNull T request, @Nullable Consumer<javax.ws.rs.core.Response> onSuccess, @Nullable Consumer<Throwable> onError)
Execute a head request for a resource asynchronously and return the response.
ib
- An invocation builder to execute requests with.request
- The original client request object given to the service
client.onSuccess
- The callback to invoke on success.onError
- The callback to invoke on failure.public <B,REQUEST extends BmcRequest<B>,RESPONSE> Function<AsyncHandler<REQUEST,RESPONSE>,Future<RESPONSE>> headFutureSupplier(REQUEST interceptedRequest, WrappedInvocationBuilder ib, com.google.common.base.Function<javax.ws.rs.core.Response,RESPONSE> transformer)
Return the function that, given an AsyncHandler
, makes the head request and returns the future.
B
- type of the bodyREQUEST
- type of the requestRESPONSE
- type of the responseinterceptedRequest
- intercepted requestib
- invocation buildertransformer
- transformer from JAX-RS response to model responsepublic ClientConfigurator getClientConfigurator()
The client configurator used for configuring the client. May be null.
Copyright © 2016–2022. All rights reserved.