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 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 takes an input of type ServiceInput. The same type parameter is used in the ExecutionContext object passed to all methods in the RestService or the HttpService interface. The input, or the request, object passed to the service, when invoked, is obtained by calling the getRequest method in the ExecutionContext object.

    	public HttpRequest buildRequest(ExecutionContext<ServiceInput> executionContext) {
    		ServiceInput input = executionContext.getRequest();
    		// Remaining implementation omitted for brevity
  • RS
    This 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 transformResponse method. If you look at the signature of the transformResponse method in the class, you will see that the ApiResponse is supplied as the type argument to the HttpResponse class, which corresponds to the RS type parameter of the RestService interface.
    Note: Deserialization occurs according to the Content-Type header present in HTTP response received from REST API. The type used as the second generic argument to RestService, or the HttpService, 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;
Semantics for the type parameter RQ is the same as mentioned earlier. The other type parameter, RS represents the output of the service that resides in the plugin. It does not represent the response received from remote REST API or any other target systems. For the 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.
  • getServiceInterface method in class returns the class object of CustomServiceGateway. ServiceGateway interface (or its child interface) provides information about the input and the output of service implementation. ServiceGateway interface is further used to contain the reference of service instance and invoke its execution.
  • By obtaining reference to the ServiceGateway instance of any service thus implemented, execute(RQ request) method can be invoked to execute the service. Note that the execute method may throw the ServiceExcecutionException if anything goes wrong during service execution. Details on service invocation and exception handling will be provided in topics that follow.