I have the following problem. I set the following properties for the marshaller:
marshaller.setProperty (Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty ("com.sun.xml.bind.characterEscapeHandler", new CharacterEscapeHandler () {
public void escape (char [] ch, int start, int length, boolean isAttVal, Writer out) throws IOException {
String s = new String (ch, start, length);
System.out.println ("Inside CharacterEscapeHandler ...");
out.write (StringEscapeUtils.escapeXml (StringEscapeUtils.unescapeXml (s)));
}
});
When I try to redirect an object to SOAPBody with the following code:
SOAPMessage message = MessageFactory.newInstance (). CreateMessage ();
marshaller.marshal (request, message.getSOAPBody ());
CharacterEscapeHandler.escape is not called, and characters are not escaped, but this code:
StringWriter writer = new StringWriter ();
marshaller.marshal (request, writer);
calls CharacterEscapeHandler.escape (), and all characters are escaped ... This is the usual behavior for JAXB. And how can I avoid characters before placing them inside a SOAP body?
Update:
Our system must interact with another system that expects text to be escaped. Example for a message sent by another system:
<env: Envelope xmlns: env = "http://www.w3.org/2003/05/soap-envelope">
<env: Body xmlns: ac = "http://www.ACORD.org/Standards/AcordMsgSvc/1">
<ac: CallRs xmlns: ac = "http://www.ACORD.org/Standards/AcordMsgSvc/1">
<ac: sender>
<ac:PartyId>urn:partyId</ac:PartyId>
<ac:PartyRoleCd/>
<ac:PartyName>PARTYNAME</ac:PartyName>
</ac:Sender>
<ac:Receiver>
<ac:PartyRoleCd>broker</ac:PartyRoleCd>
<ac:PartyName>�марант Българи� ООД</ac:PartyName>
</ac:Receiver>
<ac:Application>
<ac:ApplicationCd>applicationCd</ac:ApplicationCd>
<ac:SchemaVersion>schemaversion/</ac:SchemaVersion>
</ac:Application>
<ac:TimeStamp>2011-05-11T18:41:19</ac:TimeStamp>
<ac:MsgItem>
<ac:MsgId>30d63016-fa7d-4410-a19a-510e43674e70</ac:MsgId>
<ac:MsgTypeCd>Error</ac:MsgTypeCd>
<ac:MsgStatusCd>completed</ac:MsgStatusCd>
</ac:MsgItem>
<ac:RqItem>
<ac:MsgId>d8c2d9c4-3f1c-459f-abe1-0e9accbd176b</ac:MsgId>
<ac:MsgTypeCd>RegisterPolicyRq</ac:MsgTypeCd>
<ac:MsgStatusCd>completed</ac:MsgStatusCd>
</ac:RqItem>
<ac:WorkFolder>
<ac:MsgFile>
<ac:FileId>cid:28b8c9d1-9655-4727-bbb2-3107482e7f2e</ac:FileId>
<ac:FileFormatCd>text/xml</ac:FileFormatCd>
</ac:MsgFile>
</ac:WorkFolder>
</ac:CallRs>
</env:Body>
</env:Envelope>
, / .. ac: PartyName