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, takes the requested content and produces the desired response. It requires certain generic notations for the inputs and outputs exchanged during end-to-end logical flow.

Asset Picker uses RQ to denote certain inputs to the service, and RS to denote either output of the service or response of the remote REST API. The definition of RS might change based on where it is used.

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.CustomService 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.

    @Override
    public String getEndpointUrl(ExecutionContext<ServiceInput> executionContext) {
    ServiceInput input = executionContext.getRequest();
    // Remaining implementation omitted for brevity
    }
    
  • RS
    This type parameter 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 com.example.service.rest.CustomService class, you will see that the object of ApiResponse type is supplied as the first argument, which corresponds to the RS type parameter of 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 FunctionalInterface 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. This is the only additional method a RESTful service needs to implement and it returns the class object of the derivative (child interface) of ServiceGateway. The definition of com.hcl.unica.cms.integration.service.gateway.ServiceGateway is as follows:

public interface ServiceGateway<RQ, RS> {
		public RS execute(RQ request);
}
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 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.
Note: getServiceInterface method in com.example.service.rest.CustomService 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.