Skip to content

Commit

Permalink
Merge pull request #1563 from FIWARE/serve/hosted
Browse files Browse the repository at this point in the history
Not serving Cached contexts
  • Loading branch information
kzangeli authored Feb 22, 2024
2 parents b3cdfd8 + c397e63 commit 83a7bdb
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/lib/orionld/context/orionldContextFromBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ OrionldContext* orionldContextFromBuffer(char* url, OrionldContextOrigin origin,
KjNode* contextNodeP = kjLookup(tree, "@context");
if (contextNodeP == NULL)
{
orionldError(OrionldBadRequestData, "Invalid context - @context field missing", url, 400);
orionldError(OrionldInvalidRequest, "Invalid context - @context field missing", url, 400);
return NULL;
}

Expand Down
6 changes: 5 additions & 1 deletion src/lib/orionld/serviceRoutines/orionldDeleteContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ bool orionldDeleteContext(void)

if (orionldState.uriParams.reload == true)
{
if (oldContextP->origin != OrionldContextDownloaded)
//
// Only contexts of type Cached (indirect download) can be reloaded
//
if (oldContextP->kind != OrionldContextCached)
{
orionldError(OrionldBadRequestData, "Wrong type of context", "only cached contexts are subject for reload", 400);
return false;
Expand Down Expand Up @@ -93,6 +96,7 @@ bool orionldDeleteContext(void)
if (contextP == NULL)
{
orionldContextCacheInsert(oldContextP);
// orionldError(OrionldLdContextNotAvailable, "Unable to reload the @context", oldContextP->url, 504);
return false;
}

Expand Down
10 changes: 10 additions & 0 deletions src/lib/orionld/serviceRoutines/orionldGetContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ bool orionldGetContext(void)
return false;
}

//
// Contexts of type Cached (indirect download) are not served.
// The broker is not a context server.
// See 5.13.4.4 of the NGSI-LD API Specification
//
if ((contextP->kind == OrionldContextCached) && (orionldState.uriParams.details == false))
{
orionldError(OrionldOperationNotSupported, "Not serving cached JSON-LD @context", orionldState.wildcard[0], 422);
return false;
}

if (orionldState.uriParams.details == true)
orionldState.responseTree = orionldContextWithDetails(contextP);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/serviceRoutines/orionldPostContexts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool orionldPostContexts(void)

if (orionldState.payloadContextNode == NULL)
{
orionldError(OrionldAlreadyExists, "Invalid @context", "@context field missing", 400);
orionldError(OrionldInvalidRequest, "Invalid @context", "@context field missing", 400);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ orionldStart CB
#
# 01. Create a context in the context server
# 02. Create an entity using the context from step 01, just to get the context inside the context cache of the broker
# 03. GET the context (from step 01) from the broker
# 03. GET the context (from step 01) from the broker - without details - see 422
# 03. GET the context (from step 01) from the broker - with details - see metadata of the context
# 04. Update the context in the context server
# 05. DELETE and RELOAD the context in the broker's context cache
# 06. GET the context (from step 05) from the broker and make sure it's been updated
Expand Down Expand Up @@ -72,13 +73,20 @@ echo
echo


echo "03. GET the context (from step 01) from the broker"
echo "=================================================="
echo "03. GET the context (from step 01) from the broker - without details - see 422"
echo "=============================================================================="
orionCurl --url '/ngsi-ld/v1/jsonldContexts/http://localhost:7080/jsonldContexts/testContext2'
echo
echo


echo "03. GET the context (from step 01) from the broker - with details - see metadata of the context"
echo "==============================================================================================="
orionCurl --url '/ngsi-ld/v1/jsonldContexts/http://localhost:7080/jsonldContexts/testContext2?details=true'
echo
echo


echo "04. Update the context in the context server"
echo "============================================"
cServerCurl --url /jsonldContexts/testContext2 --verb DELETE
Expand All @@ -103,7 +111,7 @@ echo

echo "06. GET the context (from step 05) from the broker and make sure it's been updated"
echo "=================================================================================="
orionCurl --url '/ngsi-ld/v1/jsonldContexts/http://localhost:7080/jsonldContexts/testContext2'
orionCurl --url '/ngsi-ld/v1/jsonldContexts/http://localhost:7080/jsonldContexts/testContext2?details=true'
echo
echo

Expand Down Expand Up @@ -131,7 +139,7 @@ echo

echo "10. GET the context from the broker and make sure it exists in the broker's context cache and is the same as in step 06"
echo "======================================================================================================================="
orionCurl --url '/ngsi-ld/v1/jsonldContexts/http://localhost:7080/jsonldContexts/testContext2'
orionCurl --url '/ngsi-ld/v1/jsonldContexts/http://localhost:7080/jsonldContexts/testContext2?details=true'
echo
echo

Expand All @@ -156,18 +164,44 @@ Location: /ngsi-ld/v1/entities/urn:ngsi-ld:entities:E1



03. GET the context (from step 01) from the broker
==================================================
03. GET the context (from step 01) from the broker - without details - see 422
==============================================================================
HTTP/1.1 422 Unprocessable Content
Content-Length: 175
Content-Type: application/json
Date: REGEX(.*)

{
"detail": "http://localhost:7080/jsonldContexts/testContext2",
"title": "Not serving cached JSON-LD @context",
"type": "https://uri.etsi.org/ngsi-ld/errors/OperationNotSupported"
}


03. GET the context (from step 01) from the broker - with details - see metadata of the context
===============================================================================================
HTTP/1.1 200 OK
Content-Length: 42
Content-Length: 349
Content-Type: application/json
Date: REGEX(.*)

{
"@context": {
"p1": "urn:p1",
"p2": "urn:p2"
}
"URL": "http://localhost:7080/jsonldContexts/testContext2",
"createdAt": "202REGEX(.*)",
"extraInfo": {
"compactions": 0,
"expansions": 0,
"hash-table": {
"p1": "urn:p1",
"p2": "urn:p2"
},
"origin": "Downloaded",
"type": "hash-table"
},
"kind": "Cached",
"lastUsage": "202REGEX(.*)",
"localId": "REGEX(.*)",
"numberOfHits": 1
}


Expand Down Expand Up @@ -196,15 +230,27 @@ Date: REGEX(.*)
06. GET the context (from step 05) from the broker and make sure it's been updated
==================================================================================
HTTP/1.1 200 OK
Content-Length: 56
Content-Length: 363
Content-Type: application/json
Date: REGEX(.*)

{
"@context": {
"p1": "urn:step04:p1",
"p2": "urn:step04:p2"
}
"URL": "http://localhost:7080/jsonldContexts/testContext2",
"createdAt": "202REGEX(.*)",
"extraInfo": {
"compactions": 0,
"expansions": 0,
"hash-table": {
"p1": "urn:step04:p1",
"p2": "urn:step04:p2"
},
"origin": "Downloaded",
"type": "hash-table"
},
"kind": "Cached",
"lastUsage": "202REGEX(.*)",
"localId": "REGEX(.*)",
"numberOfHits": 1
}


Expand Down Expand Up @@ -242,15 +288,27 @@ Date: REGEX(.*)
10. GET the context from the broker and make sure it exists in the broker's context cache and is the same as in step 06
=======================================================================================================================
HTTP/1.1 200 OK
Content-Length: 56
Content-Length: 363
Content-Type: application/json
Date: REGEX(.*)

{
"@context": {
"p1": "urn:step04:p1",
"p2": "urn:step04:p2"
}
"URL": "http://localhost:7080/jsonldContexts/testContext2",
"createdAt": "202REGEX(.*)",
"extraInfo": {
"compactions": 0,
"expansions": 0,
"hash-table": {
"p1": "urn:step04:p1",
"p2": "urn:step04:p2"
},
"origin": "Downloaded",
"type": "hash-table"
},
"kind": "Cached",
"lastUsage": "202REGEX(.*)",
"localId": "REGEX(.*)",
"numberOfHits": 1
}


Expand Down

0 comments on commit 83a7bdb

Please sign in to comment.