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

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

问题描述

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

  1. <块引用>

    curl --request 获取http://myserver.com:9763/services/samples/RDBMSSample.HTTPEndpoint/产品-H Content-Type:"application/json"

返回

<代码>>"Fault":{"faultcode":"","faultstring":"没有收到 JSON 消息>通过 HTTP GET 或 POST","detail":""}}

  1. 从源代码看来,它期望在请求 url 中有一些请求正文(这很奇怪),所以下一个查询是

    <块引用>

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

几分钟后,这个挂起并在服务器上我得到以下异常:

<代码>>2013 年 2 月 24 日晚上 8:08:13>org.apache.tomcat.util.net.NioEndpoint$SocketProcessor 运行严重:>java.lang.ThreadDeath 在 java.lang.Thread.stop(Thread.java:776) 在>org.wso2.carbon.tomcat.ext.valves.CarbonStuckThreadDetectionValve.handleStuckThread(CarbonStuckThreadDetectionValve.java:121)>在>org.wso2.carbon.tomcat.ext.valves.CarbonStuckThreadDetectionValve.backgroundProcess(CarbonStuckThreadDetectionValve.java:175)>在>org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1387)>在>org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1566)>在>org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1576)>在>org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1555)>在 java.lang.Thread.run(Thread.java:680)

  1. 但是,以下查询有效:

    <块引用>

    curl --data '{"employeesbynumber":{"employeenumber":{"$":"1002"}}}'http://myserver.com:9763/services/samples/RDBMSSample/ --标题内容类型:应用程序/json"--headerSOAPAction:"urn:employeesByNumber"

解决方案

所以在调试 WSO2 DSS 和 Axis2 代码几个小时后,有一个修复:

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

解决方案 更多解决方法:对于 GET 请求,传递请求正文,其参数包含在根元素中(当然还有 url 编码).即使您没有参数 - 无论如何都要传递它们.所以以下查询有效:

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 内容类型:应用程序/json"

这个用于不带参数的查询,但无论如何传递一个虚拟的:

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 内容类型:应用程序/json"

希望 WSO2 的人能尽快更新到最新的 Axis2...

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"

解决方案

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

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

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