Payload factory is unable to handle special characters in XML payloads

Randini Senanayake
1 min readFeb 15, 2021

--

Issues with Wso2 ESB :

The issue is with the older versions of the ESB (Fixed from 6.2 version onwards) Consider that the ESB has a REST API which gets a JSON property from a JSON payload request and inserts into the XML payload factory as below.

<payloadFactory media-type="xml">
<format>
<p:_postinsertmembersearch xmlns:p="http://ws.wso2.org/dataservice">
<superfundAddress>$1</superfundAddress>
<p:_postinsertmembersearch>
</format>
<args>
<arg evaluator="json" expression="$.superfundAddress"/>
</args>
</payloadFactory>

JSON payload

{
"superfundAddress" : "123&456 Test 5 Street"
}

It causes the following error when the property has “&” (ampersand) from the extracted JSON property.

TID: [-1234] [] [2020–11–05 19:42:12,154] ERROR {org.apache.synapse.mediators.base.SequenceMediator} - [com.ctc.wstx.exc.WstxLazyException] Unexpected character '4' (code 52) (expected a name start character)
at [row,col {unknown-source}]: [1,808] {org.apache.synapse.mediators.base.SequenceMediator}
[com.ctc.wstx.exc.WstxLazyException] com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '4' (code 52) (expected a name start character)
at [row,col {unknown-source}]: [1,808]
at com.ctc.wstx.exc.WstxLazyException.throwLazily(WstxLazyException.java:45)
at com.ctc.wstx.sr.StreamScanner.throwLazyError(StreamScanner.java:720)

The above error is caused due to the “$.superfundAddress“ property consisting of an “&” (ampersand) from the extracted JSON property. (Value used for testing : 123&456 Test 5 Street )

Following are the workarounds that can be done to resolve this.

There are two workarounds to overcome this issue.

  1. With XML evaluator
<payloadFactory media-type="xml">
<format>
<p:_postinsertmembersearch xmlns:p="http://ws.wso2.org/dataservice">
<p:super_fund_address>$1</p:super_fund_address>
<p:_postinsertmembersearch>
</format>
<args>
<arg evaluator="xml" expression="$body/superfundAddress"/>
</args>
</payloadFactory>

2. With a property

<property name="superfundAddress" expression="json-eval($.superfundAddress)"/>
<payloadFactory media-type="xml">
<format>
<p:_postinsertmembersearch xmlns:p="http://ws.wso2.org/dataservice">
<p:super_fund_address>$1</p:super_fund_address>
<p:_postinsertmembersearch>
</format>
<args>
<arg evaluator="xml" expression="$ctx:superfundAddress"/>
</args>
</payloadFactory>

--

--

No responses yet