Class AbstractResourceRequest<T>

    • 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 a ClientWebException in case the HTTP response status is not 20x.
        Specified by:
        call in interface Callable<T>
        Specified by:
        call in interface ResourceRequest<T>
      • 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 the ResourceRequest interface, this method is called only when the HTTP response status is 20x .
        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 a 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.
        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 the 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.

        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