1

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>
    &lt;namePrefix&gt;Mr.&lt;/namePrefix&gt;    
    &lt;nameFirst&gt;Timothy&lt;/nameFirst&gt;    
    &lt;nameLast&gt;Jones&lt;/nameLast&gt;  &lt;nameMiddle&gt;D.&lt;/nameMiddle&gt;  
    &lt;nameSuffix/&gt;  &lt;nameDisplayInformal&gt;Timothy D. 
    Jones&lt;/nameDisplayInformal&gt;  &lt;nameDisplayFormal&gt;Mr. Timothy D. 
    Jones&lt;/nameDisplayFormal&gt;  &lt;nameSortedInformal&gt;Timothy, Jones 
    D.&lt;/nameSortedInformal&gt;  &lt;nameSortedFormal&gt;Timothy, Jones D. 
    Mr.&lt;/nameSortedFormal&gt;  &lt;username&gt;JONESTD&lt;/username&gt;  
    &lt;emailAddress&gt;JONESTD@xxxx.xx&lt;/emailAddress&gt;
   <xxx>...... </xxx>
   <xxx>...... </xxx>
   .......
   .......
   .......
</customer>

I see this &lt; and &gt; only in the person xml string I set in the "person" property. I tried several things(including StringEscapeUtils.unescapeHtml) to convert &lt; and &gt; into < and > (proper xml). But nothing worked for me. Could you please give me some idea on how I can fix this issue?

Devin Burke
  • 13,642
  • 12
  • 55
  • 82
Sams
  • 11
  • 2

1 Answers1

0

In order to achieve this, while calling(GET method) the Customer service I get the xml output from the "Person" resource and remove the and 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.

I believe you are saying that you have a Customer object with a String property to represent the XML contents? When you marshal this content you will see the addition of escaped characters.

I am developing RESTful web services in Java using Jersey, Tomcat and Toplink.

When you say you are using TopLink, are you oracle.toplink.* classes, or the org.eclipse.persistence.* classes. If you are using the latter (EclipseLink), you will be able to leverage EclipseLink JAXB (MOXy) to do what you want.

Representing XML as a String

Using MOXy with Jersey

Community
  • 1
  • 1
bdoughan
  • 147,609
  • 23
  • 300
  • 400