Fiware Orion上下文代理-订阅

Fiware Orion上下文代理-订阅,fiware,fiware-orion,Fiware,Fiware Orion,我有个小问题。我正在订阅Orion Context Broker,我对回调的URL有一个奇怪的问题: 此代码来自教程: { "entities": [ { "type": "Room", "isPattern": "false", "id": "Room1" } ], "attributes": [ "temperature" ], "re

我有个小问题。我正在订阅Orion Context Broker,我对回调的URL有一个奇怪的问题: 此代码来自教程:

{
   "entities": [
        {
            "type": "Room",
            "isPattern": "false",
            "id": "Room1"
        }
    ],
    "attributes": [
        "temperature"
    ],
    "reference": "http://localhost:1028/accumulate",
    "duration": "P1M",
    "notifyConditions": [
        {
            "type": "ONTIMEINTERVAL",
            "condValues": [
                "PT10S"
            ]
        }
    ]
}
但是这个代码不起作用:

{
    "entities": [
        {
            "type": "Room",
            "isPattern": "false",
            "id": "Room1"
        }
    ],
    "attributes": [
        "temperature"
    ],
    "reference": "http://192.168.1.12:1028/accumulate?name=dupex",
    "duration": "P1M",
    "notifyConditions": [
        {
            "type": "ONTIMEINTERVAL",
            "condValues": [
                "PT10S"
            ]
        }
    ]
}
唯一的区别是参考字段: “参考”:“192.168.1.12:1028/累计?名称=dupex”

我得到:

{
    "subscribeError": {
        "errorCode": {
            "code": "400",
            "reasonPhrase": "Bad Request",
            "details": "Illegal value for JSON field"
        }
    }
}

任何建议请:)谢谢。

问题的根本原因是
=
是一个禁止字符,出于安全原因,在有效负载请求中不允许使用(请参阅关于它的内容)

有两种可能的解决办法:

  • 避免使用URL中的查询字符串作为subscribeContext中的参考,例如使用
    http://192.168.1.12:1028/accumulate/name/dupex
  • 编码以避免被禁止的字符(特别是
    =
    的代码是
    %3D
    ),并准备代码对其进行解码
  • 在案例2中,您可以在subscribeContext中使用以下引用:
    http://192.168.1.12:1028/accumulate?name%3Ddupex
    。然后,下面是一个将考虑编码并正确获取
    name
    参数的代码示例(使用Flask作为REST服务器框架以Python编写):


    有关详细信息,请参阅中的“订阅”和“自定义通知”部分。

    在回答中描述的解决方法中,我们已将此作为问题包含在Orion存储库中,以便思考并最终提供更好的解决方案:。欢迎对这个问题发表意见!Orion 1.2(将于2016年6月初发布)将启用该用例。有关它的信息已添加到答题帖中(请在“编辑”下查看)。
    from flask import Flask, request
    from urllib import unquote
    from urlparse import urlparse, parse_qs
    app = Flask(__name__)
    
    @app.route("/accumulate")
    def test():
        s = unquote(request.full_path) # /accumulate?name%3Dduplex -> /accumulate?name=duplex
        p = urlparse(s)                # extract the query part: '?name=duplex'
        d = parse_qs(p.query)          # stores the query part in a Python dictionary for easy access
        name= d['name'][0]             # name <- 'duplex'
        # Do whatever you need with the name...
        return ""
    
    if __name__ == "__main__":
        app.run()
    
    {
      ..
      "notification": {
        "httpCustom": {
          "url": "http://192.168.1.12:1028/accumulate",
          "qs": {
            "name": "dupex"
          }
        }
        ..
      }
      ..
    }