I’m using IS 4.6… trying to develop some code in a java service to read an xml file and capture it as Values… here’s the sample code:
XMLCoder txfilexml = new XMLCoder();
FileInputStream txfile = new FileInputStream(“D:\B2B\Data\TXStatus.xml”);
Values txvalues = txfilexml.decode(txfile);
For some reason I’m getting an null pointer exception at the “Values” line…
Any idea why?.. can anyone provide working sample code… just a simple conversion of an xml file to Values using java and the com.wm.util.coder.XMLCoder provided by WebMethods…
The xml file you using to decode has to be an encoded file (ie. not a normal xml file but a webmethods encoded XML file - you’ll see IData elements in the xml). You actually have to ENCODE (not decode) the original xml file you have.
You can use the built-in flow service wm.record:recordToXMLValues rather than a java service. It uses XMLCoder under the hood (we tried to decode the file that was encoded using this flow service using the IDataXMLCoder and it didn’t work).
Ken I think this is what you looking for this a section from one of my working java services in IS4.6 to read XML doc in XMLCoder. I think your problem is you need ObjectInputStream instead of FileStream.
Values jms_config = null;
Values val = null;
XMLCoder coder = null;
FileOutputStream ostream = null;
ObjectOutputStream p = null;
coder = new XMLCoder();
FileInputStream istream = new FileInputStream(config_file);
ObjectInputStream in_stream = new ObjectInputStream(istream);
// Get current configuration
jms_config = coder.decode(in_stream);
I had the same problem, but then I chose the IDataXMLCoder instead of XMLCoder and my problem was solved.
you can use the pub.file:getFile service to read a file and it can be load as bytes or stream,choose what ever.Then map the output body/bytes to bytesToString service and nextstep will be stringToDocument flow.
Note:The file should be placed in the webmethods home directory then only getFile service will work.