2017-04-07 22 views
1

目前的「=」號是獵戶座中禁止使用的查詢字符串: http://fiware-orion.readthedocs.io/en/1.5.0/user/forbidden_characters/index.htmlFIWARE獵戶座:在認購有效載荷

但是,這可以防止進行了查詢字符串訂閱:

$ (curl broker.waziup.io/v1/subscribeContext -s -S --header 'Content-Type: application/json' \ 
--header 'Accept: application/json' --header 'Fiware-Service:waziup' --header 'Fiware-ServicePath:/TEST' -d @- | python -mjson.tool) <<EOF 
{ 
    "entities": [ 
     { 
      "type": "SensingDevice", 
      "isPattern": "false", 
      "id": "Sensor1" 
     } 
    ], 
    "attributes": [ 
     "temperature" 
    ], 
    "reference": "http://localhost/v1/sms/send?contact=0039&msg=Sensor1", 
    "duration": "P1M", 
    "notifyConditions": [ 
     { 
      "type": "ONCHANGE", 
      "condValues": [ 
       "temperature" 
      ] 
     } 
    ], 
    "throttling": "PT1S" 
} 
EOF 

結果:

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

查詢字符串用於傳遞參數到回調服務器(我沒有看到其他方法來做到這一點)。 任何方法?

回答

1

根據NGSIv2中的自定義通知,可以在通知URL中設置查詢參數。看看NGSIv2 specification中的「自定義通知」部分。

你正在做的會是這樣的訂閱:

POST /v2/subscriptions 
... 

{ 
    "subject": { 
    "entities": [ 
     { 
     "id": "Sensor1", 
     "type": "SensingDevice" 
     } 
    ], 
    "condition": { 
     "attrs": [ "temperature" ] 
    } 
    }, 
    "notification": { 
    "httpCustom": { 
     "url": "http://localhost/v1/sms/send", 
     "qs": { 
     "contact": "0039", 
     "msg": "Sensor1" 
     } 
    }, 
    "attrs": [ "temperature"] 
    }, 
    "expires": "2016-05-07T18:30:00.00Z", 
    "throttling": 1 
} 

注意,你甚至可以概括爲訂閱使用模板所有的傳感器,以下列方式:

POST /v2/subscriptions 
... 

{ 
    "subject": { 
    "entities": [ 
     { 
     "idPattern": "Sensor.*", 
     "type": "SensingDevice" 
     } 
    ], 
    "condition": { 
     "attrs": [ "temperature" ] 
    } 
    }, 
    "notification": { 
    "httpCustom": { 
     "url": "http://localhost/v1/sms/send", 
     "qs": { 
     "contact": "0039", 
     "msg": "${id}" 
     } 
    }, 
    "attrs": [ "temperature"] 
    }, 
    "expires": "2016-05-07T18:30:00.00Z", 
    "throttling": 1 
}