diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 36de902355..949f72d1af 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -67,4 +67,4 @@ * Issue #280 Implemented trace messages for incoming HTTP headers (trace level LmtHeaders (-t 32)) * Issue #1356 Made Orion-LD accept a configureable max size for incoming/outgoing payload bodies * Issue #280 Fixed a bug about keyValues returned as normalized when distributed operations but no hits on regs -* Issue #280 Added the feature of "urn:ngsi-ld:request" to notifications (forwarding a header with its value from the initial request) +* Issue #1307 Added the feature of "urn:ngsi-ld:request" to notifications (forwarding a header with its value from the initial request) diff --git a/src/lib/orionld/notifications/notificationSend.cpp b/src/lib/orionld/notifications/notificationSend.cpp index 0c906a9d0c..9ef23d2b0f 100644 --- a/src/lib/orionld/notifications/notificationSend.cpp +++ b/src/lib/orionld/notifications/notificationSend.cpp @@ -785,8 +785,6 @@ int notificationSend(OrionldAlterationMatch* mAltP, double timestamp, CURL** cur { const char* key = it->first.c_str(); char* value = (char*) it->second.c_str(); - int len = strlen(key) + strlen(value) + 10; - char* buf = kaAlloc(&orionldState.kalloc, len); if (strcmp(value, "urn:ngsi-ld:request") == 0) { @@ -802,6 +800,9 @@ int notificationSend(OrionldAlterationMatch* mAltP, double timestamp, CURL** cur continue; // No incoming headers? Must ignore the urn:ngsi-ld:request header, no other choice } + int len = strlen(key) + strlen(value) + 10; + char* buf = kaAlloc(&orionldState.kalloc, len); + ioVec[headerIx].iov_len = snprintf(buf, len, "%s: %s\r\n", key, value); ioVec[headerIx].iov_base = buf; ++headerIx; diff --git a/src/lib/orionld/notifications/orionldAlterationsTreat.cpp b/src/lib/orionld/notifications/orionldAlterationsTreat.cpp index 5bdf0d5ac6..e094ee356a 100644 --- a/src/lib/orionld/notifications/orionldAlterationsTreat.cpp +++ b/src/lib/orionld/notifications/orionldAlterationsTreat.cpp @@ -575,7 +575,6 @@ void orionldAlterationsTreat(OrionldAlteration* altList) CURL* curlHandleP = NULL; int fd = notificationSend(matchHead, notificationTime, &curlHandleP); // curl handle as output param? - LM_T(LmtNotificationSend, ("%s: notificationSend returned fd %d (-2 is OK if HTTPS)", matchHead->subP->subscriptionId, fd)); // // -1 is ERROR, -2 is OK for HTTPS, anything else is a file descriptor to read from, except if MQTT. diff --git a/test/functionalTest/cases/0000_ngsild/ngsild_new_notifications_entity_delete.test b/test/functionalTest/cases/0000_ngsild/ngsild_new_notifications_entity_delete.test index 7a0a384c35..1c79c4900c 100644 --- a/test/functionalTest/cases/0000_ngsild/ngsild_new_notifications_entity_delete.test +++ b/test/functionalTest/cases/0000_ngsild/ngsild_new_notifications_entity_delete.test @@ -32,12 +32,12 @@ accumulatorStart --pretty-print # # 01. Create Entity urn:E1, type T -# 02a. Create a subscription S1 for the accumulator, on entity type T, for deletions +# 02a. Create a subscription S1 for the accumulator, on entity type T, for deletions, with a receiverInfo header 'FIWARE-Correlator' header set to 'urn:ngsi-ld:request' # 02b. Create a subscription S2 for the accumulator, on entity type T + entity id urn:E1, for deletions # 02c. Create a subscription S3 for the accumulator, on entity type T + entity id urn:E2, for deletions # 02d. Create a subscription S4 for the accumulator, on entity type T2 + entity id urn:E1, for deletions -# 03. Delete urn:E1 -# 04. Dump the accumulator, see two notifications (S1+S2) on Entity deletion for urn:E1 +# 03. Delete urn:E1, with a FIWARE-Correlator header set +# 04. Dump the accumulator, see two notifications (S1+S2) on Entity deletion for urn:E1, see the 'FIWARE-Correlator' header for the S1 notification # echo "01. Create Entity urn:E1, type T" @@ -55,8 +55,8 @@ echo echo -echo "02a. Create a subscription S1 for the accumulator, on entity type T, for deletions" -echo "==================================================================================" +echo "02a. Create a subscription S1 for the accumulator, on entity type T, for deletions, with a receiverInfo header 'FIWARE-Correlator' header set to 'urn:ngsi-ld:request'" +echo "======================================================================================================================================================================" payload='{ "id": "urn:S1", "type": "Subscription", @@ -67,7 +67,13 @@ payload='{ ], "notification": { "endpoint": { - "uri": "http://127.0.0.1:'${LISTENER_PORT}'/notify" + "uri": "http://127.0.0.1:'${LISTENER_PORT}'/notify", + "receiverInfo": [ + { + "key": "FIWARE-Correlator", + "value": "urn:ngsi-ld:request" + } + ] } } }' @@ -142,15 +148,15 @@ echo echo -echo "03. Delete urn:E1" -echo "=================" -orionCurl --url /ngsi-ld/v1/entities/urn:E1 -X DELETE +echo "03. Delete urn:E1, with a FIWARE-Correlator header set" +echo "=======================================================" +orionCurl --url /ngsi-ld/v1/entities/urn:E1 -X DELETE -H "FIWARE-Correlator: c846fdbb-b8ad-41f7-ba21-84" echo echo -echo "04. Dump the accumulator, see the notification on Entity deletion for urn:E1" -echo "============================================================================" +echo "04. Dump the accumulator, see two notifications (S1+S2) on Entity deletion for urn:E1, see the 'FIWARE-Correlator' header for the S1 notification" +echo "==================================================================================================================================================" accumulatorDump echo echo @@ -166,8 +172,8 @@ Location: /ngsi-ld/v1/entities/urn:E1 -02a. Create a subscription S1 for the accumulator, on entity type T, for deletions -================================================================================== +02a. Create a subscription S1 for the accumulator, on entity type T, for deletions, with a receiverInfo header 'FIWARE-Correlator' header set to 'urn:ngsi-ld:request' +====================================================================================================================================================================== HTTP/1.1 201 Created Content-Length: 0 Date: REGEX(.*) @@ -202,15 +208,15 @@ Location: /ngsi-ld/v1/subscriptions/urn:S4 -03. Delete urn:E1 -================= +03. Delete urn:E1, with a FIWARE-Correlator header set +======================================================= HTTP/1.1 204 No Content Date: REGEX(.*) -04. Dump the accumulator, see the notification on Entity deletion for urn:E1 -============================================================================ +04. Dump the accumulator, see two notifications (S1+S2) on Entity deletion for urn:E1, see the 'FIWARE-Correlator' header for the S1 notification +================================================================================================================================================== POST http://REGEX(.*)/notify?subscriptionId=urn:S2 Content-Length: 233 User-Agent: orionld/REGEX(.*) @@ -240,6 +246,7 @@ User-Agent: orionld/REGEX(.*) Host: REGEX(.*) Accept: application/json Content-Type: application/json +Fiware-Correlator: c846fdbb-b8ad-41f7-ba21-84 Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json" Ngsild-Attribute-Format: Normalized