<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=2233467260228916&amp;ev=PageView&amp;noscript=1">

Handle custom JSON body for HTTP API with OSB 12.2.1

Cegal Tech Advisors Fighting fuzz by striving to make your coding life more straight forward.
04/14/2021 |

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.

Solution

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.

Basically, this new component allows us to insert JavaScript code where we can create or modify existing variables in the pipeline. For example, if we want to get the value of a field in the JSON response, we initiate with the variable called “process” and reference the response variable. In this case, the variable of the response is a JSON object, so I pick up the id field, which is a number, and parse it as a string.

Conclusion

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 💚

 

Related articles

Call REST API in Service Bus 12.2.1.2 (JSON Request/Response)
Cegal Tech Advisors Fighting fuzz by striving to make your...
arrow
Oracle
Solving the OSB 12c Oracle data source installation error for OCI
Cegal Tech Advisors Fighting fuzz by striving to make your...
arrow
Retrieve data from JSON Using JavaScript expressions in Oracle...
Cegal Tech Advisors Fighting fuzz by striving to make your...
arrow