In this post, we will learn how to handle custom JSON messages for HTTP services with OSB 12.2.1, here we go:
The REST API connector allows to use of REST web services via HTTP but sometimes we need to struggle when the JSON data structure is not compatible with XML structure at all.
To solve this, it is necessary to know the complete structure of the request REST service. Since the structure of the content body could be a bit tricky to manage, we are going to do some steps to handle it in a good way.
Let’s start creating the HTTP transport as shown in the image below
Then select the request message type as TEXT, so you will be able to send the message body as TEXT with any type structure.
The next step is to build the JSON request as a string; we can use XQuery function as in the image below
As you can see, it is possible to build any JSON body since we start creating from scratch as a string.
When we have the request complete as a string, the next step is to call the rest service and set it as JSON using the transport header.
Finally, use the XQuery mapping file in an assigned component and include this as a request for the service callout
If we want to handle the request or response as JSON and not as String in the pipeline, then there is a good feature added in OSB 12.2.1 called JavaScript located in the Message Processing section.
There are several solutions to achieve this solution, like, for example, using a Java callout. So, this workaround that I provide fits more with the new feature of 12.2.1 (JavaScript) and is not complex at all to complete the integration.
If you have any questions, let me know!
Thanks for reading 💚