JAVA - HTML Characters not converted in CDATA field of SOAP response



I'm writing a Java Web Service that will replace an existing one written in .NET, the client already exists and I can't change its logic in any case so I have to return exactly the same response of the previous Web Service. The response is a XML-string inside a CDATA field, like this



<Result><![CDATA[<?xml version="1.0" encoding="utf-8"?><Root><field1 name="f1"><field2 name="f2">VALUE</field2></field1></Root>]]></Result>


so my Java web method is something like this:



@WebMethod(operationName = "GetResult")
@WebResult(name = "GetProfile2Result")
public String getResult() {

String res = buildResponse();
return res;
}


I'm using SoapUI to test the service, and when I see the output line it seems to be ok (and identical to the response of the "old" service) but the client can't parse it. It I look at the raw response via SoapUI I notice that there are some characters converted in HTML special characters and some others not(expecially the '>' char). For example I see the previous response in this way:



<Result><![CDATA[<?xml version="1.0" encoding="utf-8"?>&lt;Root>&lt;field1 name="f1">&lt;field2 name="f2">VALUE&lt;/field2>&lt;/field1>&lt;/Root>]]></Result>


So I tried to build my XML string via Java putting '<' and '>' instead of '<' and '>' but the result is that the string is encoded as follows:



&amp;lt;VALUE&amp;gt;


Why this happens?


No comments:

Post a Comment