on 05-16-2018 2:07 PM
Hi Experts,
Can you please help me out in these scenario of the subject mentioned as am new to HCI.
I have created like these below:
In the First Content Modifier i have used like these in the body:
<?xml version="1.0" encoding="UTF-8"?>
<queryUserResponse>
<User>
<id>USR-93</id>
<city>New Hyde Park</city>
<cellPhone/>
<businessPhone>(1) 215 555-0922</businessPhone>
<benchStrength/>
<addressLine1>11 Lightner Ave</addressLine1>
<Item>
<MailId>raj@xyz.com</MailId>
</Item>
</User>
</queryUserResponse>
And in the second Modifier
And in the Groovy Script i have written these code:
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.util.HashMap;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
def Message processData(Message message)
{
//Body
def body = message.getBody();
//Headers
def map = message.getHeaders();
//get the constant value associated with header 'id'
def value = map.get("id");
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(body);
Element compoundEmployeeList = doc.getRootElement();
List<Element> User = compoundEmployeeList.getChildren("User");
for(Element cEmployee : User)
{
// Extract the external id for the current employee
Element person = cEmployee.getChild("Item");
person.setChildText(value);
}
//Write your logic here
message.setProperty("payload", new XMLOutputter().outputString(doc));
return message;
}
Kindly help me to get through these scenario.
Thanks
Hi Raju
The following Groovy script does three things:
Here's the script:
import com.sap.gateway.ip.core.customdev.util.Message
import groovy.util.XmlSlurper
import groovy.xml.XmlUtil
def Message processData(Message message) {
def itemNewVal = message.getProperty('id')
def queryUserResponse = new XmlSlurper().parseText(message.getBody(java.lang.String))
queryUserResponse.User.Item.replaceBody(itemNewVal)
message.setBody(XmlUtil.serialize(queryUserResponse))
return message
}
Regards,
Morten
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Morten,
Thanks a lot , it is working now.
You are super...!!
Thanks,
Raju.
HI @Morten Wittrock
I want to perform some XML parsing using JDOM lib by calling a below classes, so I used to import as stated below in my groovy script:
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
but while deploying getting below error:
Message processing failed.Processing Time: 8 sec 584 ms
Error Details javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: EffectiveData__Script.gsh: 11: unable to resolve class org.jaxen.XPath @ line 11, column 1. import org.jaxen.XPath; ^ EffectiveData__Script.gsh: 9: unable to resolve class org.jdom.output.XMLOutputter @ line 9, column 1. import org.jdom.output.XMLOutputter ^ EffectiveData__Script.gsh: 8: unable to resolve class org.jdom.input.SAXBuilder @ line 8, column 1. import org.jdom.input.SAXBuilder; ^ EffectiveData__Script.gsh: 12: unable to resolve class org.jaxen.jdom.JDOMXPath @ line 12, column 1. import org.jaxen.jdom.JDOMXPath; ^ EffectiveData__Script.gsh: 6: unable to resolve class org.jdom.Element @ line 6, column 1. import org.jdom.Element ^ EffectiveData__Script.gsh: 5: unable to resolve class org.jdom.Document @ line 5, column 1. import org.jdom.Document; ^ EffectiveData__Script.gsh: 7: unable to resolve class org.jdom.JDOMExcepti.......I can download the lib from the internet but now how to import/deploy the same to HCI or CPI tenant? Please help.Thanks for such very simple code ! Helps here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
9 | |
8 | |
6 | |
6 | |
6 | |
5 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.