on 2021 Jun 22 4:05 PM
Hi 7a519509aed84a2c9e6f627841825b5a, engswee.yeoh
I am trying to write groovy script to compare two xml files in CPI.
Below is the code which I have written.
import com.sap.gateway.ip.core.customdev.util.Message
//Imports for DataStoreService-class
import com.sap.it.api.asdk.datastore.*
import com.sap.it.api.asdk.runtime.*
mport org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
import org.xmlunit.diff;
Message processData(Message message)
{
def service = new Factory(DataStoreService.class).getService()
//Check if valid service instance was retrieved
if( service != null) {
//Read data store entry via id
def dsEntry = service.get("MetadataStorage","Metadata")
def result = new String(dsEntry.getDataAsArray())
//message.setBody(body)
def dsEntry1 = service.get("MetadataCurrent","CurrentData")
def result1 = new String(dsEntry1.getDataAsArray())
//message.setBody(body)
DifferenceEngine diff = new DOMDifferenceEngine();
diff.addDifferenceListener(new ComparisonListener() {
public void comparisonPerformed(Comparison comparison, ComparisonResult outcome) {
Assert.fail("found a difference: " + comparison);
}
});
diff.compare(result, result1);
}
// return message
}
Below is the error I am getting , Could you please help.
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
compareXML__Script.groovy: 11: unable to resolve class org.jdom.output.XMLOutputter
@ line 11, column 1.
import org.jdom.output.XMLOutputter;
^
compareXML__Script.groovy: 10: unable to resolve class org.jdom.input.SAXBuilder
@ line 10, column 1.
import org.jdom.input.SAXBuilder;
^
compareXML__Script.groovy: 8: unable to resolve class org.jdom.Element
@ line 8, column 1.
import org.jdom.Element;
^
compareXML__Script.groovy: 12: unable to resolve class org.xmlunit.diff
@ line 12, column 1.
import org.xmlunit.diff;
^
compareXML__Script.groovy: 27: unable to resolve class DifferenceEngine
@ line 27, column 19.
DifferenceEngine diff = new DOMDifferenceEngine();
^
compareXML__Script.groovy: 27: unable to resolve class DOMDifferenceEngine
@ line 27, column 26.
DifferenceEngine diff = new DOMDifferenceEngine();
^
compareXML__Script.groovy: 28: unable to resolve class ComparisonListener
@ line 28, column 53.
ener(new ComparisonListener() {
^
compareXML__Script.groovy: 29: unable to resolve class Comparison
@ line 29, column 41.
blic void comparisonPerformed(Comparison
^
compareXML__Script.groovy: 29: unable to resolve class ComparisonResult
@ line 29, column 64.
formed(Comparison comparison, Comparison
^
9 errors
Request clarification before answering.
Hi there
Those error messages are telling you that the runtime can't find some of the classes - specifically the JDOM and XMLUnit ones. To solve it, download the JDOM and XMLUnit JAR files and add them to your iflow on the Resources tab.
Good luck and have fun,
Morten
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi 7a519509aed84a2c9e6f627841825b5a , Thank you for your response.
I have imported the above jars, PFB Screenshot. Please Let me know if am missing anything.
Below is the error:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
compareXML__Script.groovy: 11: unable to resolve class org.jdom.output.XMLOutputter
@ line 11, column 1.
import org.jdom.output.XMLOutputter;
^
compareXML__Script.groovy: 10: unable to resolve class org.jdom.input.SAXBuilder
@ line 10, column 1.
import org.jdom.input.SAXBuilder;
^
compareXML__Script.groovy: 8: unable to resolve class org.jdom.Element
@ line 8, column 1.
import org.jdom.Element;
^
compareXML__Script.groovy: 12: unable to resolve class org.xmlunit.diff
@ line 12, column 1.
import org.xmlunit.diff;
^
compareXML__Script.groovy: 6: unable to resolve class org.jdom.Document
@ line 6, column 1.
import org.jdom.Document;
^
compareXML__Script.groovy: 27: unable to resolve class DifferenceEngine
@ line 27, column 19.
DifferenceEngine diff = new DOMDifferenceEngine();
^
compareXML__Script.groovy: 27: unable to resolve class DOMDifferenceEngine
@ line 27, column 26.
DifferenceEngine diff = new DOMDifferenceEngine();
^
compareXML__Script.groovy: 28: unable to resolve class ComparisonListener
@ line 28, column 53.
ener(new ComparisonListener() {
^
compareXML__Script.groovy: 29: unable to resolve class Comparison
@ line 29, column 41.
blic void comparisonPerformed(Comparison
^
compareXML__Script.groovy: 29: unable to resolve class ComparisonResult
@ line 29, column 64.
formed(Comparison comparison, Comparison
^
10 errors
Hi chandrasekharkoduru450
Ah, two more things. The JDOM package is now called org.jdom2, so you need to adjust those import statements. Also, org.xmlunit.diff is a package, so to import all classes in it, use:
import org.xmlunit.diff.*
If the code itself does not work, please raise a new question with the specifics of the new problem, instead of adding new questions in this thread.
Regards,
Morten
User | Count |
---|---|
52 | |
6 | |
5 | |
5 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.