Software AG Products 10.7 | Using API Gateway | Usage Scenarios | Custom Policy Extension | How Do I Invoke an IS Service using a Custom Extension?
 
How Do I Invoke an IS Service using a Custom Extension?
This use case explains how to invoke an IS service using custom extension in one of the policy stages and enforce during API processing.
For example you may want to process the request messages and transform them into a format required by the native API or perform some custom logic before API Gateway sends the requests to the native API.
The use case starts when you have an API which has to be enforced with a messaging custom extension and ends when you successfully invoke the API with the custom extension enforced.
*To invoke an IS service using custom extension
1. Click APIs on the title navigation bar.
2. Click the required API.
The API details page appears.
3. Click Edit.
4. Select Policies.
5. Click Any policy stage > Custom Extension.
This adds the custom extension policy where you can configure the required properties.
Click to open the policy properties section in a full page.
6. Provide the following information in the Conditions section, as required:
Property
Description
Condition
Conditions are used to specify when the policy has to be executed. You can add multiple conditions with logical operators.
Available values are:
*AND. API Gateway executes this policy when all the configured conditions comply in the respective policy stage
*OR. This is selected by default. API Gateway executes this policy when any one of the configured conditions complies.
Click Add Condition and provide the following information and click Add.
*Variable. Specifies the variable type with a syntax.
*Operator. Specifies the operator to use to relate variable and the value. You can select one of the following:
*Equals
*Equals ignore case
*Not equals
*Not equals ignore case
*Contains
*Exists
*Range
*Greater Than
*Less Than
*Value. Specifies a plain value or value with a syntax.
For details about the variables available in API Gateway, see Variables Available in API Gateway.
7. Click Custom Action.
8. Select webMethods IS service in the custom extension Type field.
9. Provide the following information in the Invoke webMethods IS section, as required:
Property
Description
webMethods IS Service
Specify the webMethods IS service to be invoked to process the messages. .
The webMethods IS service must be running on the same Integration Server as API Gateway.
Note:
If an exception occurs when invoking the webMethods IS service, by default API Gateway displays the status code as 500 and error message as Internal Server Error.
You can set custom status code and error message by setting the following properties in the message context of the webMethods IS service:
*service.exception.status.code
*service.exception.status.message
The sample code is given below:

IDataCursor idc = pipeline.getCursor();
MessageContext context = (MessageContext)IDataUtil.get(idc,"MessageContext");
if(context != null)
{
context.setProperty("service.exception.status.code", 404);
context.setProperty("service.exception.status.message", "Object Not Found");
throw new ServiceException();
}
Note:
If ServiceException or FlowException occurs when invoking webMethods IS Service, the message given in the exception is displayed to the client. If any other exception occurs, a generic error message is displayed to the client.
Run As User
Specifies the authentication mode to invoke the IS service.
If this field is left blank the incoming credentials of the user, identified by API Gateway, are used to authenticate and invoke the IS service. You can also specify a particular user, you want API Gateway to invoke the IS service.
Comply to IS Spec
Select this property to mark it true, if you want the input and the output parameters to comply to the IS Spec present in pub.apigateway.invokeISService.specifications folder in wmAPIGateway package.
webMethods IS Service Alias
Specifies the webMethods IS service alias to be invoked to process the messages.
Start typing the webMethods alias name, select the alias from the type-ahead search results displayed, and click to add one or more aliases.
10. Click Save.
The API is saved with the added custom extension.
11. Invoke the API.
The applied custom extension invokes the IS service and processes as configured.