WSO2 ESB/EI Send XML content to backend

When sending XML content inside the payload to the backend via WSO2 ESB,  we have to encode it and send it. In my usecase,  I have a Data Service which is accepting XML content as a parameter.

To implement this requirement, we can't directly define CDATA(blocks of text that are not parsed by XML parser) inside the payload factory mediator. So we have two option to do so.

The first option is that Encode XML content using Script mediator and use encoded value inside the payload factory mediator. You can read Hasitha's blog on this topic.

The second option is storing the format section of the payload factory mediator, in the registry. There you can directly define the CDATA tags inside the XML content stored in the registry. This allows you to define  CDATA inside payload factory mediator.

An example usecase is as below:

PayloadFacroy Mediator:

<?xml version="1.0" encoding="UTF-8"?>
<payloadFactory media-type="xml">
   <format key="conf:/format/Common_Error_Message.xml" />
   <args>
      <arg evaluator="xml" expression="$ctx:ORIGINAL_MESSAGE" />
      <arg expression="$axis2:HTTP_SC" />
   </args>
</payloadFactory>

Registry Content:

<?xml version="1.0" encoding="UTF-8"?>
<xs:logError xmlns:xs="http://wso2.org/services/data/error">
   <xs:originalPayload><![CDATA[$1]]></xs:originalPayload>
   <xs:statusCode>$2</xs:statusCode>
</xs:logError>

Post a Comment

Popular posts from this blog

Secure Spring Boot REST API using Basic Authentication

Yield Price Sri Lanka - Android Application

How to clean Registry log (REG_LOG) table