API Payload transformation (XML to JSON)

What product/components do you use and which version/fix level are you on?

API Gateway

Is your question related to the free trial, or to a production (customer) instance?

No

What are you trying to achieve? Please describe it in detail.

Trying to convert an incomming SOAP/xml request to a JSON POST request to the backend API. Backend is an IS Flow. Problem is de payload conversion in API GW Policy. I try to use an XSLT file for this (see below) but this gives a failure. When I test the XSLT in a seperate testing tool it gives me the correct result. When using in API GW Policy I get the error ‘com.fasterxml.aalto.WFCException: Unexpected character ‘{’ (code 123) in prolog’. It looks to me as if the payload transformation only support XML as output?

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
{
"order_id": "<xsl:value-of select="normalize-space(/*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='SendTaak']/Send/Taak/Taaknummer)"/>"
}
</xsl:template>
</xsl:stylesheet>

Do you get any error messages? Please provide a full error message screenshot and log file.

2022-11-21 11:07:28 GMT [YAI.0103.0011E] (tid=690) [default][apigw-deploy-8579478986-j2d46][APIGW:71999692-c4e8-4cb0-8280-c6ed9962cb12:690:20b0bcb30ffe46d5a537de274a9d51bf:0cf362ef~8c8749e9~first][POL:requestTransformation]I--->  Error compiling the XSLT with key {1}. org.apache.axiom.om.OMException: com.fasterxml.aalto.WFCException: Unexpected character '{' (code 123) in prolog
2022-11-21 11:07:28 GMT [YAI.0002.0071E] (tid=690) [default][apigw-deploy-8579478986-j2d46][APIGW:71999692-c4e8-4cb0-8280-c6ed9962cb12:690:20b0bcb30ffe46d5a537de274a9d51bf:0cf362ef~8c8749e9~first][POL:requestTransformation]I--->  Exception occured while executing transformation policy. Exception:

Have you installed all the latest fixes for the products and systems you are using?

Yes. Working with cloudproducts only.

hi @bastiaanr ,
I am using 10.15 version of cloud API GW and i used xslt in request processing.
With the attached XSLT I am able to convert into json format.
I used REST API for testing purpose
sample.xslt.xsl (1.4 KB)

Let me know if this works for you.

Regards
Vikash Sharma

Hello Vikash,

Thank you for your reply. Nice, clean XSLT. The problem I described only occurs when using a SOAP API. When using REST API, as you did in your tests, everything works as expected. I think API GW expects an XML as output after every policy when running a SOAP API.

Thanks,
Bastiaan Rodenburg

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.