How to use HTTP JSON Receiever to receive the data with is by JSON format
-
Dear phildunlap
As the following screenshot, I have design a Data Source and Data Points
and I try to use Publisher to send some random value to test the above HTTP JSON Reveiever, But no data can collect, what wrong of my setup?
Kam
-
Hi Kam,
There is nothing wrong in your setup, the two do not currently work together.
Both the JSON receiver and the JSON sender were created in response to situations we or customers faced, not simply to add more ways for one Mango HTTP publisher to talk to a Mango HTTP receiver. The publisher will publish a JSON object of (although the deviceName - pointName portion is configurable in the publisher):
{ "deviceName - pointName": "value@timestamp" }
whereas the HTTP Json receiver was in response to a particular situation and was bolted on top of the regular HTTP Receiver. As such, it requires the json object to be in the value of a parameter, since the HTTP Receiver is parameter based. So, for a post, it'd have to be
param={"parameterName":"pointValue"}
for an alphanumeric point. The "param" that the JSON is set to doesn't matter and could be anything, but the JSON receiver can accept many, which is where the Device Identifer comes in. If JSON receiver points have a non-empty device identifier and device identifier key, then multiple points are resolved in the situation
param={"parameterName":123,"deviceIdentifierKey":"deviceIdentifier"}&otherParam={"parameterName":1234,"deviceIdentifierKey2":"deviceIdentifier2"}
However, if a point had an empty device identifier it would try to get values from all parameters (which isn't really a good idea, since you cannot have a timestamp in the JSON receiver currently. This is mainly intended to speed up the case where it is one large JSON object on a single parameter, so checking for a device identifier doesn't need to happen).
I noticed when writing this post that the help document for the HTTP JSON receiver is incorrectly linked, so I will fix that. There's not a lot there, but you can read the in-Mango help by opening the dialogue for the HTTP Json receiver point, then going to the related items section at the bottom.
Perhaps it seems strange that the JSON receiver does not receive from the JSON publisher, but there is already an HTTP protocol to transfer information between Mango instances, so it would also seem unlikely to be required.
-
Here is a simple sample HTTP message that can be passed to the receiver,
POST /httpds HTTP/1.1 Content-Type: application/x-www-form-urlencoded Connection: Keep-Alive Host: localhost Content-Length: 19 Accept: */* json={"test":false}
#!/bin/bash #Send previous POST to the server! nc serverIp serverPort < postMessage.txt
-
Dear phildunlap
-
Where can I found the in-Mango help by opening the dialogue for the HTTP Json receiver point?
-
Can you please help to make a sample data sources and data point to me that I can import to our system to test the result, It look too difficult about this article.
Thx
Kam -
-
It is the blue help question mark (?) on the data point's edit page, at the top of the data point edit section.
I would normally post JSON for a data source, but I am traveling at the moment, so I'll have to add that in later. It should be pretty easy though. For the sample message in my last post, the data type is Binary and the Parameter Name is
test
-
Hi Phil,
Thank you but I tried per your advice, result is not optimistic. Please assist.
Firstly, I created mango http receiver with data point, with most input as "key"
Secondly, I tried to run two http post as below,
first one, I put content type as application/json,
Second one, I put content type as what you recommend above, result get is unconsumed key
For these two tests, I can not get the data from data view as below.
Thanks,
Wilson -
Would you please help explain more about below, Thank you.
#!/bin/bash
#Send previous POST to the server!
nc serverIp serverPort < postMessage.txt -
Hi Wilson,
The nc command is just to send those characters to the server at its HTTP port. HTTP is message structuring built on TCP, so for simple messages it is easy enough to use nc (the "TCP/IP Swiss Army Knife") for immediate testing results where absolutely no other factors are in the problem.
-
There is undoubtably room to improve the HTTP JSON receiver. As I said, it was bolted onto the HTTP receiver because a client was faced with a situation where use of regex to identify points and values would have been impossible. I could conceive value in consuming the post body as one large JSON object (as the receiver outputs for type JSON) as well as having a more sensible relationship to the content-type. The demand simply hasn't existed before.
-
@phildunlap I just wanting your sample file, When will you finish your traveling ?
-
What sample file? The contents of "postMessage.txt" was the text in the higher part of the post.
-
After running the script "
nc localhost 8080 < postMessage.txt" , it have the error, attach the error.txt for reference : 0_1486449341741_error.txt -
Hi Kam,
Thanks for bringing that to our attention. i bet the point you are using doesn't have a data type of Binary. But, that shouldn't throw an NPE regardless. Your line numbers imply you're using Mango 2.5 ? It shouldn't matter for this data source, since it hasn't really changed in years.
I have run my test, again, and am still able to make it work. I have a binary data point with the parameterKey 'test' and I am passing in the following messages:
setFalse.txt:
POST /httpds HTTP/1.1 Accept: */* Content-Type: application/x-www-form-urlencoded Host: 127.0.0.1 Connection: Keep-Alive Content-Length: 19 json={"test":false}
setTrue.txt:
GET /httpds?json={"test":true} HTTP/1.1 Accept: */* Content-Type: application/json Host: 127.0.0.1 Connection: Keep-Alive
I am doing:
nc 127.0.0.1 80 < setFalse.txt nc 127.0.0.1 80 < setTrue.txt
-
try to change localhost to 127.0.0.1
I did that and it worked.
If you want localhost to work you need to change your hosts file like the picture below.
I hope it helps.