• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

customize xml response in axis2

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!



 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also make use Web Service Request/Response Handlers.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic