Skip to content

Commit

Permalink
Merge pull request #1361 from FIWARE/issue/1307
Browse files Browse the repository at this point in the history
Fixed issue #1307
  • Loading branch information
kzangeli committed Apr 28, 2023
2 parents 4f5d989 + e9c8aca commit 2c67256
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 3 additions & 2 deletions src/lib/orionld/notifications/notificationSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/lib/orionld/notifications/orionldAlterationsTreat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand All @@ -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"
}
]
}
}
}'
Expand Down Expand Up @@ -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
Expand All @@ -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(.*)
Expand Down Expand Up @@ -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(.*)
Expand Down Expand Up @@ -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: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"
Ngsild-Attribute-Format: Normalized

Expand Down

0 comments on commit 2c67256

Please sign in to comment.