Dr3ko
Dr3ko

Reputation: 313

OSB replace node

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.

Upvotes: 0

Views: 7675

Answers (2)

Livio D.P.
Livio D.P.

Reputation: 71

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.

Upvotes: 2

Asutosh
Asutosh

Reputation: 1

As part of understanding there are 2 parts in your question:

  1. You want to replace the node content
  2. You are getting echo

Solution to point 1: You want to replace the node content:

If you want to replace data inside the tag then use replace with "replace node content" and provide the details as below: XPath: ./:getXXXXXXXXXXXXXXX/:Json In Variable: body Expression: {"otracosa":"otro","final":"final"}

Solution to point 2:You are getting echo:

This is the behavior of OSB that if no end point is invoked it will give echo. which will give information that no service has been invoked. To avoid echo make sure that your conditions are valid to execute the callout configuration.

If you need any further clarification you can ask here.

Regards

Asutosh

Upvotes: 0

Related Questions