jQuery in Action, 2nd edition*
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
JavaRanch » Java Forums » Java » Web Services
Bookmark "customize xml response in axis2" Watch "customize xml response in axis2" New topic
Author

customize xml response in axis2

Jeff Boucher
Greenhorn

Joined: Aug 18, 2008
Posts: 14
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

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

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


Naresh Waswani
Lester Cabrera
Greenhorn

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: http://aspose.com/file-tools
 
subject: customize xml response in axis2