JSON objects from response
It would speed development up dramatically on the client side if we were able to retrieve JSON objects out of the response from the Web Service calls rather than just XML. I know with the WSRequest object we can get at the XML in multiple formats, is there a way for us to retrieve the response as JS objects already?
Thanks!
- Login or register to post comments
- Printer friendly version
- 998 reads











Can be done using a Axis2 module thats already available.
No, WSRewuest does not have this feature at the moment. If you want to get a JSON response from a service deployed in the Mashup Server (Or even WSO2 WSAS or Axis2) you can do the following.
1. Download the Dynamic-Response module from http://dist.wso2.org/maven2/org/wso2/dynamicresponse/wso2dynamic-response/SNAPSHOT/wso2dynamic-response-20071128.123918-50.mar
2. Drop it into the modules folder (Alternatively goto https://localhost:7443/wsasadmin and upload the module) of the Mashup Server
3. Go to https://localhost:7443/wsasadmin (You will have to sign in using the same username password used for the mashup server), Go to the modules section and engage the module DynamicResponseHandler to the system globally (If you need to engage it for us service you can do so by going into the services section)
Send your request with the following query parameter, response=json.
e.g you can try the getVersion operation of the version service as follows,
http://localhost:7762/services/version/gerVersion?response=json
This would give you a json response.
Hope this would solve your requirement. Please feel free to make suggetions that you may like us to incoperate.
Thanks,
Keith.
Use of module with standard Tomcat?
Hi Keith,
I'd be interested in a way to use this module with a standalone Tomcat/WSF/Spring configuration. Do you know if that would work?
I downloaded the module and can see it listed in Tomcat's startup log, but it doesn't seem to work for my WS since it still always returns XML-Output in the browser.
I edited the axis-config so far, adding the module to the global modules section (next to addressing) and adding entries for JSONMessageFormatter and -Builder.
Thank you in advance,
Jan
Yes it should work
Yes it should work. Make sure you append ?response=json to the request. for e.g
http://localhost:7762/services/version/gerVersion?response=json
Thanks,
Keith.
yes, but...
Alright, here's what I entered into my browser:
http://localhost:8080/poc-rest-wso2-web/services/hello/sayHelloWorld?name=Dummy&response=json
My Tomcat is telling me:
[...]
2008-04-15 12:45:39,120 INFO org.apache.axis2.deployment.ModuleDeployer - Deploying module: DynamicResponseHandler-109 - file:/W:/01_workspace/poc-rest/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/poc-rest-wso2-web/WEB-INF/lib/wso2dynamic-response-20080124.210931-109.mar
[...]
And this is what my browser delivers:
--MIMEBoundaryurn_uuid_DDD28CF9A2C69D7D291208262525007
Content-Type: application/xop+xml; charset=UTF-8; type="application/soap+xml"
Content-Transfer-Encoding: binary
Content-ID: <0.urn:uuid:DDD28CF9A2C69D7D291208262525008@apache.org>
<ns:sayHelloWorldResponse xmlns:ns="http://service.wso2.sample.rest.poc.xyz.com"><ns:return>Dummy says: Hello World!</ns:return></ns:sayHelloWorldResponse>
--MIMEBoundaryurn_uuid_DDD28CF9A2C69D7D291208262525007--
Thanks for your help