Reputation: 71
We have an in sequence in our APIM that picks up the payload which is in JSON format and transforms it to XML. Some time ago it was reported to us that when the JSON had a single element array, it failed because it converted it to an object. We fixed this by putting it in the synapse.properties file:
synapse.json.to.xml.processing.instruction.enabled=true
But now we are having problems with arrays of more than one element and APIM is throwing this exception:
ERROR {org.apache.synapse.mediators.base.SequenceMediator} - SOAP message MUST NOT contain Processing Instructions(PI) {org.apache.synapse.mediators.base.SequenceMediator}
org.apache.axiom.om.OMException: SOAP message MUST NOT contain Processing Instructions(PI)
Reviewing the sequence that gives us problems, it seems that when we pass the body of the request to the mediator arguments PayloadFactory converts it with the following format:
<?xml-multiple ListPacks?>
The code of the sequence summarized, but where the problem is:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="seq_header_v2" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="//soapenv:Body/*" name="soapBody" scope="default" type="STRING" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"/>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<sec:Header xmlns:sec="http://www.pruebas.com/XSD/SecurityHeader/">
<sec:User>$1</sec:User>
</sec:Header>
</soapenv:Header>
<soapenv:Body>
$2
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$ctx:api.ut.consumerKey"/>
<arg evaluator="xml" expression="get-property('soapBody')"/>
</args>
</payloadFactory>
</sequence>
And the JSON:
{
"ListPacksFullOnline": {
"typePack": "006",
"numPack": "632",
"ListPacks": [{
"relationPerson": "1",
"numOrder": 1
},
{
"relationPerson": "1",
"numOrder": 2
}
]
}
}
What could be wrong with the sequence?
For our part, we discard that it is a Formatters or Builders issue as well.
Upvotes: 1
Views: 445
Reputation: 14574
Try the following sequence.
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="seq_header_v2" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<sec:Header xmlns:sec="http://www.pruebas.com/XSD/SecurityHeader/">
<sec:User>$1</sec:User>
</sec:Header>
</soapenv:Header>
<soapenv:Body>
$2
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$ctx:api.ut.consumerKey"/>
<arg evaluator="json" expression="$"/>
</args>
</payloadFactory>
</sequence>
Upvotes: 1