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 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.
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 alsoCustomServiceGateway
. Service instance obtained can be used to execute the respective service by supplying the required input object. Execute method is used onServiceGateway
interface to execute the service. You will observe that the type of the input tocustom-service
is same as the type used for service implementation in thecom.example.service.rest.CustomService
class or thecom.example.service.functional.CustomService class
. The type of output is the same as the one used for definingCustomServiceGateway
interface whose Class object is returned fromgetServiceInterface
method in both versions ofCustomService
class. - The
com.example.service.rest.CustomService
class and thecom.example.service.functional.CustomService
class represents the same service implemented with two different approaches. The service meta information files inasset-integration-starter
project using the META-INF/rest-content-services.yml and the META-INF/functional-content-services.yml have an entry forcustom-service
pointing 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.