WSO2 Data Services JSON issue

2019-07-17 02:26发布

问题:

I hope you can help me getting JSON REST WSO2 Data Service work. I use v 3.0.1 and sample data service. I suspect that I do smth wrong... I created a resource 'products' that is bound to productsSQL query. XML REST request work perfectly, but not JSON:

  1. curl --request GET http://myserver.com:9763/services/samples/RDBMSSample.HTTPEndpoint/products -H Content-Type:"application/json"

returns

> "Fault":{"faultcode":"","faultstring":"No JSON message received
> through HTTP GET or POST","detail":""}}
  1. From the source code looks like it expects to have some request body in request url (which is strange), so the next query is

    curl --request GET http://myserver.com:9763/services/samples/RDBMSSample.HTTPEndpoint/products?q=emptyquery -H Content-Type:"application/json"

This one hangs and on server after several minutes I get the following exception:

> Feb 24, 2013 8:08:13 PM
> org.apache.tomcat.util.net.NioEndpoint$SocketProcessor run SEVERE:
> java.lang.ThreadDeath     at java.lang.Thread.stop(Thread.java:776)   at
> org.wso2.carbon.tomcat.ext.valves.CarbonStuckThreadDetectionValve.handleStuckThread(CarbonStuckThreadDetectionValve.java:121)
>   at
> org.wso2.carbon.tomcat.ext.valves.CarbonStuckThreadDetectionValve.backgroundProcess(CarbonStuckThreadDetectionValve.java:175)
>   at
> org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1387)
>   at
> org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1566)
>   at
> org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1576)
>   at
> org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1555)
>   at java.lang.Thread.run(Thread.java:680)
  1. The following query works, however:

    curl --data '{"employeesbynumber":{"employeenumber":{"$":"1002"}}}' http://myserver.com:9763/services/samples/RDBMSSample/ --header Content-Type:"application/json" --header SOAPAction:"urn:employeesByNumber"

回答1:

So after several hours debugging WSO2 DSS and Axis2 code there is a fix:

Reason: WSO2 still runs on Axis 1.6.1 which had some critical bugs in JSONOMBuilder and JSONDataSource (which seem to have been fixed in 1.6.2). Specifically it required all GET requests to have input parameter and also wrapped in a root element + some other issues. The fact is that inside, AXIS2 maps JSON payload to SOAP body, so needs to have root element..

Solution More of a workaround: For GET requests pass request body with parameters wrapped in a root element (and of course url encoded). Even if you do not have parameters - pass them anyway. So the following queries work:

curl --request GET http://192.168.1.10:9763/services/samples/RDBMSSample.HTTPEndpoint/employees?q=%7B%22request%22%3A%7B%22employeeNumber%22%3A%221%22%7D%7D%20 -H Content-Type:"application/json"

And this one for query without parameter but passing dummy one anyway:

curl --request GET http://192.168.1.10:9763/ervices/samples/RDBMSSample.HTTPEndpoint/products?q=%7B%22request%22%3A%7B%22employeeNumber%22%3A%221%22%7D%7D%20 -H Content-Type:"application/json"

Hope WSO2 guys will update to latest Axis2 soon...



回答2:

I think the way you call REST cal from curl is wrong if you want to play with curl you can use the reference [1]. the correct message would be

curl -i -H "Accept: application/json" http://myserver.com:9763/services/samples/RDBMSSample.HTTPEndpoint/products  

Else there is a good Google chrome plugin "Advanced REST client" you can simply use it for invoke REST services.

[1]. http://blogs.plexibus.com/2009/01/15/rest-esting-with-curl/