java - CDATA section in SOAP Request XML -


i using jax-ws service. following part of request class.

@xmlelement(name = "answers")  protected string answers; 

now, in actual soap request, answers need sent in xml cdata. there separate stub class answers. hence, marshalling object of class xml. surrounding in cdata tags shown below:

xmlstr = "<![cdata[" + xmlstr + "]]>";  

hence, request xml should this:

<s:envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:body>     <!-- other tags -->     <answers>         <![cdata[             <tagone></tagone>             <tagtwo></tagtwo>         ]]>     </answers> </s:body> </s:envelope> 

however, when request sent server, soaplogginghandler, looks this:

<s:envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:body>     <!-- other tags -->     <answers>         &lt;![cdata[             &lt;tagone>&lt;/tagone&gt;&#13;             &lt;tagtwo>&lt;/tagtwo&gt;&#13;         ]]&gt;&#13;     </answers> </s:body> </s:envelope> 

due escaping of characters, receiving response saying "invalid answers xml format". have 2 questions:

  1. is xmlstr = "" correct way create cdata xml bean? if not then, there standard way that?

  2. if want send cdata section in request without escaping, changes should make implementation?

let me know if else required.

i think situation here java object representation doesn't quite match you'd see in xml. , presume use jaxb jax-ws, can create adapter class element in bean xmljavatypeadapter annotation.

public class cdataadapter extends xmladapter<string, string> {    @override   public string marshal(string v) throws exception {     return "<![cdata[" + v + "]]>";   }    @override   public string unmarshal(string v) throws exception {     return v;   } } 

in bean:

@xmlelement(name = "answers") @xmljavatypeadapter(value=cdataadapter.class) protected string answers; 

for more details please read using jaxb 2.0's xmljavatypeadapter


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -