Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SOAPMessage.writeTo() - No line breaks

 
Eddy McGregor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

In the SAAJ API there is the SOAPMessage.writeTo(java.io.OutputStream). This writes out the XML of the SOAP message, BUT with NO line breaks.

Does anyone know of / have a convenient method WHICH INCLUDES line braeks
and indents - so you see the XML in it's normal form ??

Cheers Eddy
 
Eddy McGregor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forgot to add
Or if there is some configuration that can be done ....

Cheers Eddy
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could capture the OutputStream, and run it through an XML pretty-printer, such as the ones that are part of Xerces or XOM.
 
Eddy McGregor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks Ulf, I'll check that out, Eddy
 
Glittery Lally
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, having the same problem.
Is there any standard solution now for this (noticed the topic is from 2005...)?
I need to save the content of the SoapMessage simply as String, not some other fancy format.

But it has to match EXACTLY the content of the soap response (also indents and line breaks)
because it contains a digital signature and the validation of the signed document fails if some parts are edited


Thanks in advance for any help!!! It's kind of urgent

Laura

 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Glittery Lally wrote:But it has to match EXACTLY the content of the soap response (also indents and line breaks)
because it contains a digital signature and the validation of the signed document fails if some parts are edited

Before the calculation of any digital signature of XML data, the data must be canonicalized, that is the XML data must be transformed to a standardized form.
References:
http://java.sun.com/developer/technicalArticles/xml/dig_signatures/
http://www.w3.org/TR/xml-c14n

Regarding your question:
You can use a XSLT transform to write XML to a file, below follows an example:

For more examples, see page 306 and forward in this document:
http://www.slideshare.net/krizsan/scdjws-5-study-notes-3085287
Best wishes!
 
Glittery Lally
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi thanks for your prompt answer
The problem is not how to write the stuff in an xml file
the problem is how to take the content of a SOAPMessage object and put it into a string
when I do soapMessage.writeTo(myByteArrayOutputStream)
the byteArrayOutputStream doesn't contain the same white spaces and line breaks as the original one.
I'm gonna read the documents about the canonicalization you sent me now, thanks

 
R Srini
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Ivan, Thank you for that very helpful code example.

@Glittery Lally: After some searching based on Ivan's example, I found another link that may have exactly what you need: SOAP message handler for logging inbound SOAP results. I just tried it and it worked fine for me. Its the same as Ivan's example, except that it reads the XML from the soap message instead of from a file. Hope that helps.
 
Glittery Lally
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@R Srini: Thanks a lot for your message and your time.
I tried your code and it works but unfortunately I have the same problem.
Some line breaks are lost
So I have to try another solution.
 
Yogesh Gandhi
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used : http://javakafunda.blogspot.in/2012/04/how-to-format-xml-string-in-java.html

and it worked for me...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic