Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

customize xml response in axis2

 
Jeff Boucher
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm hoping someone has experience with customizing the XML response from an axis2 web service. I need to convert an element into an attribute. Here's an example...

I currently have:

<ns:getSimpleResponse>
<ns:return type="service.Simple">
<ns:name>name</ns:name>
<ns:values>hello</ns:values>
<ns:values>world</ns:values>
</ns:return>
</ns:getSimpleResponse>

and I'd like to have:

<ns:getSimpleResponse>
<ns:return type="service.Simple" name="name">
<ns:values>hello</ns:values>
<ns:values>world</ns:values>
</ns:return>
</ns:getSimpleResponse>

In other words, I'd like to take one of the elements and add it as an attribute to the return type.

I'm not writing any xml myself, I'm just using Axis2's ability to return a POJO as an XML/SOAP response. So I'm just calling a function that returns an instance of a class like this:



Where the web service method just populates the fields and then returns an instance of Simple.

If you have any ideas or experience with this, please let me know.

Thanks!



 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
If Axis2 uses JAXB to serialize object data to XML then you can annotate your POJO with JAXB annotations to customize the mapping.
Of special interest to you is the javax.xml.bind.annotation.XmlAttribute annotation.
If Axis2 does not support JAXB data binding, then perhaps there is some similar option available in the supported data bindings?
Best wishes!
 
Waswani Naresh
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also make use Web Service Request/Response Handlers.
 
Lester Cabrera
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would like to ask how to make my web service method work. I am trying to return String output in XML format. But somehow the SOAP engine converts the "<" to HTML-encoded characters. As for the request, I'm able to make it work by enclosing my input XML string inside the CDATA tag.

public String doMethod(String request) {
String response = "";
...
... // compose XML doc
... // generate String from XML doc and assign to response
return response;
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic