0

When creating a SOAP message using Axis2/Axiom I need to preserve the carriage returns in the body element. If I escape the CR to 
 (which is what is supposed to be done) Axis2/Axiom escapes the "&" to &. If I do nothing Axis2/Axiom converts the CR to LF.

How do I get Axis2/Axiom to correctly escape the CR?

If that is not possible, how do I get Axis2/Axiom to ignore an already escaped sequence or perhaps even more simply, to leave a specific "&" alone?

I would prefer to be able to get Axis2/Axiom to escape the CR correctly to 

Brian Reinhold
  • 2,313
  • 3
  • 27
  • 46

2 Answers2

1

Preserving carriage returns (by replacing them with character references) should actually be the default in Axiom:

http://ws.apache.org/axiom/userguide/ch04.html#factory.properties

Maybe you are not using Woodstox as StAX implementation or there was a change between version 3 (which was the version used by Axiom at the time the documentation was written) and 4 of Woodstox (which is the version used by current Axiom releases).

Andreas Veithen
  • 8,868
  • 3
  • 25
  • 28
  • yes, that appears to be correct. The XMLOutputFactory is javax and not woodstox. The javax default is apparently different. I will have to figure out how to move to woodstox and see if that solves the problem. – Brian Reinhold Sep 26 '12 at 12:03
  • Attempted to configure using `XMLOutputFactory xmlOutputFactory = StAXUtils.getXMLOutputFactory(); xmlOutputFactory.setProperty(WstxOutputProperties.P_OUTPUT_ESCAPE_CR, true);` but I find that the object is immutable. – Brian Reinhold Sep 26 '12 at 14:11
  • It appears all I had to do was add the woodstox jars to my classpath and the proper escaping appeared. No other code changes were necessary. – Brian Reinhold Sep 26 '12 at 14:30
  • I removed the woodstox jars from the classpath and the CRs were once again changed to LFs. Interesting. Would have never guessed! – Brian Reinhold Sep 26 '12 at 14:37
0

The strings which you supply to Axis2 shouldn't already be escaped. Axis2 (or the XML layer) handles that for you. XML is supposed to canonicalize end-of-line characters in textual data; see XML Carriage return encoding.

The real problem may be that you're using a datatype intended for textual data, when you really want to pass binary data through it. Can you redefine the relevant element of the WSDL as a base64binary or another binary-preserving type?

Community
  • 1
  • 1
Kenster
  • 23,465
  • 21
  • 80
  • 106
  • Thanks for the help but unfortunately I cannot encode as base64. (I should add that this is a client.) The text data inside the body element must adhere to a format specified by a standard (its all printable ASCII except for the CR) and the service is not anticipating base64. The question really comes down to why isn't Axis2/Axiom escaping the CR to ` `. There must be a way to specify that but I do not know what it is. I am surprised its not done by default. – Brian Reinhold Sep 22 '12 at 12:29