Outbound callback service
Outbound callback service is useful when there is need to modify headers before sending to consumer or there is any other modification which needs to be perform on payload. For webservice provider outbound callback service can be used to modify response payload to client.
For this post, requirement was to change security header which is generated by IS. Rampart module always mustUnderstand attribute to 1 for security Policy, but here client wanted esb to send this attribute as 0 or not send at all. There is no out of the box setting to achieve this.
Outbound callback service was used to achieve this requirement.
Below are the step by step explanation how to achieve this.
- Create a flow service in desired location, which will act as outbound call back service and will hold logic which needs to be performed. Use “pub.soap.utils:callbackServiceSpec” specification reference for this service.
- Open webservice consumer where outbound call back services are needed to be implemented. Look for outbound call back service property. Navigate and select the service created in last step. This is the only thing which needs to be done for webservice consumer.
- Come back to flow service created in first step and write logic for what need to be done in that service.
- Outbound service gets called at two phases during consumer connector call. First is PRESECURITY and second is TRANSPORT. For my requirement, header need to be changed on TRANSPORT phase as that is the last phase. If we add header at transport phase, then we run into risk of adding same header twice.
- Below is a screen shot of code written in outbound call back service.
- First getProperty is called with key as “CallbackPhase” which will return phase values as either “PRESECURITY” or “TRANSPORT”
- For this requirement we are forming security doc in service and adding using addHeaderBlock.
- Inbuilt services can be used to retrieve header from messageContext and then modify.
This is simple implementation of Outbound call back service. Depending on your requirement this can be expanded further.