Unable to loop through an object list

Hi,

I have a String which contains multiple repeating xml nodes. For Eg:
PurchaseOrderabc…
PurchaseOrderabc…

I wrote a java service which splits the String into indivdual messages into an ArrayList and put it to the pipeline. When I try to loop through the ArrayList (which I assume is an object list), it does not even enter the loop. However, if put the Arraylist elements into a String array, it works fine.

But to put the messages inside a string list, I will need to go through an extra loop in the java service as a String array in java is static while an ArrayList can grow dynamically and I do not know before hand how many xml nodes are present.

This could have performance issues when the volumes are high. Is there a way I can avoid this extra loop by looping through an object list in WM.

i have attached an image of my WM Developer instance.

My java service is as below:

IDataCursor pipelineCursor = pipeline.getCursor();
try
{
String xmlString = IDataUtil.getString( pipelineCursor, “translatedMessage” );
logInfo("xmlString = " + xmlString);
ArrayList xmlList = new ArrayList();
String splitXml = “”;

do{
splitXml = xmlString.substring(xmlString.indexOf(“”),xmlString.indexOf(“”)+7);
xmlList.add(splitXml);
logInfo(“splitXml = " + splitXml);
xmlString = xmlString.substring(xmlString.indexOf(”")+1,xmlString.length());
}while (splitXml.length()<= xmlString.length());
int poCount = xmlList.size();
logInfo("poCount = "+poCount);
String xmlStringList = new String[poCount];
int i=0;

Iterator iter = xmlList.iterator();
while (iter.hasNext()){
xmlStringList[i]= (String)iter.next();
logInfo(“\n\ntXML=”+xmlStringList[i]);
i++;
}
//debugging end
IDataUtil.put( pipelineCursor, “xmlList”, xmlStringList);
//IDataUtil.put( pipelineCursor, “xmlList”, xmlList);
}catch (Exception e){
logInfo("error message = "+e.getMessage());
}
finally{
pipelineCursor.destroy();
}

I am a java developer and new to Web Methods. Any help would be appreciated. Thanks

sjalis
wmLooping.jpg

sjalis,

If using Java is not a mandate here then I would suggest you to go with wM itself if it is just to split the xml nodes and extract data.

Since the XML string looks like a straight forward and a well formed XML, the built-in services to convert XML String to Document would do the spliting for you and give you each node as a document element in a documentList(txml). Then you can extract/map out the required values as you wish under a loop.
 
Hope this helps,

cheers,
Suren

Suren,

Would you know which particular flow services will help me in the splitting? Also, can i do an equivalent of a do-while loop in WM. Thanks.

SJalis

xmlNodeToDocument should do it.

HTH

Yes, as leonlee suggested, use xmlStringToNode and xmlNodeToDocument services to convert ur XML string to document.

Actually the xml is not well formed. If you save the below string as an xml file and open it in a browser, it will be unable to display it. The individual tXML nodes by themselves are well formed. See below log message…

That’s the reason i want to split them into individual xmls and post them to the App Server via the IS.
2010-04-23 09:37:47 EDT [ISP.0090.0004I] Manh.Utils.Ftp.Services:processFtpJob – translated message - PO = <?xml version="1.0" encoding="UTF-8"?>
WMIS<Action_Type>Create</Action_Type><Reference_ID>036_HJBT_EO1</Reference_ID><Message_Type>po</Message_Type><Company_ID>5</Company_ID>PO504162010_90362010031001/06/2010 00:00:0001/06/2010 00:00:0001234567890123452540 Windy Hill RoadMariettaGA30067US036100 Friars LanePaulsboroNJ08066USRoute125Stop100TrailerCodeEO1CustOrderNbrPickticketCtrlNbr04162010_9CustNbr001233333StarPickNbr0008416JRO0015DescWhite111004EachWMIS<Action_Type>Create</Action_Type><Reference_ID>036_HJBT_EO1</Reference_ID><Message_Type>po</Message_Type><Company_ID>5</Company_ID>PO504162010_100362010031001/06/2010 00:00:0001/06/2010 00:00:0001234567890123452540 Windy Hill RoadMariettaGA30067US036100 Friars LanePaulsboroNJ08066USRoute125Stop100TrailerCodeEO1CustOrderNbrPickticketCtrlNbr04162010_10CustNbr001233333StarPickNbr0008416JRO0015DescWhite111004Each
2010-04-23 09:37:47 EDT [ISP.0090.0004I] Manh.Utils.Ftp.Services:processFtpJob – Before Calling xmlStringToXMLNode
2010-04-23 09:37:47 EDT [ISP.0090.0004I] Manh.Utils.Ftp.Services:processFtpJob – Before Calling xmlNodeDocument
2010-04-23 09:37:47 EDT [ISP.0090.0004E] Manh.Utils.Ftp.Services:processFtpJob – Outer catch PO %function%
2010-04-23 09:37:47 EDT [FF.0001.0033C] Error processing service: [FPL.0002.0004] Server Error: com.wm.pkg.xslt.util.LocalizedTransformerException: [XSL.0002.9002] JAXP: Error during transformation - The markup in the document following the root element must be well-formed.; Line#: 2; Column#: 1803

It is actually a well formed XML but with more than one top level element. Once you receive this XML data in IS you can easily solve this by enclosing the XML inside a temporary top level element.

Just check the attached file, I ve done it by adding a tempHead, now it will open in a browser as well as get converted to IS doc by using built-in the services.
wmusers_sjalis.xml (3.58 KB)

sjalis,

I have written a small flow service that should help you with what you wish to implement.

Install this WMTest.zip and let me know if it helps.

Thanks,
Pallav
WMTest.zip (6.4 KB)

Well-formed XML documents can contain only one top level element. A good rule of thumb is to always make the source of bad XML do the fix. Of course that isn’t always practical but I often see bizarre code put into place to address poor XML from partners–and the partners were never notified/asked to fix what they were doing wrong.

Usually, if you’re working with XML and you find you need to/want to resort to using Java for some reason, then the XML is probably malformed.

Pallav,

It worked! Thanks a lot. One last question. Are java services generally considered heavy as opposed to using flow services in WM. Particularly in this context where I was doing a lot of string manipulations in my java service. How would i compare these two approaches in terms of performance.

sjalis

It is best to avoid java code where possible.
There is a separate thread dedicated to this discussion.
[url]wmusers.com