T
- the type of response to extract from the request execution.public abstract class AbstractResourceRequest<T> extends Object implements ResourceRequest<T>
This class doesn't set a OSLC-Core-Version
header, as it might be used to execute non-OSLC requests.
Constructor and Description |
---|
AbstractResourceRequest(OslcClient client,
URI uri)
Instantiates a new request.
|
Modifier and Type | Method and 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 a
ResourceResponse 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() |
public AbstractResourceRequest(OslcClient client, URI uri)
client
- the REST client used to execute a request.uri
- the URI used for the underlying request.protected final OslcClient getClient()
protected final URI getUri()
public T call()
ResourceRequest
ClientWebException
in case the HTTP response status is not 20x
.protected abstract ClientResponse call(OslcResource resource)
resource
- the resource on which to execute a request.protected abstract T createResponse(OslcResource resource, ClientResponse response)
ResourceRequest
interface, this method is called only when the HTTP response status is 20x
.resource
- the resource on which a request is executed.response
- the response obtained.protected <R> ResourceResponse<R> createResourceResponse(ClientResponse response, Class<R> type)
ResourceResponse
instance from the obtained HTTP response.
If the specified type is null
or Void.class
, this method does not try to parse the entity from the response and
returns just the response headers in a ResourceResponse
instance.R
- the type of entity to instantiate when parsing the response.response
- the HTTP response obtained when executing the request.type
- the type of information to extract from the response.protected T createErrorResponse(OslcResource resource, ClientResponse response)
ResourceRequest
interface, this method is called when the HTTP response status is anything but
20x
.
The default implementation raises a ClientWebException
.
Subclasses may override for example to return a default entity instead of throwing an exception.
resource
- the resource on which a request is executed.response
- the error response obtained.ClientWebException
- if the response is indeed an error and no entity shall be extracted from it.