• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

altering the xml output for axis2 soap response

 
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'd like to use Axis2 to provide a web service, but it would help if I could customize the kind of SOAP response. I really like the ability to deploy POJOs without a lot of configuration, so I'm hoping to use the standard output as much as possible... but, suppose I have an output like this...

<ns:getSampleObjectsResponse xmlns:ns="http://quicktest">
<ns:return xmlns:ax23="http://quicktest/xsd" type="quicktest.SampleCustomReturnType">
<ax23:name>customreturntype</ax23:name>
</ns:return>
</ns:getSampleObjectsResponse>

(this is just a very simple object called SampleCustomReturnType that holds a string to illustrate...) - and the xml is what axis2 provides when the method is called through the URL via

http://localhost:8080/axis2/services/SampleService/getSampleObject

suppose I'd like to alter the format of this xml response, to something like:

<getSampleObjectsResponse xmlns:ns="http://quicktest">
<return xmlns:ax23="http://quicktest/xsd" type="quicktest.SampleCustomReturnType">
<name>customreturntype<name>
<return>
<getSampleObjectsResponse>

ie., just getting rid of some of the namespace/tags that axis2 puts in there... can I edit this in the wsdl? Almost all of the tutorials/articles I've read are about how to use RPC as a client and don't actually get into the XML side of it.

Thanks!
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am also facing a similar situation. Anybody got any idea.....
I need to remove the empty tags that are coming in the response, even if not
set in the server side. I want to remove the empty tags from the response coming
from the axis2 deployed service as .aar

The same is working fine using JBoss4.2.2 deployment where the empty tags are automatically
removed while sending back the response to client. I verified the empty tags in the etheral logs as well
as through soap UI.

sample response with empty tags...

-----------------------------------------------------------------------------------
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<ns:createProfileResponse xmlns:ns="http://example">
<ns:return xmlns:ax230="http://example/xsd" type="example.Response">
<ax230:desc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<ax230:respCode>0000</ax230:respCode>
<ax230:respStr>Your name - hello, Age- 1</ax230:respStr>
<ax230:tokenId xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</ns:return>
</ns:createProfileResponse>
</soapenv:Body>
</soapenv:Envelope>
-----------------------------------------------------------------------------------

The last tag (attribute) is empty tag which I don't want in soap response at all. This is something to
do with backward compatibility. If the older client does not know of a newly added attribute/tag in
the new version, it will fail while parsing the response. This is not an issue with both the server and clients
as java but will be an issue if the client is non java and will fail.

what I want is the following without the empty tag...

-----------------------------------------------------------------------------------
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<ns:createProfileResponse xmlns:ns="http://example">
<ns:return xmlns:ax230="http://example/xsd" type="example.Response">
<ax230:desc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<ax230:respCode>0000</ax230:respCode>
<ax230:respStr>Your name - hello, Age- 1</ax230:respStr>
</ns:return>
</ns:createProfileResponse>
</soapenv:Body>
</soapenv:Envelope>
-----------------------------------------------------------------------------------


Ideally spaking if any empty tag is there it should be removed by default which works fine if
I deploy the service in JBoss. But is not if I deploy it on Axis2 + Tomcat environment.

Thanks in advance...
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Upananda Singha wrote:This is something to do with backward compatibility. If the older client does not know of a newly added attribute/tag in the new version, it will fail while parsing the response.



One possible solution is to create and deploy a serverside Axis2 outFlow handler that specifically looks for these "new" elements in the SOAP body and removes them if they are empty.
Writing Your Own Axis2 Module
Axis2 Execution Framework
 
Upananda Singha
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peer,

Thanks for your quick reply.
Yeah thats possible to remove the empty tags / attributes using some outflow handler.
But as a general assumption introducing another layer of xml parsing and manipulating using a handler
might slow down the total request - response cycle if I am not wrong. This would be critical to any high
load Application.

Anyway I will try this if it can be done without much overhead to the processing...
I just wonder how it's handled in JBoss4.2.2 (which provides ws2.0 and it's on top of Axis).
So what I felt is Axis2 should have that feature built in to it as it's the latest version Axis1.4.1.

Thanks
Upananda
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Upananda Singha wrote:But as a general assumption introducing another layer of xml parsing and manipulating using a handler
might slow down the total request - response cycle if I am not wrong. This would be critical to any high
load Application.



Yes, however the impact may not be a great as you make it out to be. By the time the handler gets the message it still is in its tree/object form, not a bytestream. So you just have to walk the tree looking for the nodes that you are interested in and remove them if necessary. While the code may be tedious it is most likely pretty fast too. So there is no actual "addtional layer of XML parsing".

Upananda Singha wrote:I just wonder how it's handled in JBoss4.2.2 (which provides ws2.0 and it's on top of Axis).
So what I felt is Axis2 should have that feature built in to it as it's the latest version Axis1.4.1.



According to this Axis2 technology is only used for web service client stubs. The actual web services use JAXB and JAX-WS style-annotations - Axis2 uses Axiom with data binding options of ADB, XmlBeans or JiBX.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peer,

A basic question on axis2...

Is it possible to drop off few contents from the body after receiving it in the Outflow Handler. I am not able to override the faults which is returned by the service, in the Outflow handler..i.e remove some elements in the body but I am able to append contents to the body..

Basically I want to do the following

1. I am able to send SOAP response to a request successfully by using a simpleINOUT message receiver. But when it comes to sending SOAP fault as a response I am able to do it ,but i am not able to add custom headers to the outgoing fault message.

2. I tried to add the header in the OUTFAULT FLOW and am able to do it but my custom headers value depends on the values from the request headers i.e take some values from the input headers (eg.sessionID) and include it in the SOAP response headers.

Kindly share your views of doing it..

Cheers,
Raghav.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic