FIWARE / context.Orion-LD

Context Broker and CEF building block for context data management which supports both the NGSI-LD and the NGSI-v2 APIs
https://www.etsi.org/deliver/etsi_gs/CIM/001_099/009/01.06.01_60/gs_CIM009v010601p.pdf
GNU Affero General Public License v3.0
50 stars 43 forks source link

entities PATCH with Link Header not processed correctly. #372

Closed jason-fox closed 4 years ago

jason-fox commented 4 years ago

I create a shelf Unit:

 curl -X POST \
  'http://localhost:1026/ngsi-ld/v1/entities/' \
  -H 'Content-Type: application/ld+json' \
  -d '{
    "id": "urn:ngsi-ld:Shelf:unit001",
    "type": "Shelf",
    "location": {
      "type": "GeoProperty",
      "value": {"type": "Point", "coordinates": [13.3986112,52.554699]}
    },
    "maxCapacity": {"type": "Property", "value": 50},
    "numberOfItems": {"type": "Property", "value": 50},
    "name": {"type": "Property", "value": "Corner Unit"},
    "stocks": {
      "type": "Relationship", "object": "urn:ngsi-ld:Product:001"
    },
    "locatedIn" : {
      "type": "Relationship", "object": "urn:ngsi-ld:Building:store001",
      "requestedBy": {"type": "Relationship", "object": "urn:ngsi-ld:Person:bob-the-manager"},
      "installedBy": {"type": "Relationship", "object": "urn:ngsi-ld:Person:employee001"},
      "statusOfWork": {"type": "Property", "value": "completed"}
    },
    "@context": "https://fiware.github.io/tutorials.Step-by-Step/tutorials-context.jsonld"
}'

I update the shelf unit providing the @context in a Link Header and setting Content-type=application/json

curl -L -X PATCH 'http://localhost:1026/ngsi-ld/v1/entities/urn:ngsi-ld:Shelf:unit001/attrs' \
-H 'Link: <https://fiware.github.io/tutorials.Step-by-Step/tutorials-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
-H 'Content-Type: application/json' \
--data-raw '{ "numberOfItems": { "type": "Property", "value": 9 }
 }'

I receive an invalid BadRequestData response - note my payload is JSON only.

{
    "type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData",
    "title": "@context missing in JSON payload",
    "detail": "For application/ld+json, the @context must be present in the JSON payload"
}
kzangeli commented 4 years ago

This one I can't reproduce. Works just fine for me ...

jason-fox commented 4 years ago

This seems to be a Postman only issue:

Postman

time=Tuesday 18 Feb 10:39:27 2020.715Z | lvl=INFO | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=logMsg.h[1916]:lmTransactionEnd | msg=Transaction ended
time=Tuesday 18 Feb 10:41:06 2020.934Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=orionldMhdConnectionInit.cpp[279]:orionldMhdConnectionInit | msg=------------------------- Servicing NGSI-LD request 038: PATCH /ngsi-ld/v1/entities/urn:ngsi-ld:Shelf:unit001/attrs --------------------------
time=Tuesday 18 Feb 10:41:06 2020.935Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=rest.cpp[590]:httpHeaderGet | msg=FWD: Got HTTP Header:   Link: <https://fiware.github.io/tutorials.Step-by-Step/tutorials-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"
time=Tuesday 18 Feb 10:41:06 2020.935Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=rest.cpp[590]:httpHeaderGet | msg=FWD: Got HTTP Header:   Content-Type: application/json
time=Tuesday 18 Feb 10:41:06 2020.935Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=rest.cpp[590]:httpHeaderGet | msg=FWD: Got HTTP Header:   User-Agent: PostmanRuntime/7.22.0
time=Tuesday 18 Feb 10:41:06 2020.936Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=rest.cpp[590]:httpHeaderGet | msg=FWD: Got HTTP Header:   Accept: */*
time=Tuesday 18 Feb 10:41:06 2020.936Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=rest.cpp[590]:httpHeaderGet | msg=FWD: Got HTTP Header:   Host: localhost:1026
time=Tuesday 18 Feb 10:41:06 2020.936Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=rest.cpp[590]:httpHeaderGet | msg=FWD: Got HTTP Header:   Accept-Encoding: gzip, deflate, br
time=Tuesday 18 Feb 10:41:06 2020.936Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=rest.cpp[590]:httpHeaderGet | msg=FWD: Got HTTP Header:   Content-Length: 55
time=Tuesday 18 Feb 10:41:06 2020.936Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=rest.cpp[590]:httpHeaderGet | msg=FWD: Got HTTP Header:   Cookie: _csrf=MAPTGFPcoPnewsGCWklHi4Mq; connect.sid=s%3Akghk0WDrWw8O6Zv98gVFFNOnFm4ipsJ1.cEZcCYmr%2BcPbE%2Fb0EPOO8IuRBrBOmIeFgv%2FBiU3QjRw
time=Tuesday 18 Feb 10:41:06 2020.937Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=rest.cpp[590]:httpHeaderGet | msg=FWD: Got HTTP Header:   Connection: keep-alive
time=Tuesday 18 Feb 10:41:06 2020.937Z | lvl=ERROR | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=orionldMhdConnectionTreat.cpp[134]:contentTypeCheck | msg=Bad Input (@context missing in JSON payload: For application/ld+json, the @context must be present in the JSON payload)
time=Tuesday 18 Feb 10:41:06 2020.971Z | lvl=INFO | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=logMsg.h[1916]:lmTransactionEnd | msg=Transaction ended

Curl

time=Tuesday 18 Feb 10:42:03 2020.646Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | 
op=orionldMhdConnectionInit.cpp[279]:orionldMhdConnectionInit | msg=------------------------- Servicing NGSI-LD request 039: PATCH /ngsi-ld/v1/entities/urn:ngsi-ld:Shelf:unit001/attrs --------------------------
time=Tuesday 18 Feb 10:42:03 2020.647Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=rest.cpp[590]:httpHeaderGet | msg=FWD: Got HTTP Header:   Host: localhost:1026
time=Tuesday 18 Feb 10:42:03 2020.647Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=rest.cpp[590]:httpHeaderGet | msg=FWD: Got HTTP Header:   User-Agent: curl/7.64.1
time=Tuesday 18 Feb 10:42:03 2020.647Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=rest.cpp[590]:httpHeaderGet | msg=FWD: Got HTTP Header:   Accept: */*
time=Tuesday 18 Feb 10:42:03 2020.647Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=rest.cpp[590]:httpHeaderGet | msg=FWD: Got HTTP Header:   Link: <https://fiware.github.io/tutorials.Step-by-Step/tutorials-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"
time=Tuesday 18 Feb 10:42:03 2020.647Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=rest.cpp[590]:httpHeaderGet | msg=FWD: Got HTTP Header:   Content-Type: application/json
time=Tuesday 18 Feb 10:42:03 2020.647Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=rest.cpp[590]:httpHeaderGet | msg=FWD: Got HTTP Header:   Content-Length: 55

