Thilina, it seems to me we should also support a more dynamic way to
select the response format.
Why not just support HTTP content negotiation? If the request has an
Accept: header with a specific content type then we try to send in that
type (subject to preference values etc. given in the Accept header). I
don't think its a risky thing in terms of interop because pretty much no
WS-* stacks put an Accept: header .. so the odds of an expected SOAP
response coming back as JSON or POX or whatever is not that high. We
should even be able to use this same approach to turn on binary
serialization instead of XML serialization.
That solution of course only works for HTTP but that's ok for a start I'd
say.
Thoughts?
Sanjiva.
Thilina Gunarathne wrote:
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
--
Sanjiva Weerawarana, Ph.D.
Founder & Director; Lanka Software Foundation; http://www.opensource.lk/
Founder, Chairman & CEO; WSO2, Inc.; http://www.wso2.com/
Director; Open Source Initiative; http://www.opensource.org/
Member; Apache Software Foundation; http://www.apache.org/
Visiting Lecturer; University of Moratuwa; http://www.cse.mrt.ac.lk/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]