Class WebAppResourceRequest<T>

  • Type Parameters:
    T - the type of response to extract from the request execution.
    All Implemented Interfaces:
    ResourceRequest<T>, Callable<T>
    Direct Known Subclasses:
    GetProxyResource, PutProxyResource

    public abstract class WebAppResourceRequest<T>
    extends Object
    implements ResourceRequest<T>
    Base class for REST requests executed from the server to another remote server.

    The contract is to throw a WebApplicationException for any HTTP responses whose status is not 20x.

    The recommendation is to use the call(HttpServletRequest, Function) method in most cases. Subclassing shall be used to define a WebAppResourceRequest called from multiple places. Subclasses may call a client ResourceRequest in their overridden call(OslcClient) method. Any client exception that may be thrown will be caught and changed to a web exception.

    Since:
    1.3.0
    • Constructor Detail

      • WebAppResourceRequest

        protected WebAppResourceRequest​(HttpServletRequest request)
        Instantiates a new request.
        Parameters:
        request - the HTTP request used to obtain an OSLC client
    • Method Detail

      • call

        public static <T> T call​(HttpServletRequest request,
                                 Function<OslcClient,​T> function)
        Executes a REST request from this server to a remote server, the actual request being determined by the given function. The HTTP request is used to obtain an OSLC client, then given to the function to execute a REST request (likely a ResourceRequest) and provide a result.
        Type Parameters:
        T - the type of response to extract from the request execution.
        Parameters:
        request - the HTTP request used to obtain an OSLC client
        function - the function to execute with the obtained OSLC client
        Returns:
        the result of the function
        Throws:
        WebApplicationException - for any HTTP response whose status is not 20x. Any client exception thrown by the function is caught by this method and changed to a web exception.
        Since:
        3.4.0
      • call

        public final T call()
        Executes the request and parse the response content in the specified format. Throws a WebApplicationException 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 T call​(OslcClient client)
        Executes the request with the specified client.

        Subclasses may call a ResourceRequest or use the client to make a custom request.

        Parameters:
        client - the client to use to execute the request.
        Returns:
        the response of the request execution.