Package com.sodius.oslc.client.requests
Class AbstractResourceRequest<T>
- java.lang.Object
-
- com.sodius.oslc.client.requests.AbstractResourceRequest<T>
-
- Type Parameters:
T
- the type of response to extract from the request execution.
- All Implemented Interfaces:
ResourceRequest<T>
,Callable<T>
- Direct Known Subclasses:
CreateProvisionalConsumerKey
,DeleteResource
,ExecuteLinkIndexQuery
,ExecuteQuery
,GetDataGroups
,GetResource
,GetResources
,GetRootServices
,GetUserGroupMembers
,GetUserGroups
,PostResource
,PutResource
,QueryUsers
public abstract class AbstractResourceRequest<T> extends Object implements ResourceRequest<T>
Base class for REST request executions.This class doesn't set a
OSLC-Core-Version
header, as it might be used to execute non-OSLC requests.- Since:
- 1.1.0
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractResourceRequest(OslcClient client, URI uri)
Instantiates a new request.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description T
call()
Executes the request and parse the response content in the specified format.protected abstract ClientResponse
call(OslcResource resource)
Executes the request on the specified resource.protected T
createErrorResponse(OslcResource resource, ClientResponse response)
Processes the error response obtained when executing a request on the specified resource.protected <R> ResourceResponse<R>
createResourceResponse(ClientResponse response, Class<R> type)
Extracts aResourceResponse
instance from the obtained HTTP response.protected abstract T
createResponse(OslcResource resource, ClientResponse response)
Processes the response obtained when executing a request on the specified resource.protected OslcClient
getClient()
protected URI
getUri()
-
-
-
Constructor Detail
-
AbstractResourceRequest
protected AbstractResourceRequest(OslcClient client, URI uri)
Instantiates a new request.- Parameters:
client
- the REST client used to execute a request.uri
- the URI used for the underlying request.
-
-
Method Detail
-
getClient
protected final OslcClient getClient()
-
getUri
protected final URI getUri()
-
call
public T call()
Description copied from interface:ResourceRequest
Executes the request and parse the response content in the specified format. Throws aClientWebException
in case the HTTP response status is not20x
.
-
call
protected abstract ClientResponse call(OslcResource resource)
Executes the request on the specified resource. Subclasses may add extra information (such as headers) on the resource before executing the request.- Parameters:
resource
- the resource on which to execute a request.- Returns:
- the response of the request execution.
-
createResponse
protected abstract T createResponse(OslcResource resource, ClientResponse response)
Processes the response obtained when executing a request on the specified resource. Due to the contract of theResourceRequest
interface, this method is called only when the HTTP response status is20x
.- Parameters:
resource
- the resource on which a request is executed.response
- the response obtained.- Returns:
- the extraction of the response content into the expected format.
-
createResourceResponse
protected <R> ResourceResponse<R> createResourceResponse(ClientResponse response, Class<R> type)
Extracts aResourceResponse
instance from the obtained HTTP response. If the specified type isnull
orVoid.class
, this method does not try to parse the entity from the response and returns just the response headers in aResourceResponse
instance.- Type Parameters:
R
- the type of entity to instantiate when parsing the response.- Parameters:
response
- the HTTP response obtained when executing the request.type
- the type of information to extract from the response.- Returns:
- the extracted content.
-
createErrorResponse
protected T createErrorResponse(OslcResource resource, ClientResponse response)
Processes the error response obtained when executing a request on the specified resource. Due to the contract of theResourceRequest
interface, this method is called when the HTTP response status is anything but20x
.The default implementation raises a
ClientWebException
. Subclasses may override for example to return a default entity instead of throwing an exception.- Parameters:
resource
- the resource on which a request is executed.response
- the error response obtained.- Returns:
- a default entity or an entity extracted from the error response, if any.
- Throws:
ClientWebException
- if the response is indeed an error and no entity shall be extracted from it.- Since:
- 1.2.0
-
-