I'd like to return one of the following depending on the content type
specified on the request:
1. Plain XML
2. XML wrapped in a SOAP envelope
3. JSON
As mentioned by Sanjiva currently in the server side we use the
content-type of the request message to determine the output message
type provided that there is a MessageFormatter registered for  that
content-type..

Also there are couple of ways to override this..You can set a
parameter called "messageType" in the services.xml with the value set
to the contentType registered for the fomatter of your choice. As an
example if you set the "messageType" parameter as "application/xml" ,
then your service will response with plain XML even if it receives a
SOAP message.

Second method is to programmatically set the above as a property in
the messageContext from your service impl class..
eg:
msgContext.setProperty(Constants.Configuration.MESSAGE_TYPE,
"application/json");

http://localhost:8080/axis2/services/Version/getVersion

I get the following response:

<ns:getVersionResponse xmlns:ns="http://axisversion.sample/xsd";>
  <ns:return>Hello I am Axis2 version service , My version is
1.2-SNAPSHOT</ns:return>
</ns:getVersionResponse>

Good. When I change the content type in the header to text/javascript
(Content-Type: text/javascript) I get the following error (formatted for
readability here):
Theoretically it should go beyond this point and will return plain XML
as for the current behaviour of Axis2. May be the JSONOMBuilder is
expecting some kind of payload. Please log a Jira for this behaviour.

As I found out now Axis2 is currently sets the outgoing message type
as Application/XML for any "get" request(Not sure whether it's the
correct behaviour, you may log a Jira for this too)... You might need
to override this using either of the two methods I mentioned above..

As for SOAP, I'm not sure what exactly I have to do to get a SOAP
response. I tried setting the SOAPAction header (I read this somewhere)
but that didn't help.
It won't be possible dynamically due to the above hard coded logic...
But again you can try the above two methods......

Thanks,
Thilina
--
Thilina Gunarathne  -  http://www.wso2.com - http://thilinag.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to