简体   繁体   English

猎户座上下文代理,订阅格式“JSON”

[英]Orion Context Broker, subscription format “JSON”

Im working on a simple subscription on contextBroker, and I'm subscribing my node application. 我在contextBroker上做一个简单的订阅,我正在订阅我的节点应用程序。

subscribeContext subscribeContext

After that it returns 200 status OK, and it insert the row in mongo, orion db. 之后它返回200状态OK,并在mongo,orion db中插入行。

The problem is the field in collection csubs format is "XML", and on the my node application when I log the body that contextBroker sends it logs this logs from node that is subscribed 问题是集合csubs格式中的字段是“XML”,当我记录contextBroker发送它的主体时,在我的节点应用程序上,它从订阅的节点记录此日志

Empty body. 空身。 Then when I change the format in mongo to be "JSON" everything works fine. 然后,当我将mongo中的格式更改为“JSON”时,一切正常。 The body returns the data from contextBroker. 正文从contextBroker返回数据。

My question is, how to make contextBroker to insert default "JSON" in the format field. 我的问题是,如何使contextBroker在格式字段中插入默认的“JSON”。

UPDATE: 更新:

Version of contextBroker is 0.26.1 contextBroker的版本是0.26.1

UPDATE UPDATE

订阅上下文,请求+正文和响应

Here I tried with attributeFormat=object to make it insert "JSON" in the format field, but it's still "XML" 在这里,我尝试使用attributeFormat = object使其在格式字段中插入“JSON”,但它仍然是“XML”

Orion Context Broker choses the encoding of notifications based on the encoding used for the response of the subscribe context operation associated to such notifications. Orion Context Broker基于用于与这些通知相关联的订阅上下文操作的响应的编码来选择通知的编码。 Note that in this case, the response is in XML so you are getting notifications in XML. 请注意,在这种情况下,响应是XML格式,因此您将收到XML格式的通知。

I guess that you are getting XML in the response because Accept HTTP header is not being used in the subscribe context request, which implicitely is Acccept: */* , meaning that the client has not preference regarding encoding. 我猜你在响应中得到了XML,因为订阅上下文请求中没有使用Accept HTTP头,这隐含地是Acccept: */* ,这意味着客户端没有关于编码的偏好。 In this situation, Orion choses XML (due to legacy reasons to mantain backward compatibility with old Orion versions that only support XML). 在这种情况下,Orion选择了XML(由于遗留原因保留了与仅支持XML的旧Orion版本的向后兼容性)。

Thus, there are two possible solutions to this situation: 因此,这种情况有两种可能的解决方案:

  • (Recommended) Include Accept: application/json in the subscribe context request. (推荐)在订阅上下文请求中包含Accept: application/json
  • Add ?notifyFormat=json to "force" notifications to be send in JSON (eg POST /v1/subscribeContext?notifyFormat=json ), no matter the encoding used for the response to the subscribe context operation. 添加?notifyFormat=json以“强制”通知以JSON POST /v1/subscribeContext?notifyFormat=json发送(例如POST /v1/subscribeContext?notifyFormat=json ),无论用于响应订阅上下文操作的编码如何。

Side-note : ONTIMEINTERVAL subscriptions (the one shown in your screenshot) have been deprecated . 附注 :ONTIMEINTERVAL订阅(屏幕截图中显示的订阅) 已弃用 Thus, you are encouraged to stop using them, using ONCHANGE instead. 因此,建议您使用ONCHANGE停止使用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM