Package com.sodius.oslc.server.requests
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 not20x
.The recommendation is to use the
call(HttpServletRequest, Function)
method in most cases. Subclassing shall be used to define aWebAppResourceRequest
called from multiple places. Subclasses may call a clientResourceRequest
in their overriddencall(OslcClient)
method. Any client exception that may be thrown will be caught and changed to a web exception.- Since:
- 1.3.0
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
WebAppResourceRequest(HttpServletRequest request)
Instantiates a new request.
-
Method Summary
All Methods Static 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 T
call(OslcClient client)
Executes the request with the specified client.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.
-
-
-
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 aResourceRequest
) 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 clientfunction
- the function to execute with the obtained OSLC client- Returns:
- the result of the function
- Throws:
WebApplicationException
- for any HTTP response whose status is not20x
. 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.
-
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.
-
-