Hi Sanjiva,

Thanks for the response. 

>It seems to me what you're looking for is a way to send SOAP in and get 
JSON out etc.? 

Actually, at this point I just want to understand the requirements to get 
the different return types. Can I have a service with an input that 
contains no payload (simply a GET on a URL) that somehow distinguishes the 
content type (through the Content-type or Accept header information) and 
returns XML, XML wrapped in SOAP, or JSON as requested by the client? Does 
my message need to contain a payload? 

For example, if I send the following request to Axis2,

http://localhost:8080/axis2/Services/People/LawrenceMandel

how can I indicate the content type I want to receive in response to my 
query? Does this even make sense in the context of Axis2?

Thanks,

Lawrence 




Sanjiva Weerawarana <[EMAIL PROTECTED]> 
04/30/2007 08:18 PM
Please respond to
axis-user@ws.apache.org


To
axis-user@ws.apache.org
cc

Subject
Re: [Axis2] Trouble getting JSON response






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]




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

Reply via email to