Service invocation
The asset-integration-starter project contains a com.example.service.client.CustomServiceClient class to illustrate the service invocation.
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 systemIdThis system identifier is same as the one used in service meta information file to declare the service whose instance needs to be obtained.
String serviceNameThis 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> gatewayClassThis 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.
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
getServiceGatewayis alsoCustomServiceGateway. Service instance obtained can be used to execute the respective service by supplying the required input object. Execute method is used onServiceGatewayinterface to execute the service. You will observe that the type of the input tocustom-serviceis same as the type used for service implementation in thecom.example.service.rest.CustomServiceclass or thecom.example.service.functional.CustomService class. The type of output is the same as the one used for definingCustomServiceGatewayinterface whose Class object is returned fromgetServiceInterfacemethod in both versions ofCustomServiceclass. - The
com.example.service.rest.CustomServiceclass and thecom.example.service.functional.CustomServiceclass represents the same service implemented with two different approaches. The service meta information files inasset-integration-starterproject using the META-INF/rest-content-services.yml and the META-INF/functional-content-services.yml have an entry forcustom-servicepointing to the respective versions of thefactoryClass. 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.