File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes customize xml response in axis2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "customize xml response in axis2" Watch "customize xml response in axis2" New topic

customize xml response in axis2

Jeff Boucher

Joined: Aug 18, 2008
Posts: 14

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:return type="service.Simple">

and I'd like to have:

<ns:return type="service.Simple" name="name">

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.


Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
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

Joined: May 01, 2008
Posts: 66
You can also make use Web Service Request/Response Handlers.

Naresh Waswani
Lester Cabrera

Joined: Aug 24, 2009
Posts: 1
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;
I agree. Here's the link:
subject: customize xml response in axis2
It's not a secret anymore!