time=Tuesday 18 Feb 10:42:03 2020.648Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=mongoCppLegacyKjTreeFromBsonObj.cpp[54]:mongoCppLegacyKjTreeFromBsonObj | msg=BsonObj Converted to a JSON String: { "_id" : { "id" : "urn:ngsi-ld:Shelf:unit001", "type" : "https://fiware.github.io/tutorials.Step-by-Step/schema/Shelf", "servicePath" : "/" }, "attrNames" : [ "location", "https://fiware.github.io/tutorials.Step-by-Step/schema/maxCapacity", "https://fiware.github.io/tutorials.Step-by-Step/schema/numberOfItems", "https://uri.etsi.org/ngsi-ld/name", "https://fiware.github.io/tutorials.Step-by-Step/schema/stocks", "https://fiware.github.io/tutorials.Step-by-Step/schema/locatedIn" ], "attrs" : { "location" : { "type" : "GeoProperty", "creDate" : 1582022298, "modDate" : 1582022298, "value" : { "type" : "Point", "coordinates" : [ 13.3986112, 52.554699 ] }, "mdNames" : [] }, "https://fiware=github=io/tutorials=Step-by-Step/schema/maxCapacity" : { "type" : "Property", "creDate" : 1582022298, "modDate" : 1582022298, "value" : 50, "mdNames" : [] }, "https://fiware=github=io/tutorials=Step-by-Step/schema/numberOfItems" : { "value" : 9, "type" : "Property", "mdNames" : [], "creDate" : 1582022298, "modDate" : 1582022354 }, "https://uri=etsi=org/ngsi-ld/name" : { "type" : "Property", "creDate" : 1582022298, "modDate" : 1582022298, "value" : "Corner Unit", "mdNames" : [] }, "https://fiware=github=io/tutorials=Step-by-Step/schema/stocks" : { "type" : "Relationship", "creDate" : 1582022298, "modDate" : 1582022298, "value" : "urn:ngsi-ld:Product:001", "mdNames" : [] }, "https://fiware=github=io/tutorials=Step-by-Step/schema/locatedIn" : { "type" : "Relationship", "creDate" : 1582022298, "modDate" : 1582022298, "value" : "urn:ngsi-ld:Building:store001", "md" : { "https://fiware=github=io/tutorials=Step-by-Step/schema/requestedBy" : { "type" : "Relationship", "value" : "urn:ngsi-ld:Person:bob-the-manager" }, "https://fiware=github=io/tutorials=Step-by-Step/schema/installedBy" : { "type" : "Relationship", "value" : "urn:ngsi-ld:Person:employee001" }, "https://fiware=github=io/tutorials=Step-by-Step/schema/statusOfWork" : { "type" : "Property", "value" : "https://fiware.github.io/tutorials.Step-by-Step/schema/completed" } }, "mdNames" : [ "https://fiware.github.io/tutorials.Step-by-Step/schema/requestedBy", "https://fiware.github.io/tutorials.Step-by-Step/schema/installedBy", "https://fiware.github.io/tutorials.Step-by-Step/schema/statusOfWork" ] } }, "creDate" : 1582022298, "modDate" : 1582022354, "location" : { "attrName" : "location", "coords" : { "type" : "Point", "coordinates" : [ 13.3986112, 52.554699 ] } }, "lastCorrelator" : "" }
time=Tuesday 18 Feb 10:42:03 2020.649Z | lvl=DEBUG | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=MongoGlobal.cpp[611]:composeDatabaseName | msg=database name composed: 'orion'
time=Tuesday 18 Feb 10:42:03 2020.650Z | lvl=INFO | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=connectionOperations.cpp[94]:collectionQuery | msg=Database Operation Successful (query: { _id.id: "urn:ngsi-ld:Shelf:unit001", _id.servicePath: { $in: [ null, /^/$/ ] } })
time=Tuesday 18 Feb 10:42:03 2020.650Z | lvl=INFO | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=logMsg.h[1916]:lmTransactionEnd | msg=Transaction ended
jason-fox commented 4 years ago

"Fixed" by rebooting Postman - closing as non-reproducible.