Service invocation

The asset-integration-starter project contains a com.example.service.client.CustomServiceClient class to illustrate the service invocation.

The invocationDemo method in this class obtains the reference to custom-service by using getServiceGateway static method from ServiceGatewayFactory class. The getServiceGateway method takes three arguments to return the service instance. The arguments are as follows:
  • String systemId

    This system identifier is same as the one used in service meta information file to declare the service whose instance needs to be obtained.

  • String serviceName

    This is name of service whose instance needs to be obtained. It must be same as the one declared in service meta information file.

  • Class<T> gatewayClass

    This must be the Class object of ServiceGateway interface (or its child interface). It must match the return value of getServiceInterface method in corresponding service implementation.

The invocationDemo method in the com.example.service.client.CustomServiceClient class uses CustomServiceGateway (gatewayClass) to obtain the service instance of custom-service (serviceName) for the system Foo (systemId). The following code snippet is for your reference:
public void invocationDemo() {
		String systemId = "Foo";
		
		CustomServiceGateway customService = 
ServiceGatewayFactory.getServiceGateway(
				systemId, 
				"custom-service",
				CustomServiceGateway.class
			);
		
		ServiceInput input = new ServiceInput();
		ServiceOutput output = customService.execute(input);
	}
The return type of getServiceGateway is also CustomServiceGateway. Service instance obtained can be used to execute the respective service by supplying the required input object.
Note:
  • The return type of getServiceGateway is also CustomServiceGateway. Service instance obtained can be used to execute the respective service by supplying the required input object. Execute method is used on ServiceGateway interface to execute the service. You will observe that the type of the input to custom-service is same as the type used for service implementation in the com.example.service.rest.CustomService class or the com.example.service.functional.CustomService class. The type of output is the same as the one used for defining CustomServiceGateway interface whose Class object is returned from getServiceInterface method in both versions of CustomService class.
  • The com.example.service.rest.CustomService class and the com.example.service.functional.CustomService class represents the same service implemented with two different approaches. The service meta information files in asset-integration-starter project using the META-INF/rest-content-services.yml and the META-INF/functional-content-services.yml have an entry for custom-service pointing to the respective versions of the factoryClass. These two versions are provided only for illustration purpose. For all practical purposes, only one version of the service implementation is expected by the Asset Picker. Irrespective of the approach used for service implementation, the method for service invocation remains the same.

Multi-partitioned clients

In case of multi-partitioned client application of Asset Picker, the earlier mentioned method of obtaining the service instance will appropriately return reference partition specific to the service gateway. The ExecutionContext object passed to various callback methods will contain the necessary partition specific information to work with.