Hi Anas,

The messageFormatters and messageBuilders should be in the Axis2.xml and not
the services.xml. You can return the response as Json by setting the correct
MessageType on the outgoing messageContext.

Actually today I wrote a module that can do what you request. All you need
to do it add a query parameter called response with the value of the
contentType that you require as the response.

For e.g.
http://localhost:8080/axis2/services/version/getVersion?response=application/jsonwould
give you a JSON response.

I just added this module as a WSO2 commons project. You can check it out at
http://wso2.org/repos/wso2/trunk/commons/dynamic-response/

Just take a checkout and build it using maven clean install. That will
create wso2dynamic-response-SNAPSHOT.mar in the target dir. You can drop
this into your modules directory and engage it on any service you need.

Let us know what you think about it.

Thanks,
Keith.

On 10/9/07, Anas Mughal <[EMAIL PROTECTED]> wrote:
>
> I am unable to respond with pure JSON using a POJO service. Here is my
> POJO:
>
> public class AxisTest {
>     public String getVersion() throws Exception {
>                 return " { "customer" : { "name" : { "$" : "Jane Doe" } }
> }";
>     }
> }
>
>
> The response I get in the browser includes the wrapper:
>
> <
> ns:getVersionResponse xmlns:ns="http://axisversion.sample";>
>   <
> ns:return>{ "customer" : { "name" : "Jane Doe", "company" : "Acme 
> Enterprises"}</ns:return
> >
> </ns:getVersionResponse>
>
> Instead, I would like get back only:
>
> { "customer" : { "name" : "Jane Doe", "company" : "Acme Enterprises"}
>
>
>
> In the browser, I see the content-type showing up as :
> "application/xml".   I might be able to resolve this problem by setting the
> content type to "application/json". How do I set the content type on a POJO
> service?
>
> Do I need return XML and Axis2 will automatically convert it to JSON
> (based on the message formatter setting of JSONMessageFormatter)?
>
>
> Here is my services.xml:
>
> <service name="AxisTest3" scope="application">
>
>     <description>This service is to JSON in Axis.</description>
>
>     <parameter name="ServiceClass">sample.axisversion.AxisTest</parameter>
>
>     <messageReceivers>
>         <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only";
>                          class="
> org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver "/>
>         <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out";
>                          class="
> org.apache.axis2.rpc.receivers.RPCMessageReceiver "/>
>     </messageReceivers>
>
>          <messageFormatters>
>         <messageFormatter contentType="application/json" class="
> org.apache.axis2.json.JSONMessageFormatter"/>
>         </messageFormatters>
>
>         <messageBuilders>
>             <messageBuilder contentType=" application/json" class="
> org.apache.axis2.json.JSONOMBuilder"/>
>         </messageBuilders>
>
> </service>
>
>


-- 
Keith Chapman
WSO2 Inc.
Oxygen for Web Services Developers.
http://wso2.org/

Reply via email to