Package rs.jerseyclient.util
Class AbstractClient
java.lang.Object
rs.jerseyclient.util.AbstractClient
- Direct Known Subclasses:
JerseyClient
The abstract implementation of all REST clients.
The class can already handle paging (with page and pageSize query parameters)
as well as sorting (with sort parameter}.
- Author:
- ralph
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor.protectedAbstractClient(javax.ws.rs.client.WebTarget target) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected javax.ws.rs.client.WebTargetapplyPaging(javax.ws.rs.client.WebTarget target, Integer page, Integer pageSize) Applies paging parameters to the target.protected javax.ws.rs.client.WebTargetApplies sort parameter to the target.protected voidcheckResponse(javax.ws.rs.core.Response response) Helper method to raise exceptions in case of any other response than 2xx successful.protected <T> TcheckResponse(javax.ws.rs.core.Response response, T successValue) Helper method to raise exceptions in case of any other response than 2xx successful.protected <T extends AbstractClient>
TReturns the subclient of the given type.org.slf4j.LoggergetLog()Returns the logger for this client.javax.ws.rs.client.Invocation.BuilderReturns a request builder.protected <T> ResultList<T>getResults(HateOasPagedList<T> pagedList) Retrieves the results from the REST response object.protected javax.ws.rs.client.WebTargetReturns the target.protected javax.ws.rs.client.WebTargetReturns the target with paging parameters applied.protected javax.ws.rs.client.WebTargetReturns the target with sort parameter applied.protected javax.ws.rs.client.WebTargetReturns the target with paging and sort parameters applied.protected voidsetTarget(javax.ws.rs.client.WebTarget target) Sets a target for this client.
-
Constructor Details
-
AbstractClient
protected AbstractClient()Constructor.Descendants must call
setTarget(WebTarget)to initialize class correctly. -
AbstractClient
protected AbstractClient(javax.ws.rs.client.WebTarget target) Constructor.- Parameters:
target- - the target to request.
-
-
Method Details
-
setTarget
protected void setTarget(javax.ws.rs.client.WebTarget target) Sets a target for this client.- Parameters:
target- the target
-
getRequest
public javax.ws.rs.client.Invocation.Builder getRequest()Returns a request builder.- Returns:
- the builder
-
getTarget
protected javax.ws.rs.client.WebTarget getTarget()Returns the target.- Returns:
- the target
-
getTarget
Returns the target with paging parameters applied.- Parameters:
page- - page index (0-based)pageSize- - page size- Returns:
- the target
-
getTarget
Returns the target with sort parameter applied.- Parameters:
sort- - the sort parameter- Returns:
- the target
-
getTarget
Returns the target with paging and sort parameters applied.- Parameters:
sort- - the sort parameterpage- - page index (0-based)pageSize- - page size- Returns:
- the target
-
applyPaging
protected javax.ws.rs.client.WebTarget applyPaging(javax.ws.rs.client.WebTarget target, Integer page, Integer pageSize) Applies paging parameters to the target.- Parameters:
target- - the base targetpage- - page index (0-based)pageSize- - page size- Returns:
- the new target
-
applySort
Applies sort parameter to the target.- Parameters:
target- - the base targetsort- - the sort parameter- Returns:
- the new target
-
get
Returns the subclient of the given type.Be aware that subclient use relative REST API paths.
- Type Parameters:
T- - Class of subclient- Parameters:
clazz- - class of subclient- Returns:
- new or existing instance of subclient
-
getResults
Retrieves the results from the REST response object.- Type Parameters:
T- - class of result type- Parameters:
pagedList- - the response object- Returns:
- the list of objects (or empty list)
-
checkResponse
protected void checkResponse(javax.ws.rs.core.Response response) Helper method to raise exceptions in case of any other response than 2xx successful.- Parameters:
response- theResponseobject
-
checkResponse
protected <T> T checkResponse(javax.ws.rs.core.Response response, T successValue) Helper method to raise exceptions in case of any other response than 2xx successful.- Type Parameters:
T- - the type of successful return- Parameters:
response- theResponseobjectsuccessValue- the value to return when response was successfull- Returns:
- usually the successValue - everything else will raise a runtime exception
-
getLog
public org.slf4j.Logger getLog()Returns the logger for this client.- Returns:
- the logger
-