Im working on a simple subscription on contextBroker, and I'm subscribing my node application.
After that it returns 200 status OK, and it insert the row in 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
Empty body. Then when I change the format in mongo to be "JSON" everything works fine. The body returns the data from contextBroker.
My question is, how to make contextBroker to insert default "JSON" in the format field.
UPDATE:
Version of contextBroker is 0.26.1
UPDATE
Here I tried with attributeFormat=object to make it insert "JSON" in the format field, but it's still "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. Note that in this case, the response is in XML so you are getting notifications in 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. In this situation, Orion choses XML (due to legacy reasons to mantain backward compatibility with old Orion versions that only support XML).
Thus, there are two possible solutions to this situation:
Accept: application/json
in the subscribe context request.?notifyFormat=json
to "force" notifications to be send in JSON (e.g. POST /v1/subscribeContext?notifyFormat=json
), no matter the encoding used for the response to the subscribe context operation.Side-note: ONTIMEINTERVAL subscriptions (the one shown in your screenshot) have been deprecated. Thus, you are encouraged to stop using them, using ONCHANGE instead.