Orion Context Broker, subscription format "JSON" - fiware

Im working on a simple subscription on contextBroker, and I'm subscribing my node application.
subscribeContext
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:
(Recommended) Include Accept: application/json in the subscribe context request.
Add ?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.

Related

What is "application/x-amz-json" and how is it different from "application/json"?

I've run into "application/x-amz-json-1.1" in making requests to AWS resources. Most recently, it became a problem that an API Gateway I was communicating with didn't like handling it (for whatever reason). This got me wondering what the benefit to using application/x-amz-json-1.1 instead of application/json for my requests is. And to my disappointment, AWS doesn't seem to have any documentation on this odd content type.
So I turn to SO: what is "application/x-amz-json" and how is it different from "application/json"?
Amazon does not specifically document what application/x-amz-json Content-Type is for, however there are protocol documentations on Smithy (an open source language for defining services and SDKs published by AWS):
AWS JSON 1.1 protocol
AWS JSON 1.0 protocol
Considering the question relates to the difference when used as Content-Type1 header to make requests, I think we can tell the difference is:
application/json is to request/receive JSON data without anything more specific
application/x-amz-json-1.1 (or other version) is also to request/receive JSON data and expect additional behaviors described in the docs above. (i.e. tell the server/client this is JSON plus additional elements)
I think application/x-amz-json can be thought as a sort of extension or a more specific way of doing application/json requests.
it became a problem that an API Gateway I was communicating with didn't like handling it (for whatever reason)
In the specific case of making PATCH, PUT and POST requests to AWS Amazon API Gateway, specifying Content-Type header application/x-amz-json-1.1 or other version seems to be required. As per related docs:
Content-Type (Conditional)
Specifies JSON and the version, for example, Content-Type: application/x-amz-json-1.0.
Condition: Required for PATCH, PUT and POST requests.
Maybe the server understands application/json as basic JSON but requires application/x-amz-json-1.1 to perform specific requests.
1 Content-Tye header being used to tell the server/client how to process our request

Message does not contain valid HTTP context information, Need return context info

I am using IBM integration toolkit
I have an application with two flows; the request flow has a json request message using http request node then the message is thrown to another flow (in another application representing a stub)through a MQ Input, compute node then MQ reply.
It then throws the message to the response flow in my application through MQ Input
I need to output the message in a json form through http reply node but in the flow it runs an exception "Message does not contain valid HTTP context information, Need return context info"
if anyone have a clue for this error and how to solve it
Thanks in advance
The problem is that your HTTP response flow does not know which request it has to respond.
In case you really need your request and response to be implemented as different flows, you have to store identifier of incoming HTTP or SOAP request somewhere, for example as a message in some dedicated queue.
In your request flow you can find identifier of request in
InputLocalEnvironment.Destination.HTTP.RequestIdentifier
or
InputLocalEnvironment.Destination.SOAP.RequestIdentifier
depending on the type of your input node.
Then, your response flow should read a message written by request flow to find a value of RequestIdentifier.
This value should be set into the LocalEnvironment of response message assembly:
OutputLocalEnvironment.Destination.HTTP.Reply.ReplyIdentifier
or
OutputLocalEnvironment.Destination.SOAP.Reply.ReplyIdentifier
Here is IBM doc: https://www.ibm.com/support/knowledgecenter/SSMKHH_9.0.0/com.ibm.etools.mft.doc/ac20450_.htm#ac20450___le
When the HTTPInput node receives an input request message, it sets the local environment field Destination.HTTP.RequestIdentifier to a unique value that identifies the Web service client that sent the request. You can refer to this value, and you can save it to another location if appropriate.
For example, if you design a pair of message flows that interact with
an existing WebSphere MQ application (as described in Broker calls
existing Web service), you can save the identifier value in the
request flow, and restore it in the reply flow, to ensure that the
correct client receives the reply. If you use this technique, you must
not change the data, and you must retain the data as a BLOB.
The HTTPReply node extracts the identifier value from the local
environment tree and sets up the reply so that it is sent to the
specific client. However, if you are using an HTTPReply node in a flow
that does not have an HTTPInput node, and this field has been deleted
or set incorrectly, message BIP3143S is issued.

Subscription to Cygnus in case of Orion context Broker multitenant not working

I tested the basic subscription mechanism of Orion setting an instance of Cygnus as a reference and it works well: once Orion receives an updateContext of my entity, it fires a notification to Cygnus that persists the data to the defauld mySQL db.
But if I add the following headers to the subscription:
fiware-service: sat
Fiware-ServicePath: /proto1
in order to save the data in another mySQL db, Orion accepts the subscription but does not fire any notification to Cygnus.
I tried to add the same headers to the updateContext REST call without success.
Any idea?
PS:
Orion version 0.22
Cygnus version 0.8
I found out the problem: headers have to be inserted also in the registration of the entity (*).
So, the correct sequence of operations is:
1) First, register your entity with a POST /NGSI10/updateContext call specifying "APPEND" updateAction in payload and including "fiware-service" and "fiware-servicepath" headers.
2) Make a subscription (/ngsi10/subscribeContext) to Orion including exactly the same headers above
3) Update your entity including the headers above
(*)Since I was using Data Handling GE as NGSI source and Orion as an event sink, updates to my entities were fired directly by Data Handling GE under certain conditions set by an esper rule/statement. It seems that Data Handling GE does not add the headers when it performs updates to event sinks.

Is there any action I could do with POST, but not with GET?

I know differences and advantages of each command, my question is could I replace POST requests with GET everywhere? And which these commands calls by default while sending request from html form?
could I replace POST requests with GET everywhere
No (and it would be a terrible idea to try).
Things that a form can do with POST that you can't do with GET include:
Sending lots of data
Sending files
There are other things that would simply be stupid to do with GET.
From http://www.w3.org/TR/html5/forms.html#attr-fs-method :
The method and formmethod content attributes are enumerated attributes
with the following keywords and states:
The keyword get, mapping to the state GET, indicating the HTTP GET
method. The keyword post, mapping to the state POST, indicating the
HTTP POST method. The invalid value default for these attributes is
the GET state. (There is no missing value default.)
When using GET to transfer data from the client to the server, the data is added to the URL, there is not BODY of the request. There is usually a limit on how long a URL can be, in the old days this was 1024 characters but that really depends on the server software and server middleware and even the browser.
This means if you want to transfer loads or data or upload a file to the server, you can not do it with GET.

How to disable content negotiation and always return JSON from WCF data service?

Let's say I have a northwind database and I use ADO.NET Entity Data Model which I automatically generate from the tables in database. Then I add a new WCF data service that inherits from DataService. When I start the web application, that runs the service I can request data like this:
http://machine/Northwind.svc/Orders
This will return all orders from order table in atom/xml format. The problem is I do not want XML. I want JSON. I think I tried all kinds of settings (web.config) and attributes in my application, but I still get XML. No matter what. I can only get JSON, when I use fiddler and change the request header to accept JSON.
I do not like the concept of content negotiation. I want always to return data in JSON format. How can I achieve that?
Keep in mind that I did not create any model objects, they are automatically created based on database tables and relationships.
Well - content negotiation comes with HTTP. In any case, you could intercept the incoming request and add/overwrite the Accept header to always specify the JSON. There's a sample how to support JSONP which uses a similar trick, I think you should be able to modify it to always return JSON as well. http://archive.msdn.microsoft.com/DataServicesJSONP.
The behavior you criticize is defined by specification of OData protocol. OData defaults to Atom and client can control media type of the representation either by Accept HTTP header or by $format parameter in query string (but I'm not sure if WCF Data services already support this).