I've been trying to replace a node with the action "Replace" but I don't understand, hope somebody help me.
I've an ErrorHandler, inside a Stage and inside; Assign > Replace > Reply.
In Assign;
Expression: $body
Variable: faultString
In Replace;
Xpath: .
In Variable: faultString
Expression: $body
Replace node contents
In Reply;
With failure
So here is I'm getting an echo, this;
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cli="http://www.xxxx.com.mx/xxxx/xxxxxxx">
<soapenv:Header xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"></soapenv:Header>
<soapenv:Body>
<cli:getXXXXXXXXXXXXXXX>
<Json>{"principal":"principal","secundario":"secundario"}</Json>
</cli:getXXXXXXXXXXXXXXX>
</soapenv:Body>
</soapenv:Envelope>
I want to replace the node
<Json>{"principal":"principal","secundario":"secundario"}</Json>
with;
<Json>{"otracosa":"otro","final":"final"}</Json>
By the way I'm getting that echo when OSB don't reach the endpoint and want to replace what I said.
Many thanks in advance.
In order to replace what you want use this configuration:
XPath: ./*:getXXXXXXXXXXXXXXX/Json
In Variable: $body
Expression: <Json>{"otracosa":"otro","final":"final"}</Json>
Replace entire node
Another option:
XPath: ./*:getXXXXXXXXXXXXXXX/Json
In Variable: $body
Expression: xs:string('{"otracosa":"otro","final":"final"}')
Replace node contents
Some explanation: (with my words)
Variable: where is the payload you want to replace. The root variable.
XPath: XPath to get the node you want to replace in the variable. In the example "." is the root bariable, "" can be any namespace. (you can also use "cli" instead "" if you define the namespace in the IDE)
Expression: Data you want to put.
Replace entire node/Replace node content: if you want to replace all the content including the tag you get with XPath or just the content inside the tags. I put you two examples to do the same.
About Echo, maybe you have no route node, or maybe you are not reaching endpoint. Response pipeline run in separate thread, if you have no route node, an echo is created to response pipeline.