Lawrence Mandel wrote:
I've just picked up the latest Axis2 build (from 20070425) and am having trouble getting JSON and SOAP responses from the sample Version service. Really I think the problem is I just don't understand if Axis2 can do what I'd like it to do. The online documentation and googling for an answer (which revealed an interesting doc at WSO2) hasn't resulted in an answer.

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

I specified messageformatters and messagebuilders as follows:

<messageFormatters>
  <messageFormatter contentType="application/x-www-form-urlencoded"
                    class=
"org.apache.axis2.transport.http.XFormURLEncodedFormatter"/>
  <messageFormatter contentType="multipart/form-data"
                    class=
"org.apache.axis2.transport.http.MultipartFormDataFormatter"/>
  <messageFormatter contentType="application/xml"
                    class=
"org.apache.axis2.transport.http.ApplicationXMLFormatter"/>
  <messageFormatter contentType="text/javascript"
                    class="org.apache.axis2.json.JSONMessageFormatter"/>
</messageFormatters>

<messageBuilders>
  <messageBuilder contentType="application/xml"
                  class="org.apache.axis2.builder.ApplicationXMLBuilder"/>
  <messageBuilder contentType="application/x-www-form-urlencoded"
                  class="org.apache.axis2.builder.XFormURLEncodedBuilder"
/>
  <messageBuilder contentType="multipart/form-data"
                  class=
"org.apache.axis2.builder.MultipartFormDataBuilder"/>
  <messageBuilder contentType="text/javascript"
                  class="org.apache.axis2.json.JSONOMBuilder"/>
</messageBuilders>

The rest of my axis2.xml file has not been modified. When I make a request to
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):

I assume you also sent it JSON input in the payload right? If so please open an issue against Axis2 with a test case.

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. Suggestions? Pointers to docs? Have I configured Axis2 correctly? Is this type of configuration known to work?

To get a SOAP response you need to get a SOAP request! That means you need a message whose payload contains an s:Envelope element as well as the correct content type. I suggest you use a client library (e.g., Axis2 itself) to generate these messages.

It seems to me what you're looking for is a way to send SOAP in and get JSON out etc.? If so there must be some way for the server to figure out which format to respond in. The current approach is that it'll respond in whatever format the message came in. How do you propose the server figures out what format you expect to receive the response in? I think that needs to be indicated somewhere in the request .. maybe via HTTP content negotiation (Accept: header)?

Sanjiva.
--
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]

Reply via email to