WSO2数据服务JSON问题 [英] WSO2 Data Services JSON issue

查看:129
本文介绍了WSO2数据服务JSON问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望您能帮助我使JSON REST WSO2数据服务正常工作. 我使用3.0.1版和示例数据服务.我怀疑我做错了... 我创建了绑定到productsSQL查询的资源产品". XML REST请求可以完美运行,但不能完美运行JSON:

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:

curl --request GET http://myserver.com:9763/services/samples/RDBMSSample.HTTPEndpoint/产品 -H内容类型:"application/json"

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

返回

> "Fault":{"faultcode":"","faultstring":"No JSON message received
> through HTTP GET or POST","detail":""}}

  1. 从源代码看,它似乎希望在请求url中有一些请求正文(这很奇怪),因此下一个查询是

  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内容类型:"application/json"

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. 但是,以下查询有效:

  1. The following query works, however:

curl --data'{"employeesbynumber":{"employeenumber":{"$":"1002"}}}'' http://myserver.com:9763/services/samples/RDBMSSample/-头 内容类型:"application/json" --header SOAPAction:"urn:employeesByNumber"

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

推荐答案

因此,在调试WSO2 DSS和Axis2代码几个小时后,有一个修复程序:

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

原因:WSO2仍在Axis 1.6.1上运行,这些轴在JSONOMBuilder和JSONDataSource(在1.6.2中已修复)中存在一些严重的错误.具体来说,它要求所有GET请求都具有输入参数,并且还包装在根元素中以及其他一些问题.事实是,在内部,AXIS2将JSON有效负载映射到SOAP主体,因此需要具有根元素.

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

解决方案,更多的解决方法:对于GET请求,传递的请求正文带有包装在根元素中的参数(当然还有URL编码).即使您没有参数-仍要传递它们. 因此,以下查询有效:

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"

希望WSO2的家伙很快就会更新到最新的Axis2 ...

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

这篇关于WSO2数据服务JSON问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