Generic type parameters
Generic type parameters are used for implementing service interfaces. For more information on service interfaces, see Service implementations.
A service that resides in a plugin is just a programming unit, which takes some input and returns the expected output. Similarly, the REST API, wrapped by our service, asks for the required input (request body, headers, cookies, and query parameters) and produces the desired response (response body, headers, and cookies). It requires certain generic notations for the inputs and outputs exchanged during end-to-end logical flow.
Content Integration Framework uses RQ type parameter to denote the type of input supplied to the service on its invocation. Here, the RS type parameter is used to denote either the type of object returned by the Functional service or the type of response body returned by the remote REST API invoked using RESTful approach. The purpose of RS might change based on where it is used, but it always indicates the return value of something.
RestService<RQ, RS>
Refer the com.example.service.rest.CustomService class from the
asset-integration-starter project to understand the type
parameters used in the RestService inteface.
RestService is just a marker interface extended from
HttpService. The definition of these type parameters is similar
for the HttpService too.
- RQ
A service requires an input to perform its operation. RQ corresponds to the type of input, or request, the service requires when invoked. The
com.example.service.rest.CustomServicetakes an input of typeServiceInput. The same type parameter is used in theExecutionContextobject passed to all methods in theRestServiceor theHttpServiceinterface. The input, or the request, object passed to the service, when invoked, is obtained by calling thegetRequestmethod in theExecutionContextobject.@Override public HttpRequest buildRequest(ExecutionContext<ServiceInput> executionContext) { ServiceInput input = executionContext.getRequest(); // Remaining implementation omitted for brevity } - RSThis parameter type corresponds to the type of response (post deserialization) received from the remote REST API. Service implementation chooses this parameter based on the kind of object it wants to work with in
transformResponsemethod. If you look at the signature of thetransformResponsemethod in thecom.example.service.rest.CustomServiceclass, you will see that theApiResponseis supplied as the type argument to theHttpResponseclass, which corresponds to the RS type parameter of theRestServiceinterface.Note: Deserialization occurs according to theContent-Typeheader present in HTTP response received from REST API. The type used as the second generic argument toRestService, or theHttpService, must be appropriately annotated if Jackson or JAXB deserialization is expected.
FunctionalService<RQ, RS>
FunctionalService interface is analogous to the
java.util.function.Function interface from the Standard Java
Library. The type parameters of FunctionalService have similar
semantics as the type parameters of java.util.function.Function
interface. - RQ
Represents the type of input given to the service upon invocation.
- RS
Represents the type of value returned by the service upon completion.
ServiceGateway<RQ, RS>
This interface is used for implementing the getServiceInterface
method from AbstractService<RQ, RS> interface.
AbstractService is an important interface of
RestService, or HttpService, and the
FunctionalService. Semantics for RQ and RS for AbstractService
are same as RestService, or HttpService. It
declares the getServiceInterface method, which must be implemented
by a service. The getServiceInterface method must return the class
object of the derivative (child interface) of ServiceGateway. The
definition of
com.hcl.unica.system.integration.service.gateway.ServiceGateway
is as follows:
public interface ServiceGateway<RQ, RS> {
public RS execute(RQ request) throws ServiceExecutionException;
}
com.example.service.rest.CustomService class, the
CustomServiceGateway is defined as the child interface of
ServiceGateway by using ServiceInput and
ServiceOutput type arguments because the service receives an
input of type ServiceInput and returns the value of type
ServiceOutput on completion.getServiceInterfacemethod incom.example.service.rest.CustomServiceclass returns the class object ofCustomServiceGateway.ServiceGatewayinterface (or its child interface) provides information about the input and the output of service implementation.ServiceGatewayinterface is further used to contain the reference of service instance and invoke its execution.- By obtaining reference to the
ServiceGatewayinstance of any service thus implemented, execute(RQ request) method can be invoked to execute the service. Note that the execute method may throw theServiceExcecutionExceptionif anything goes wrong during service execution. Details on service invocation and exception handling will be provided in topics that follow.