I am developing RESTful web services in Java using Jersey, Tomcat and Toplink. One of my requirement is replacing a resource link(person) with actual xml data(returned by that person resource link) in the XML data that my "Customer" service returns. In order to achieve this, while calling(GET method) the Customer service I get the xml output from the "Person" resource and remove the <person>
and </person>
tags from this xml data(since my "Customer" service has the property "person" where I want to stick this xml data) and set this xml data in the "person" property of the "Customer" resource.
Here is my output: Output returned from Customer service:
<customer>
<person>http://localhost:8080/xxxx/resources/person/JONESTD</person>
<xxx>...... </xxx>
<xxx>...... </xxx>
......
......
......
</customer>
Output returned from Customer service when I use query string composite=person(to replace person resource url with actual data) while calling this service:
<customer>
<person><namePrefix>Mr.</namePrefix> <nameFirst>Timothy</nameFirst>
<nameLast>Jones</nameLast> <nameMiddle>D.</nameMiddle> <nameSuffix/>
<nameDisplayInformal>Timothy D. Jones</nameDisplayInformal> <nameDisplayFormal>Mr.
Timothy D. Jones</nameDisplayFormal> <nameSortedInformal>Jones, Timothy
D.</nameSortedInformal> <nameSortedFormal>Timothy, Jones D. Mr.</nameSortedFormal>
<username>JONESTD</username> <emailAddress>JONESTD@xxxx.xx</emailAddress> </person>
<xxx>...... </xxx>
<xxx>...... </xxx>
......
......
......
</customer>
As you see, the XML string I set in the person property of Customer resource is not properly indented. If I view "View Source" it shows this output like this:
<customer>
<namePrefix>Mr.</namePrefix>
<nameFirst>Timothy</nameFirst>
<nameLast>Jones</nameLast> <nameMiddle>D.</nameMiddle>
<nameSuffix/> <nameDisplayInformal>Timothy D.
Jones</nameDisplayInformal> <nameDisplayFormal>Mr. Timothy D.
Jones</nameDisplayFormal> <nameSortedInformal>Timothy, Jones
D.</nameSortedInformal> <nameSortedFormal>Timothy, Jones D.
Mr.</nameSortedFormal> <username>JONESTD</username>
<emailAddress>JONESTD@xxxx.xx</emailAddress>
<xxx>...... </xxx>
<xxx>...... </xxx>
.......
.......
.......
</customer>
I see this <
and >
only in the person xml string I set in the "person" property. I tried several things(including StringEscapeUtils.unescapeHtml) to convert <
and >
into <
and >
(proper xml). But nothing worked for me. Could you please give me some idea on how I can fix this issue?