cancel
Showing results for 
Search instead for 
Did you mean: 

Issue in Content modifier and Groovy Script for reading the payload data

meerhyderali
Explorer
0 Kudos

Hi All,

I tried to extract the Body data from the XML payload, but couldn't succeed so I blogged and couldn’t found the one which suits my requirement. Hence I am writing this blog to make the script/Content Modifier based on the requirement.

Requirement

I need to fetch the data which is in the Body, I declared the xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" in main and tried to fetch the data using content modifier. But the body is coming as blank after the Content Modifier step execution by giving the path as //s:Envelope/s:Body/.

I tried using the Groovy script using the removal statement by below code, but its failing.

import com.sap.gateway.ip.core.customdev.util.Message;

import java.util.HashMap;

def Message processData(Message message) {

def removal=message.getBody(java.lang.String) as String;

removal=removal.replace(/s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"/,””);

message.setBody(removal);

return message;

}

Payload.

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none" s:mustUnderstand="1">http://sap.com/xi/WebService/soap1.1</Action>
</s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<_BAPI_PO_GETDETAILS xmlns="urn:sap-com:document:sap:rfc:functions">
<PO xmlns=""/>
</_BAPI_PO_GETDETAILS>
</s:Body>
</s:Envelope>

Can you all please help me on this using the content modifier where i am wrong. I have highlighted in bold which i required in payload.

Thank you in advance.

Regards,

Meer Hyder Ali

MortenWittrock
Active Contributor
0 Kudos

Hi

Please use the "Code" button to insert your XML payload. Otherwise it gets completely mangled. The same goes for the script code.

Regards,

Morten

Accepted Solutions (0)

Answers (2)

Answers (2)

RobertQ
Explorer
<br>

Hello Hyder Ali,

you can declare a content modifier and copy the body into a parameter, that you set as the body of the message.

If you use local-name() functionality in XPath you do not need to know the namespace of your selected node.

IFlow:

Parameters:

Name: ExtractedMessage

SourceType: XPath

SourceValue: //*[local-name()='_BAPI_PO_GETDETAILS']

DataType: org.w3c.dom.NodeList

Body:

Expression: ${property.ExtractedMessage}

input:

output:

If the answer helps you, please consider to accept it.

Best Regards

Robert

meerhyderali
Explorer
0 Kudos

Hi Robert,

Thanks for your inputs, without hardcode is there any way to the data, as we have different payloads with same format, only the below content gets changed. Else I need to create multiple iflows.

<_BAPI_PO_GETDETAILS xmlns="urn:sap-com:document:sap:rfc:functions">
<PO xmlns=""/>
</_BAPI_PO_GETDETAILS>

Regards,

Meer Hyder Ali

RobertQ
Explorer

Hi Hyder,

as long as you now, that you want the third descandand of the root node, you can change the XPath to "/*/*/*".

First would be the Envelope Element, second the Body Element, and the third Element is your selected node regardless the name or namespace of it.

Best Regards

Robert

MortenWittrock
Active Contributor

Hi

What you need is the Filter step, not the Content Modifier step. Add the namespace declaration to your iflow's runtime configuration like this:

Then add a Filter step configured like this:

Simulating this with your payload gives me this result:

Regards,

Morten

meerhyderali
Explorer
0 Kudos

Hi Morten,

Thanks for your inputs, I need the data only to be received as below. Also we have different payloads with same format only the below content gets changed. Hence I need to capture the data. If there is <Body> available then RFC ADAPTER is through an error.

<_BAPI_PO_GETDETAILS xmlns="urn:sap-com:document:sap:rfc:functions">
<PO xmlns=""/>
</_BAPI_PO_GETDETAILS>

Regards,

Meer Hyder Ali

MortenWittrock
Active Contributor
0 Kudos

Hi meerhyderali

Well, you did include the Body element in bold in your question, to be included in the result.

Anyway, I've updated the answer to produce the output without the Body element.

Regards,

Morten

meerhyderali
Explorer
0 Kudos

Hi Morten,

After the filter step, is there any step applied? If there no issues, Can you please share the screenshot?

Regards

Meer Hyder Ali

MortenWittrock
Active Contributor

Hi meerhyderali

No, the Filter step is the only step needed.

As I said, I've already tested the solution. If it's not working for you, then the payload is different from what you showed.

Regards,

Morten