Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Parsing XML to make SOAP call  RSS feed

 
Pushkal Mishra
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

I am parsing an XML file and making a SOAP call using Axis APIs:

Document document = builder.parse("portfolio.xml");
DOMSource domSource = new DOMSource(document);

MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();
SOAPPart sp = message.getSOAPPart();
sp.setContent(domSource);
SOAPEnvelope se = sp.getEnvelope();
System.out.println("envelope: " + se);

The above SOP prints (among other things):
<Service>
etsGateway </Service>
<Version>
5.0 </Version>
<UserID>
scam </UserID>
<ReturnType>
SOAP </ReturnType>

Basically, a new line is added before each tag value read from the xml file. If I parse the xml file using DOM and print out each node, each node prints fine (implying that no extra white space exists inadvertently in the xml file). Because of this extra space and newline added to each tag, the SOAP call fails (on server-side, the code must not have trimmed the tag field - otherwise it might have worked fine).

I am able to implement the same thing in perl just fine and thus I infer that DOMSource is somehow to blame. I was wondering if anyone has experienced this. Please advise.

Thanks,
Pushkal
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is very interesting - I have just been runing into what may be the same thing with DOMsource - it seems to be injecting a single 0x0D after the element start tag under certain circumstances, but I have not figured out what the circumstances are.
This was with a servlet under Tomcat 4.1.30 installation and JDK 4.1.2 - but I'm not sure which version of the DOMsource is used.
Bill
 
Pushkal Mishra
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Just an update on this -- I basically used alternate approaches to create the soap message:
1. Parse the read XML message node by node and create an envelope, header, body and action elements incrementally
2. Use SOAP::Lite APIs (I did not try this, but I theorize that this will circumvent the problem) - I basically used some other perl APIs to create the SOAP message and make the SOAP call, but soon found that SOAP::Lite does the same thing
3. Use Axis (http://ws.apache.org/axis/). I was able to use it successfully.

Thanks,
Pushkal
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!