Custom Code for Invoking an Integration Service from a Preprocessor, Postprocessor, Custom filter, Custom Servlet, or Java service
The middleware Java API helps to invoke an integration/Orchestration/object service from custom code.
Important: The Volt MX Foundry Console does not send the dependent artifacts with the request for a Java Service. Therefore, invoking a service from Custom Code using the ServicesManager API is not supported.
How to use the API
Initial steps is to create an Operation Data and Service Request Objects:
To invoke and get JSON response:
To invoke and get result object:
> **_Note:_** In case of result object API.
To invoke a PassThroughService:
To get the service manager in the custom filter or servlets using HttpServletRequest instance:
To fetch user profile, user attributes and security attributes:
To fetch user attributes and security attributes using provider name:
If you want to invoke an authentication service which contains identity parameters or headers, modify the inline invocation of the service and include the new authorization token (X-VoltMX-Authorization token). You can pass the token to the parent service (service which invokes the inline service), read the token from the custom code and pass it in the Services Manager API.
To execute a sequence of RDBMS operations in a transaction you can use Transaction manager. When you execute services through Transaction Manager, the services listed in TransactionExecutor are executed in a single transaction, and the transaction roll backs if there is any error.
For Example: Let us assume a database has a Country table and an Address table. The Address table contains a country column. You can use Transaction Manager in the transaction, where the operations update the Country table first and then update address with country in the Address table. If any operation fails, the changes done by previous operations/verbs will roll back automatically.
Following is the sample code for it:
Exception Handling (for Java Preprocessor and Postprocessor)
In case of Exception from the API, result object will be available as an attribute in the request object.
For example:
Note: For server upgrade from version 7.x to version 8.3.x, if Services Manger APIs are used in the custom code, you must rebuild the jar with the latest middleware plugins to avoid IncompatibleClassChangeError.
Exception Handling (for Multiple Java Preprocessor and Postprocessor)
If there is an exception occurs in a request with many pre-processors, the Volt MX Server ignores the request.
If there is an exception occurs in a response, the Volt MX Server sends the response including the exception details.