Class WebAppResourceRequest<T>

java.lang.Object
com.sodius.oslc.server.requests.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.

You may use:

Subclassing should be avoided in most cases. It shall be used to define a WebAppResourceRequest called from multiple places. Subclasses may call a client ResourceRequest in the 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 Details

    • WebAppResourceRequest

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

    • call

      public static <T> T call(HttpServletRequest request, Function<OslcClient,T> function)
      Uses the HTTP request to obtain an OSLC client and execute the function to generate a result. The function is meant to use the provided OSLC client for executing REST requests from this server to a remote server. Any client exception thrown by the function is caught by this method and changed to a web exception.
      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
      Since:
      3.4.0
    • call

      public static <T> T call(ResourceRequest<T> request)
      Executes the given request to provide a result. Any client exception thrown by the request is caught by this method and changed to a web exception.
      Type Parameters:
      T - the type of response to extract from the request execution.
      Parameters:
      request - the request to execute
      Returns:
      the result of the request
      Throws:
      WebApplicationException - for any HTTP response whose status is not 20x
      Since:
      4.0.0
    • call

      public static <T> T call(OslcClientFactory clientFactory, Function<OslcClient,T> function)
      Uses the given factory to obtain an OSLC client to execute the function and generate a result. The function is meant to use the provided OSLC client for executing REST requests from this server to a remote server. Any client exception thrown by the function is caught by this method and changed to a web exception.
      Type Parameters:
      T - the type of response to extract from the request execution.
      Parameters:
      clientFactory - a factory to create 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
      Since:
      4.0.0
    • call

      public static <T> T call(Supplier<OslcClient> clientSupplier, Function<OslcClient,T> function)
      Uses the given supplier to obtain an OSLC client to execute the function and generate a result. The function is meant to use the provided OSLC client for executing REST requests from this server to a remote server. Any client exception thrown by the function is caught by this method and changed to a web exception.
      Type Parameters:
      T - the type of response to extract from the request execution.
      Parameters:
      clientSupplier - provides an OSLC client instance
      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
      Since:
      4.0.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.