diff --git a/src/lib/apiTypesV2/Entity.cpp b/src/lib/apiTypesV2/Entity.cpp index 8ffde8bcfa..5516bb0173 100644 --- a/src/lib/apiTypesV2/Entity.cpp +++ b/src/lib/apiTypesV2/Entity.cpp @@ -718,18 +718,18 @@ void Entity::fill(const QueryContextResponse& qcrs, OrionError* oeP) { Entity* eP = NULL; - if (qcrs.errorCode.code == SccContextElementNotFound) + if (qcrs.error.code == SccContextElementNotFound) { oeP->fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY, ERROR_NOT_FOUND); } - else if (qcrs.errorCode.code != SccOk) + else if (qcrs.error.code != SccOk) { // // any other error distinct from Not Found // - oeP->fill(qcrs.errorCode.code, qcrs.errorCode.details, qcrs.errorCode.reasonPhrase); + oeP->fill(qcrs.error.code, qcrs.error.description, qcrs.error.error); } - else // qcrs.errorCode.code == SccOk + else // qcrs.error.code == SccOk { // // If there are more than one entity (ignoring SccContextElementNotFound cases), we return an error @@ -737,7 +737,7 @@ void Entity::fill(const QueryContextResponse& qcrs, OrionError* oeP) // for (unsigned int ix = 0; ix < qcrs.contextElementResponseVector.size(); ++ix) { - if (qcrs.contextElementResponseVector[ix]->statusCode.code != SccContextElementNotFound) + if (qcrs.contextElementResponseVector[ix]->error.code != SccContextElementNotFound) { if (eP != NULL) { diff --git a/src/lib/common/logTracing.cpp b/src/lib/common/logTracing.cpp index db50faae99..d78e11e694 100644 --- a/src/lib/common/logTracing.cpp +++ b/src/lib/common/logTracing.cpp @@ -229,7 +229,15 @@ void logInfoFwdRequest { char buffer[STRING_SIZE_FOR_INT]; snprintf(buffer, sizeof(buffer), "%d", rc); - logInfoFwdRequest(regId, verb, url, requestPayload, responsePayload, buffer); + + if (responsePayload == NULL) + { + logInfoFwdRequest(regId, verb, url, requestPayload, "", buffer); + } + else + { + logInfoFwdRequest(regId, verb, url, requestPayload, responsePayload, buffer); + } } diff --git a/src/lib/mongoBackend/MongoCommonUpdate.cpp b/src/lib/mongoBackend/MongoCommonUpdate.cpp index 498577529f..24def43268 100644 --- a/src/lib/mongoBackend/MongoCommonUpdate.cpp +++ b/src/lib/mongoBackend/MongoCommonUpdate.cpp @@ -2397,7 +2397,7 @@ static bool updateContextAttributeItem { /* If updateAttribute() returns false, then that particular attribute has not * been found. In this case, we interrupt the processing and early return with - * an error StatusCode */ + * an error OrionError */ // // FIXME P10: not sure if this .fill() is useless... it seems it is "overriden" by @@ -2408,7 +2408,7 @@ static bool updateContextAttributeItem " - entity: [" + entityDetail + "]" + " - offending attribute: " + targetAttr->getName(); - cerP->statusCode.fill(SccInvalidParameter, details); + cerP->error.fill(SccInvalidParameter, details); /* Although 'ca' has been already pushed into cerP, the pointer is still valid, of course */ ca->found = false; @@ -2425,7 +2425,7 @@ static bool updateContextAttributeItem " - offending attribute: " + targetAttr->getName() + " - " + err; - cerP->statusCode.fill(SccInvalidParameter, details); + cerP->error.fill(SccInvalidParameter, details); // oe->fill() not used, as this is done internally in processLocationAtUpdateAttribute() alarmMgr.badInput(clientIp, err, targetAttr->getName()); @@ -2484,7 +2484,7 @@ static bool appendContextAttributeItem " - offending attribute: " + targetAttr->getName() + " - " + err; - cerP->statusCode.fill(SccInvalidParameter, details); + cerP->error.fill(SccInvalidParameter, details); // oe->fill() is not used here as it is managed by processLocationAtAppendAttribute() alarmMgr.badInput(clientIp, err, targetAttr->getName()); @@ -2536,7 +2536,7 @@ static bool deleteContextAttributeItem " - offending attribute: " + targetAttr->getName() + " - location attribute has to be defined at creation time, with APPEND"; - cerP->statusCode.fill(SccInvalidParameter, details); + cerP->error.fill(SccInvalidParameter, details); oe->fill(SccInvalidModification, details, ERROR_UNPROCESSABLE); alarmMgr.badInput(clientIp, "location attribute has to be defined at creation time", targetAttr->getName()); @@ -2564,13 +2564,13 @@ static bool deleteContextAttributeItem { /* If deleteAttribute() returns false, then that particular attribute has not * been found. In this case, we interrupt the processing and early return with - * a error StatusCode */ + * a OrionError */ std::string details = std::string("action: DELETE") + " - entity: [" + entityDetail + "]" + " - offending attribute: " + targetAttr->getName() + " - attribute not found"; - cerP->statusCode.fill(SccInvalidParameter, details); + cerP->error.fill(SccInvalidParameter, details); alarmMgr.badInput(clientIp, "attribute to be deleted is not found", targetAttr->getName()); ca->found = false; @@ -2707,7 +2707,7 @@ static bool processContextAttributeVector { std::string details = std::string("unknown actionType"); - cerP->statusCode.fill(SccInvalidParameter, details); + cerP->error.fill(SccInvalidParameter, details); oe->fill(SccBadRequest, details, ERROR_BAD_REQUEST); // If we reach this point, there's a BUG in the parse layer checks @@ -2751,7 +2751,7 @@ static bool processContextAttributeVector } else if (!addTriggeredSubscriptions(entityId, entityType, attributes, attrsWithModifiedValue, attrsWithModifiedMd, subsToNotify, err, tenant, servicePathV, targetAltType)) { - cerP->statusCode.fill(SccReceiverInternalError, err); + cerP->error.fill(SccReceiverInternalError, err); oe->fill(SccReceiverInternalError, err, "InternalServerError"); return false; } @@ -2765,14 +2765,14 @@ static bool processContextAttributeVector // FIXME P5: this is ugly, our code should be improved to set cerP in a common place for the "happy case" - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); } #endif /* If the status code was not touched (filled with an error), then set it with Ok */ - if (cerP->statusCode.code == SccNone) + if (cerP->error.code == SccNone) { - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); } return entityModified; @@ -3020,12 +3020,12 @@ static bool removeEntity std::string err; if (!collectionRemove(composeDatabaseName(tenant), COL_ENTITIES, bob.obj(), &err)) { - cerP->statusCode.fill(SccReceiverInternalError, err); + cerP->error.fill(SccReceiverInternalError, err); oe->fill(SccReceiverInternalError, err, "InternalServerError"); return false; } - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); return true; } @@ -3469,7 +3469,7 @@ static unsigned int updateEntity if ((action == ActionTypeDelete) && (eP->attributeVector.size() == 0)) { LM_T(LmtServicePath, ("Removing entity")); - removeEntity(entityId, entityType, cerP, tenant, entitySPath, &(responseP->oe)); + removeEntity(entityId, entityType, cerP, tenant, entitySPath, &(responseP->error)); responseP->contextElementResponseVector.push_back(cerP); /* EntityDelete subscriptions may be triggered */ @@ -3495,8 +3495,8 @@ static unsigned int updateEntity ngsiv2::SubAltType::EntityDelete)) { releaseTriggeredSubscriptions(&subsToNotify); - cerP->statusCode.fill(SccReceiverInternalError, err); - responseP->oe.fill(SccReceiverInternalError, err, ERROR_INTERNAL_ERROR); + cerP->error.fill(SccReceiverInternalError, err); + responseP->error.fill(SccReceiverInternalError, err, ERROR_INTERNAL_ERROR); responseP->contextElementResponseVector.push_back(cerP); return 0; // Error already in responseP @@ -3627,7 +3627,7 @@ static unsigned int updateEntity forcedUpdate, overrideMetadata, loopDetected, - &(responseP->oe))) + &(responseP->error))) { // The entity wasn't actually modified, so we don't need to update it and we can continue with the next one @@ -3879,8 +3879,8 @@ static unsigned int updateEntity } if (!success) { - cerP->statusCode.fill(SccReceiverInternalError, err); - responseP->oe.fill(SccReceiverInternalError, err, "InternalServerError"); + cerP->error.fill(SccReceiverInternalError, err); + responseP->error.fill(SccReceiverInternalError, err, "InternalServerError"); responseP->contextElementResponseVector.push_back(cerP); @@ -3922,11 +3922,11 @@ static unsigned int updateEntity searchContextProviders(tenant, servicePathV, en, eP->attributeVector, cerP); } - // StatusCode may be set already (if so, we keep the existing value) + // OrionError may be set already (if so, we keep the existing value) - if (cerP->statusCode.code == SccNone) + if (cerP->error.code == SccNone) { - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); } responseP->contextElementResponseVector.push_back(cerP); @@ -3956,7 +3956,7 @@ static bool contextElementPreconditionsCheck if ((name == eP->attributeVector[jx]->name)) { alarmMgr.badInput(clientIp, "duplicated attribute name", name); - responseP->oe.fill(SccBadRequest, "duplicated attribute /" + name + "/", ERROR_BAD_REQUEST); + responseP->error.fill(SccBadRequest, "duplicated attribute /" + name + "/", ERROR_BAD_REQUEST); return false; // Error already in responseP } } @@ -3965,7 +3965,7 @@ static bool contextElementPreconditionsCheck /* Not supporting idPattern currently */ if (!eP->entityId.idPattern.empty()) { - // No need of filling responseP->oe, this cannot happen in NGSIv2 + // No need of filling responseP->error, this cannot happen in NGSIv2 // FIXME PR: check this return false; // Error already in responseP } @@ -4079,14 +4079,14 @@ unsigned int processContextElement if (!orion::collectionCount(composeDatabaseName(tenant), COL_ENTITIES, query, &entitiesNumber, &err)) { - responseP->oe.fill(SccReceiverInternalError, err, "InternalServerError"); + responseP->error.fill(SccReceiverInternalError, err, "InternalServerError"); return 0; } // This is the case of POST /v2/entities, in order to check that entity doesn't previously exist if ((entitiesNumber > 0) && (ngsiv2Flavour == NGSIV2_FLAVOUR_ONCREATE)) { - responseP->oe.fill(SccInvalidModification, ERROR_DESC_UNPROCESSABLE_ALREADY_EXISTS, ERROR_UNPROCESSABLE); + responseP->error.fill(SccInvalidModification, ERROR_DESC_UNPROCESSABLE_ALREADY_EXISTS, ERROR_UNPROCESSABLE); return 0; } @@ -4094,7 +4094,7 @@ unsigned int processContextElement // both for regular case and when ?options=append is used if ((entitiesNumber == 0) && (ngsiv2Flavour == NGSIV2_FLAVOUR_ONAPPEND)) { - responseP->oe.fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY, ERROR_NOT_FOUND); + responseP->error.fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY, ERROR_NOT_FOUND); return 0; } @@ -4102,7 +4102,7 @@ unsigned int processContextElement // not allowed in NGSIv2 if (entitiesNumber > 1) { - responseP->oe.fill(SccConflict, ERROR_DESC_TOO_MANY_ENTITIES, ERROR_TOO_MANY); + responseP->error.fill(SccConflict, ERROR_DESC_TOO_MANY_ENTITIES, ERROR_TOO_MANY); return 0; } @@ -4113,7 +4113,7 @@ unsigned int processContextElement { orion::releaseMongoConnection(connection); TIME_STAT_MONGO_READ_WAIT_STOP(); - responseP->oe.fill(SccReceiverInternalError, err, "InternalServerError"); + responseP->error.fill(SccReceiverInternalError, err, "InternalServerError"); return 0; } @@ -4224,7 +4224,7 @@ unsigned int processContextElement { /* In the case of UPDATE or REPLACE we look for context providers */ searchContextProviders(tenant, servicePathV, en, eP->attributeVector, cerP); - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); responseP->contextElementResponseVector.push_back(cerP); // @@ -4232,10 +4232,10 @@ unsigned int processContextElement // if (forwardsPending(responseP) == false) { - cerP->statusCode.fill(SccContextElementNotFound); + cerP->error.fill(SccContextElementNotFound); std::string details = ERROR_DESC_DO_NOT_EXIT + enStr + " - [entity itself]"; - responseP->oe.fillOrAppend(SccContextElementNotFound, details, ", " + enStr + " [entity itself]", ERROR_NOT_FOUND); + responseP->error.fillOrAppend(SccContextElementNotFound, details, ", " + enStr + " [entity itself]", ERROR_NOT_FOUND); if (updateCoverageP != NULL) { *updateCoverageP = UC_ENTITY_NOT_FOUND; @@ -4244,10 +4244,10 @@ unsigned int processContextElement } else if (action == ActionTypeDelete) { - cerP->statusCode.fill(SccContextElementNotFound); + cerP->error.fill(SccContextElementNotFound); std::string details = ERROR_DESC_DO_NOT_EXIT + enStr + " - [entity itself]"; - responseP->oe.fillOrAppend(SccContextElementNotFound, details, ", " + enStr + " [entity itself]", ERROR_NOT_FOUND); + responseP->error.fillOrAppend(SccContextElementNotFound, details, ", " + enStr + " [entity itself]", ERROR_NOT_FOUND); responseP->contextElementResponseVector.push_back(cerP); if (updateCoverageP != NULL) { @@ -4269,14 +4269,14 @@ unsigned int processContextElement servicePathV, fiwareCorrelator, ngsiv2Flavour == NGSIV2_NO_FLAVOUR, - &(responseP->oe))) + &(responseP->error))) { - cerP->statusCode.fill(SccInvalidParameter, errDetail); - // In this case, responseP->oe is not filled, as createEntity() deals internally with that + cerP->error.fill(SccInvalidParameter, errDetail); + // In this case, responseP->error is not filled, as createEntity() deals internally with that } else { - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); /* Successful creation: send potential notifications */ std::map subsToNotify; @@ -4299,8 +4299,8 @@ unsigned int processContextElement ngsiv2::SubAltType::EntityCreate)) { releaseTriggeredSubscriptions(&subsToNotify); - cerP->statusCode.fill(SccReceiverInternalError, err); - responseP->oe.fill(SccReceiverInternalError, err, ERROR_INTERNAL_ERROR); + cerP->error.fill(SccReceiverInternalError, err); + responseP->error.fill(SccReceiverInternalError, err, ERROR_INTERNAL_ERROR); responseP->contextElementResponseVector.push_back(cerP); return 0; // Error already in responseP @@ -4351,13 +4351,13 @@ unsigned int processContextElement if ((attributeAlreadyExistsNumber > 0) && (action == ActionTypeAppendStrict)) { std::string details = ERROR_DESC_UNPROCESSABLE_ATTR_ALREADY_EXISTS + enStr + " - " + attributeAlreadyExistsList; - responseP->oe.fillOrAppend(SccInvalidModification, details, ", " + enStr + " - " + attributeAlreadyExistsList, ERROR_UNPROCESSABLE); + responseP->error.fillOrAppend(SccInvalidModification, details, ", " + enStr + " - " + attributeAlreadyExistsList, ERROR_UNPROCESSABLE); } if ((attributeNotExistingNumber > 0) && ((action == ActionTypeUpdate) || (action == ActionTypeDelete))) { std::string details = ERROR_DESC_DO_NOT_EXIT + enStr + " - " + attributeNotExistingList; - responseP->oe.fillOrAppend(SccInvalidModification, details, ", " + enStr + " - " + attributeNotExistingList, ERROR_UNPROCESSABLE); + responseP->error.fillOrAppend(SccInvalidModification, details, ", " + enStr + " - " + attributeNotExistingList, ERROR_UNPROCESSABLE); } // The following check makes sense only when there are at least one attribute in the request diff --git a/src/lib/mongoBackend/MongoGlobal.cpp b/src/lib/mongoBackend/MongoGlobal.cpp index 0edd4b53b7..a663de0af9 100644 --- a/src/lib/mongoBackend/MongoGlobal.cpp +++ b/src/lib/mongoBackend/MongoGlobal.cpp @@ -1226,7 +1226,7 @@ bool entitiesQuery const StringList& attrL, const ScopeVector& spV, ContextElementResponseVector* cerV, - std::string* err, + OrionError* oeP, const std::string& tenant, const std::vector& servicePath, int offset, @@ -1247,6 +1247,8 @@ bool entitiesQuery * */ + std::string err; + orion::BSONObjBuilder finalQuery; orion::BSONObjBuilder finalCountQuery; orion::BSONArrayBuilder orEnt; @@ -1430,7 +1432,7 @@ bool entitiesQuery TIME_STAT_MONGO_READ_WAIT_START(); orion::DBConnection connection = orion::getMongoConnection(); - if (!orion::collectionRangedQuery(connection, composeDatabaseName(tenant), COL_ENTITIES, query, countQuery, sort, limit, offset, &cursor, countP, err)) + if (!orion::collectionRangedQuery(connection, composeDatabaseName(tenant), COL_ENTITIES, query, countQuery, sort, limit, offset, &cursor, countP, &err)) { orion::releaseMongoConnection(connection); TIME_STAT_MONGO_READ_WAIT_STOP(); @@ -1486,7 +1488,6 @@ bool entitiesQuery } } - cer->statusCode.fill(SccOk); cerV->push_back(cer); } @@ -1498,35 +1499,15 @@ bool entitiesQuery if (errType == ON_NEXT_MANAGED_ERROR) { - ContextElementResponse* cer = new ContextElementResponse(); - alarmMgr.dbError(nextErr); - // - // It would be nice to fill in the entity but it is difficult to do this. - // - // Solution: - // If the incoming entity-vector has only *one* entity, I simply fill it in with enV[0] and - // if more than one entity is in the vector, an empty entity is returned. - // - if (enV.size() == 1) - { - cer->entity.fill(enV[0]); - } - else - { - EntityId enId("", "", "", ""); - cer->entity.fill(enId); - } - - cer->statusCode.fill(SccReceiverInternalError, nextErr); - cerV->push_back(cer); - return true; + oeP->fill(SccReceiverInternalError, nextErr); + return false; } else if (errType == ON_NEXT_UNMANAGED_ERROR) { - *err = nextErr; LM_E(("Runtime Error (exception in next(): %s - query: %s)", nextErr.c_str(), query.toString().c_str())); + oeP->fill(SccReceiverInternalError, nextErr); return false; } @@ -1581,7 +1562,7 @@ bool entitiesQuery cerP->entity.attributeVector.push_back(caP); } - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); cerV->push_back(cerP); } @@ -1629,7 +1610,7 @@ void pruneContextElements // FIXME P10: not sure if this is the right way to do it, maybe we need a fill() method for this newCerP->entity.providerList = cerP->entity.providerList; newCerP->entity.providerRegIdList = cerP->entity.providerRegIdList; - newCerP->statusCode.fill(&cerP->statusCode); + newCerP->error.fill(&cerP->error); bool pruneEntity = cerP->prune; diff --git a/src/lib/mongoBackend/MongoGlobal.h b/src/lib/mongoBackend/MongoGlobal.h index 0c51f52770..97370f41f2 100644 --- a/src/lib/mongoBackend/MongoGlobal.h +++ b/src/lib/mongoBackend/MongoGlobal.h @@ -214,7 +214,7 @@ extern bool entitiesQuery const StringList& attrL, const ScopeVector& spV, ContextElementResponseVector* cerV, - std::string* err, + OrionError* oeP, const std::string& tenant, const std::vector& servicePath, int offset = DEFAULT_PAGINATION_OFFSET_INT, diff --git a/src/lib/mongoBackend/mongoNotifyContext.cpp b/src/lib/mongoBackend/mongoNotifyContext.cpp index 5b448d7cd1..63a7dfebd6 100644 --- a/src/lib/mongoBackend/mongoNotifyContext.cpp +++ b/src/lib/mongoBackend/mongoNotifyContext.cpp @@ -71,7 +71,7 @@ HttpStatusCode mongoNotifyContext } reqSemGive(__FUNCTION__, "notification", reqSemTaken); - responseP->responseCode.fill(SccOk); + responseP->error.fill(SccOk); return SccOk; } diff --git a/src/lib/mongoBackend/mongoQueryContext.cpp b/src/lib/mongoBackend/mongoQueryContext.cpp index 348eb5ad49..61c064abd6 100644 --- a/src/lib/mongoBackend/mongoQueryContext.cpp +++ b/src/lib/mongoBackend/mongoQueryContext.cpp @@ -132,7 +132,7 @@ static void addContextProviderEntity cerP->entity.providerList.push_back(provider); cerP->entity.providerRegIdList.push_back(regId); - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); cerV.push_back(cerP); } @@ -191,7 +191,7 @@ static void addContextProviderAttribute EntityId enId(regEn.id, regEn.idPattern, regEn.type, regEn.typePattern); cerP->entity.fill(enId); - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); ContextAttribute* caP = new ContextAttribute(regAttr, "", ""); @@ -359,7 +359,7 @@ HttpStatusCode mongoQueryContext requestP->attributeList, requestP->scopeVector, &rawCerV, - &err, + &responseP->error, tenant, servicePathV, offset, @@ -370,7 +370,6 @@ HttpStatusCode mongoQueryContext if (!ok) { - responseP->errorCode.fill(SccReceiverInternalError, err); rawCerV.release(); reqSemGive(__FUNCTION__, "query request", reqSemTaken); @@ -454,11 +453,11 @@ HttpStatusCode mongoQueryContext char details[256]; snprintf(details, sizeof(details), "Number of matching entities: %lld. Offset is %d", *countP, offset); // FIXME PR: this could be removed?? - responseP->errorCode.fill(SccContextElementNotFound, details); + responseP->error.fill(SccContextElementNotFound, details); } else { - responseP->errorCode.fill(SccContextElementNotFound); + responseP->error.fill(SccContextElementNotFound); } } else if (countP != NULL) @@ -472,7 +471,7 @@ HttpStatusCode mongoQueryContext char details[64]; snprintf(details, sizeof(details), "Count: %lld", *countP); - responseP->errorCode.fill(SccOk, details); + responseP->error.fill(SccOk, details); } rawCerV.release(); diff --git a/src/lib/mongoBackend/mongoQueryTypes.cpp b/src/lib/mongoBackend/mongoQueryTypes.cpp index db134f3362..8a222f7e2b 100644 --- a/src/lib/mongoBackend/mongoQueryTypes.cpp +++ b/src/lib/mongoBackend/mongoQueryTypes.cpp @@ -369,7 +369,7 @@ HttpStatusCode mongoEntityTypesValues { TIME_STAT_MONGO_COMMAND_WAIT_STOP(); orion::releaseMongoConnection(connection); - responseP->statusCode.fill(SccReceiverInternalError, err); + responseP->error.fill(SccReceiverInternalError, err); reqSemGive(__FUNCTION__, "query types request", reqSemTaken); return SccOk; @@ -411,7 +411,7 @@ HttpStatusCode mongoEntityTypesValues *totalTypesP = docs; } - responseP->statusCode.fill(SccOk); + responseP->error.fill(SccOk); reqSemGive(__FUNCTION__, "query types request", reqSemTaken); return SccOk; @@ -557,7 +557,7 @@ HttpStatusCode mongoEntityTypes { TIME_STAT_MONGO_COMMAND_WAIT_STOP(); orion::releaseMongoConnection(connection); - responseP->statusCode.fill(SccReceiverInternalError, err); + responseP->error.fill(SccReceiverInternalError, err); reqSemGive(__FUNCTION__, "query types request", reqSemTaken); return SccOk; @@ -642,11 +642,11 @@ HttpStatusCode mongoEntityTypes *totalTypesP = docs; char detailsMsg[256]; snprintf(detailsMsg, sizeof(detailsMsg), "Number of types: %u. Offset is %u", *totalTypesP, offset); - responseP->statusCode.fill(SccContextElementNotFound, detailsMsg); + responseP->error.fill(SccContextElementNotFound, detailsMsg); } else { - responseP->statusCode.fill(SccContextElementNotFound); + responseP->error.fill(SccContextElementNotFound); } } else @@ -656,11 +656,11 @@ HttpStatusCode mongoEntityTypes *totalTypesP = docs; char detailsMsg[256]; snprintf(detailsMsg, sizeof(detailsMsg), "Count: %u", *totalTypesP); - responseP->statusCode.fill(SccOk, detailsMsg); + responseP->error.fill(SccOk, detailsMsg); } else { - responseP->statusCode.fill(SccOk); + responseP->error.fill(SccOk); } } @@ -770,7 +770,7 @@ HttpStatusCode mongoAttributesForEntityType { TIME_STAT_MONGO_COMMAND_WAIT_STOP(); orion::releaseMongoConnection(connection); - responseP->statusCode.fill(SccReceiverInternalError, err); + responseP->error.fill(SccReceiverInternalError, err); reqSemGive(__FUNCTION__, "query types request", reqSemTaken); return SccOk; @@ -849,7 +849,7 @@ HttpStatusCode mongoAttributesForEntityType if (docs == 0) { - responseP->statusCode.fill(SccContextElementNotFound); + responseP->error.fill(SccContextElementNotFound); reqSemGive(__FUNCTION__, "query types request", reqSemTaken); return SccOk; @@ -862,11 +862,11 @@ HttpStatusCode mongoAttributesForEntityType if (count) { snprintf(detailsMsg, sizeof(detailsMsg), "Count: %d", (int) docs); - responseP->statusCode.fill(SccOk, detailsMsg); + responseP->error.fill(SccOk, detailsMsg); } else { - responseP->statusCode.fill(SccOk); + responseP->error.fill(SccOk); } } else @@ -874,11 +874,11 @@ HttpStatusCode mongoAttributesForEntityType if (count) { snprintf(detailsMsg, sizeof(detailsMsg), "Number of attributes: %d. Offset is %u", docs, offset); - responseP->statusCode.fill(SccContextElementNotFound, detailsMsg); + responseP->error.fill(SccContextElementNotFound, detailsMsg); } else { - responseP->statusCode.fill(SccContextElementNotFound); + responseP->error.fill(SccContextElementNotFound); } } diff --git a/src/lib/mongoBackend/mongoRegistrationGet.cpp b/src/lib/mongoBackend/mongoRegistrationGet.cpp index f152b8814b..dbafb69191 100644 --- a/src/lib/mongoBackend/mongoRegistrationGet.cpp +++ b/src/lib/mongoBackend/mongoRegistrationGet.cpp @@ -144,7 +144,7 @@ void mongoRegistrationsGet bool reqSemTaken = false; std::string err; orion::OID oid; - StatusCode sc; + OrionError oe; std::string servicePath = (servicePathV.size() == 0)? "/#" : servicePathV[0]; // FIXME P4: see #3100 reqSemTake(__FUNCTION__, "Mongo Get Registrations", SemReadOp, &reqSemTaken); diff --git a/src/lib/mongoBackend/mongoUpdateContext.cpp b/src/lib/mongoBackend/mongoUpdateContext.cpp index 5179034a59..08f5a04bce 100644 --- a/src/lib/mongoBackend/mongoUpdateContext.cpp +++ b/src/lib/mongoBackend/mongoUpdateContext.cpp @@ -142,8 +142,8 @@ HttpStatusCode mongoUpdateContext std::string details = std::string("service path length ") + lenV + " is greater than the one in update"; alarmMgr.badInput(clientIp, details); - responseP->errorCode.fill(SccBadRequest, "service path length greater than the one in update"); - responseP->oe.fill(SccBadRequest, "service path length greater than the one in update", ERROR_BAD_REQUEST); + responseP->error.fill(SccBadRequest, "service path length greater than the one in update"); + responseP->error.fill(SccBadRequest, "service path length greater than the one in update", ERROR_BAD_REQUEST); } else { @@ -218,22 +218,26 @@ HttpStatusCode mongoUpdateContext // Other cases follow the usual response processing flow (whatever it is :) if (updateCoverage == UC_PARTIAL) { - responseP->oe.code = SccInvalidModification; - responseP->oe.error = ERROR_PARTIAL_UPDATE; + responseP->error.code = SccInvalidModification; + responseP->error.error = ERROR_PARTIAL_UPDATE; } LM_T(LmtNotifier, ("total notifications sent during update: %d", notifSent)); /* Note that although individual processContextElements() invocations return ConnectionError, this - error gets "encapsulated" in the StatusCode of the corresponding ContextElementResponse and we + error gets "encapsulated" in the OrionError of the corresponding ContextElementResponse and we consider the overall mongoUpdateContext() as OK. + FIXME PR: we are removing the "corresponding ContextElementResposne" error. Review this wording */ - responseP->errorCode.fill(SccOk); + if (responseP->error.code == SccNone) + { + responseP->error.fill(SccOk); + } } reqSemGive(__FUNCTION__, "update request", reqSemTaken); - if (flowControl && fcEnabled && (responseP->errorCode.code == SccOk)) + if (flowControl && fcEnabled && (responseP->error.code == SccOk)) { LM_T(LmtNotifier, ("start notification flow control algorithm")); flowControlAwait(q0, notifSent, tenant); diff --git a/src/lib/mongoDriver/safeMongo.h b/src/lib/mongoDriver/safeMongo.h index a26c0a7102..f6a7f61f4d 100644 --- a/src/lib/mongoDriver/safeMongo.h +++ b/src/lib/mongoDriver/safeMongo.h @@ -28,7 +28,7 @@ #include #include -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "mongoDriver/DBCursor.h" #include "mongoDriver/BSONObj.h" diff --git a/src/lib/ngsi/CMakeLists.txt b/src/lib/ngsi/CMakeLists.txt index c720add459..96cac53083 100644 --- a/src/lib/ngsi/CMakeLists.txt +++ b/src/lib/ngsi/CMakeLists.txt @@ -32,7 +32,6 @@ SET (SOURCES Request.cpp Scope.cpp ScopeVector.cpp - StatusCode.cpp StringList.cpp ) @@ -46,7 +45,6 @@ SET (HEADERS Metadata.h MetadataVector.h Scope.h - StatusCode.h StringList.h ) diff --git a/src/lib/ngsi/ContextElementResponse.cpp b/src/lib/ngsi/ContextElementResponse.cpp index 8144c00f1d..d08beef005 100644 --- a/src/lib/ngsi/ContextElementResponse.cpp +++ b/src/lib/ngsi/ContextElementResponse.cpp @@ -80,7 +80,7 @@ ContextElementResponse::ContextElementResponse(ContextElementResponse* cerP, boo prune = false; entity.fill(cerP->entity, false, cloneCompounds); - statusCode.fill(cerP->statusCode); + error.fill(cerP->error); } @@ -92,7 +92,7 @@ ContextElementResponse::ContextElementResponse(ContextElementResponse* cerP, boo * This constructor builds the CER object based in a BSON object taken from the * entities collection at DB. * -* Note that statusCode is not touched by this constructor. +* Note that error field is not touched by this constructor. */ ContextElementResponse::ContextElementResponse ( @@ -140,7 +140,7 @@ ContextElementResponse::ContextElementResponse * * ContextElementResponse::ContextElementResponse - * -* This constructor builds the CER from a CEP. Note that statusCode is not touched. +* This constructor builds the CER from a CEP. Note that error field is not touched. */ ContextElementResponse::ContextElementResponse(Entity* eP, bool useDefaultType) { @@ -189,5 +189,4 @@ void ContextElementResponse::applyUpdateOperators(void) void ContextElementResponse::release(void) { entity.release(); - statusCode.release(); } diff --git a/src/lib/ngsi/ContextElementResponse.h b/src/lib/ngsi/ContextElementResponse.h index aa00f67cf5..df57a79610 100644 --- a/src/lib/ngsi/ContextElementResponse.h +++ b/src/lib/ngsi/ContextElementResponse.h @@ -29,7 +29,7 @@ #include "common/RenderFormat.h" #include "common/globals.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "ngsi/StringList.h" #include "ngsi/ContextAttribute.h" #include "apiTypesV2/Entity.h" @@ -46,7 +46,7 @@ typedef struct ContextElementResponse { Entity entity; // Mandatory (represents a Context Element) - StatusCode statusCode; // Mandatory + OrionError error; // Mandatory bool prune; // operational attribute used internally by the queryContext logic for not deleting entities that were // without attributes in the Orion DB diff --git a/src/lib/ngsi/ContextElementResponseVector.cpp b/src/lib/ngsi/ContextElementResponseVector.cpp index 50c170034b..6550937e2e 100644 --- a/src/lib/ngsi/ContextElementResponseVector.cpp +++ b/src/lib/ngsi/ContextElementResponseVector.cpp @@ -123,7 +123,7 @@ ContextElementResponse* ContextElementResponseVector::lookup(Entity* eP, HttpSta { if (vec[ix]->entity.equal(eP) == true) { - if ((code == SccNone) || (vec[ix]->statusCode.code == code)) + if ((code == SccNone) || (vec[ix]->error.code == code)) { return vec[ix]; } @@ -161,7 +161,7 @@ void ContextElementResponseVector::fill(EntityVector& erV, HttpStatusCode sc) { ContextElementResponse* cerP = new ContextElementResponse(erV[ix]); - cerP->statusCode.fill(sc, erV[ix]->entityId.id); + cerP->error.fill(sc, erV[ix]->entityId.id); push_back(cerP); } diff --git a/src/lib/ngsi/StatusCode.cpp b/src/lib/ngsi/StatusCode.cpp deleted file mode 100644 index 0abedc9706..0000000000 --- a/src/lib/ngsi/StatusCode.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/string.h" -#include "common/JsonHelper.h" -#include "common/limits.h" -#include "ngsi/Request.h" -#include "ngsi/StatusCode.h" -#include "ngsi10/UpdateContextResponse.h" -#include "rest/HttpStatusCode.h" - - - -/* **************************************************************************** -* -* StatusCode::StatusCode - -*/ -StatusCode::StatusCode() -{ - code = SccNone; - reasonPhrase = ""; - details = ""; -} - - - - -/* **************************************************************************** -* -* StatusCode::toJson - -* -* For version 2 of the API, based on OrionError. -*/ -std::string StatusCode::toJson(void) -{ - OrionError oe(code, details, reasonPhrase); - return oe.toJson(); -} - - - -/* **************************************************************************** -* -* StatusCode::fill - -*/ -void StatusCode::fill(HttpStatusCode _code, const std::string& _details) -{ - code = _code; - reasonPhrase = httpStatusCodeString(code); - details = _details; -} - - - -/* **************************************************************************** -* -* StatusCode::fill - -*/ -void StatusCode::fill(StatusCode* scP) -{ - fill(scP->code, scP->details); -} - - - -/* **************************************************************************** -* -* StatusCode::fill - -*/ -void StatusCode::fill(const StatusCode& sc) -{ - fill(sc.code, sc.details); -} - - - -/* **************************************************************************** -* -* release - -* -* FIXME PR: rellay needed? -*/ -void StatusCode::release(void) -{ - code = SccNone; - reasonPhrase = ""; - details = ""; -} - diff --git a/src/lib/ngsi/StatusCode.h b/src/lib/ngsi/StatusCode.h deleted file mode 100644 index a89d05a731..0000000000 --- a/src/lib/ngsi/StatusCode.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef SRC_LIB_NGSI_STATUSCODE_H_ -#define SRC_LIB_NGSI_STATUSCODE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/Request.h" -#include "rest/HttpStatusCode.h" - - - -/* **************************************************************************** -* -* Incomplete type declarations -*/ -struct UpdateContextResponse; - - - -/* **************************************************************************** -* -* StatusCode - -* -* FIXME PR: merge into OrionError class -*/ -typedef struct StatusCode -{ - HttpStatusCode code; // Mandatory - std::string reasonPhrase; // Mandatory - std::string details; // Optional - - StatusCode(); - - std::string toJson(void); - void fill(HttpStatusCode _code, const std::string& _details = ""); - void fill(StatusCode* scP); - void fill(const StatusCode& sc); - void release(void); - -} StatusCode; - -#endif // SRC_LIB_NGSI_STATUSCODE_H_ diff --git a/src/lib/ngsi10/NotifyContextResponse.cpp b/src/lib/ngsi10/NotifyContextResponse.cpp index 6c6d1760ad..a02d7ac94c 100644 --- a/src/lib/ngsi10/NotifyContextResponse.cpp +++ b/src/lib/ngsi10/NotifyContextResponse.cpp @@ -29,7 +29,7 @@ #include "logMsg/traceLevels.h" #include "common/globals.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "ngsi10/NotifyContextResponse.h" #include "rest/HttpStatusCode.h" @@ -41,18 +41,5 @@ */ NotifyContextResponse::NotifyContextResponse() { - responseCode.fill(SccOk); -} - - - -/* **************************************************************************** -* -* NotifyContextResponse::release - -* -* FIXME PR: this method is not called (it can be removed without compilation errors). Possible memory leak? -*/ -void NotifyContextResponse::release(void) -{ - responseCode.release(); + error.fill(SccOk); } diff --git a/src/lib/ngsi10/NotifyContextResponse.h b/src/lib/ngsi10/NotifyContextResponse.h index 3b36365a55..79cfa1ca38 100644 --- a/src/lib/ngsi10/NotifyContextResponse.h +++ b/src/lib/ngsi10/NotifyContextResponse.h @@ -29,7 +29,7 @@ #include #include "ngsi/Request.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" @@ -37,14 +37,14 @@ * * NotifyContextResponse - * +* FIXME: class really needed? */ typedef struct NotifyContextResponse { - StatusCode responseCode; // Mandatory + OrionError error; // Mandatory NotifyContextResponse(); - void release(void); } NotifyContextResponse; #endif // SRC_LIB_NGSI10_NOTIFYCONTEXTRESPONSE_H_ diff --git a/src/lib/ngsi10/QueryContextResponse.cpp b/src/lib/ngsi10/QueryContextResponse.cpp index c3b87ff0e7..64a1a4dea4 100644 --- a/src/lib/ngsi10/QueryContextResponse.cpp +++ b/src/lib/ngsi10/QueryContextResponse.cpp @@ -31,7 +31,7 @@ #include "common/errorMessages.h" #include "alarmMgr/alarmMgr.h" #include "rest/HttpStatusCode.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "ngsi10/QueryContextResponse.h" @@ -52,7 +52,6 @@ QueryContextResponse::QueryContextResponse() */ QueryContextResponse::~QueryContextResponse() { - errorCode.release(); contextElementResponseVector.release(); } @@ -65,7 +64,6 @@ QueryContextResponse::~QueryContextResponse() void QueryContextResponse::release(void) { contextElementResponseVector.release(); - errorCode.release(); } @@ -99,22 +97,22 @@ void QueryContextResponse::fill(const EntityVector& entities) */ ContextAttribute* QueryContextResponse::getAttr(const std::string& attrName, OrionError* oeP) { - if (errorCode.code == SccContextElementNotFound) + if (error.code == SccContextElementNotFound) { oeP->fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY, ERROR_NOT_FOUND); return NULL; } - if (errorCode.code != SccOk) + if (error.code != SccOk) { // // any other error distinct from Not Found // - oeP->fill(errorCode.code, errorCode.details, errorCode.reasonPhrase); + oeP->fill(error.code, error.description, error.error); return NULL; } - if (contextElementResponseVector.size() > 1) // errorCode.code == SccOk + if (contextElementResponseVector.size() > 1) // error.code == SccOk { // // If there are more than one entity, we return an error diff --git a/src/lib/ngsi10/QueryContextResponse.h b/src/lib/ngsi10/QueryContextResponse.h index 3e36be0d39..82deb20f1e 100644 --- a/src/lib/ngsi10/QueryContextResponse.h +++ b/src/lib/ngsi10/QueryContextResponse.h @@ -30,7 +30,7 @@ #include #include "ngsi/ContextElementResponseVector.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" @@ -45,7 +45,7 @@ typedef struct QueryContextResponse { ContextElementResponseVector contextElementResponseVector; // Optional - StatusCode errorCode; // Optional + OrionError error; // Optional QueryContextResponse(); ~QueryContextResponse(); diff --git a/src/lib/ngsi10/UpdateContextResponse.cpp b/src/lib/ngsi10/UpdateContextResponse.cpp index 8704d6a23c..995af4129c 100644 --- a/src/lib/ngsi10/UpdateContextResponse.cpp +++ b/src/lib/ngsi10/UpdateContextResponse.cpp @@ -33,7 +33,7 @@ #include "alarmMgr/alarmMgr.h" #include "ngsi/ContextElementResponse.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "ngsi10/UpdateContextResponse.h" @@ -54,7 +54,6 @@ UpdateContextResponse::UpdateContextResponse() */ UpdateContextResponse::~UpdateContextResponse() { - errorCode.release(); contextElementResponseVector.release(); LM_T(LmtDestructor, ("destroyed")); } @@ -69,7 +68,6 @@ void UpdateContextResponse::release(void) { LM_T(LmtRelease, ("In UpdateContextResponse::release")); contextElementResponseVector.release(); - errorCode.release(); } @@ -82,7 +80,7 @@ void UpdateContextResponse::release(void) * 2. If not found: create a new one. * */ -void UpdateContextResponse::notFoundPush(Entity* eP, ContextAttribute* aP, StatusCode* scP) +void UpdateContextResponse::notFoundPush(Entity* eP, ContextAttribute* aP, OrionError* oeP) { ContextElementResponse* cerP = contextElementResponseVector.lookup(eP, SccContextElementNotFound); @@ -98,13 +96,13 @@ void UpdateContextResponse::notFoundPush(Entity* eP, ContextAttribute* aP, Statu cerP->entity.attributeVector.push_back(new ContextAttribute(aP)); } - if (scP != NULL) + if (oeP != NULL) { - cerP->statusCode.fill(scP); + cerP->error.fill(oeP); } else { - cerP->statusCode.fill(SccContextElementNotFound, eP->entityId.id); + cerP->error.fill(SccContextElementNotFound, eP->entityId.id); } contextElementResponseVector.push_back(cerP); @@ -142,7 +140,7 @@ void UpdateContextResponse::foundPush(Entity* eP, ContextAttribute* aP) cerP->entity.attributeVector.push_back(new ContextAttribute(aP)); } - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); contextElementResponseVector.push_back(cerP); } else @@ -160,7 +158,7 @@ void UpdateContextResponse::foundPush(Entity* eP, ContextAttribute* aP) void UpdateContextResponse::fill(UpdateContextResponse* upcrsP) { contextElementResponseVector.fill(upcrsP->contextElementResponseVector); - errorCode.fill(upcrsP->errorCode); + error.fill(upcrsP->error); } @@ -172,8 +170,9 @@ void UpdateContextResponse::fill(UpdateContextRequest* upcrP, HttpStatusCode sc) { contextElementResponseVector.fill(upcrP->entityVector, sc); - // Note that "external" StatusCode is always SccOk, sc is not used here - errorCode.fill(SccOk); + // Note that "external" OrionError is always SccOk, sc is not used here + // FIXME PR: internal error should be avoided. Review this + error.fill(sc, ""); } @@ -191,28 +190,28 @@ void UpdateContextResponse::merge(UpdateContextResponse* upcrsP) if (upcrsP->contextElementResponseVector.size() == 0) { // If no contextElementResponses, copy errorCode if empty - if ((errorCode.code == SccNone) || (errorCode.code == SccOk)) + if ((error.code == SccNone) || (error.code == SccOk)) { - errorCode.fill(upcrsP->errorCode); + error.fill(upcrsP->error); } - else if (errorCode.details.empty()) + else if (error.description.empty()) { - errorCode.details = upcrsP->errorCode.details; + error.description = upcrsP->error.description; } } for (unsigned int cerIx = 0; cerIx < upcrsP->contextElementResponseVector.size(); ++cerIx) { Entity* eP = &upcrsP->contextElementResponseVector[cerIx]->entity; - StatusCode* scP = &upcrsP->contextElementResponseVector[cerIx]->statusCode; + OrionError* oeP = &upcrsP->contextElementResponseVector[cerIx]->error; for (unsigned int aIx = 0; aIx < eP->attributeVector.size(); ++aIx) { ContextAttribute* aP = eP->attributeVector[aIx]; - if (scP->code != SccOk) + if (oeP->code != SccOk) { - notFoundPush(eP, aP, scP); + notFoundPush(eP, aP, oeP); } else { diff --git a/src/lib/ngsi10/UpdateContextResponse.h b/src/lib/ngsi10/UpdateContextResponse.h index 98533de4b0..0ccc2dd55c 100644 --- a/src/lib/ngsi10/UpdateContextResponse.h +++ b/src/lib/ngsi10/UpdateContextResponse.h @@ -29,11 +29,8 @@ #include #include "ngsi/ContextElementResponseVector.h" -#include "ngsi/StatusCode.h" -#include "ngsi10/UpdateContextRequest.h" - #include "rest/OrionError.h" - +#include "ngsi10/UpdateContextRequest.h" /* **************************************************************************** @@ -43,9 +40,7 @@ typedef struct UpdateContextResponse { ContextElementResponseVector contextElementResponseVector; // Optional - StatusCode errorCode; // Optional - - OrionError oe; // Used by NGSIv2 + OrionError error; UpdateContextResponse(); ~UpdateContextResponse(); @@ -53,7 +48,7 @@ typedef struct UpdateContextResponse void release(void); void fill(UpdateContextResponse* upcrsP); void fill(UpdateContextRequest* upcrP, HttpStatusCode sc); // Needed by NGSIv2 forwarding logic - void notFoundPush(Entity* eP, ContextAttribute* aP, StatusCode* scP); + void notFoundPush(Entity* eP, ContextAttribute* aP, OrionError* oeP); void foundPush(Entity* eP, ContextAttribute* aP); void merge(UpdateContextResponse* upcrsP); } UpdateContextResponse; diff --git a/src/lib/ngsiNotify/Notifier.cpp b/src/lib/ngsiNotify/Notifier.cpp index 795d3c738a..1c3f251c6a 100644 --- a/src/lib/ngsiNotify/Notifier.cpp +++ b/src/lib/ngsiNotify/Notifier.cpp @@ -148,7 +148,7 @@ static bool setPayload // described in issue #4263 will happend cer.entity.attributeVector.push_back(en.attributeVector, true); - cer.statusCode.code = SccOk; + cer.error.code = SccOk; ncr.subscriptionId = subscriptionId; ncr.contextElementResponseVector.push_back(&cer); @@ -313,7 +313,7 @@ static bool setNgsiPayload } } - cer.statusCode.code = SccOk; + cer.error.code = SccOk; ncr.subscriptionId = subscriptionId; ncr.contextElementResponseVector.push_back(&cer); @@ -716,7 +716,7 @@ SenderThreadParams* Notifier::buildSenderParams /* Note we use cloneCompound=true in cer.entity.fill(). This is due to * cer.entity destructor does release() on the attrs vector */ cer.entity.fill(notifyCerP->entity, false, true); - cer.statusCode.fill(SccOk); + cer.error.fill(SccOk); ncr.contextElementResponseVector.push_back(&cer); diff --git a/src/lib/orionTypes/EntityTypeResponse.cpp b/src/lib/orionTypes/EntityTypeResponse.cpp index b850ed6d81..a56988eaf0 100755 --- a/src/lib/orionTypes/EntityTypeResponse.cpp +++ b/src/lib/orionTypes/EntityTypeResponse.cpp @@ -46,7 +46,6 @@ void EntityTypeResponse::release(void) { entityType.release(); - statusCode.release(); } diff --git a/src/lib/orionTypes/EntityTypeResponse.h b/src/lib/orionTypes/EntityTypeResponse.h index 26046b4b31..645c11587b 100644 --- a/src/lib/orionTypes/EntityTypeResponse.h +++ b/src/lib/orionTypes/EntityTypeResponse.h @@ -29,7 +29,7 @@ #include #include "ngsi/Request.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "orionTypes/EntityType.h" @@ -42,7 +42,7 @@ class EntityTypeResponse { public: EntityType entityType; - StatusCode statusCode; + OrionError error; std::string toJson(void); void release(void); diff --git a/src/lib/orionTypes/EntityTypeVectorResponse.cpp b/src/lib/orionTypes/EntityTypeVectorResponse.cpp index 08f6c16809..0194f624b1 100755 --- a/src/lib/orionTypes/EntityTypeVectorResponse.cpp +++ b/src/lib/orionTypes/EntityTypeVectorResponse.cpp @@ -45,7 +45,6 @@ void EntityTypeVectorResponse::release(void) { entityTypeVector.release(); - statusCode.release(); } diff --git a/src/lib/orionTypes/EntityTypeVectorResponse.h b/src/lib/orionTypes/EntityTypeVectorResponse.h index 63752799f5..614b33620e 100644 --- a/src/lib/orionTypes/EntityTypeVectorResponse.h +++ b/src/lib/orionTypes/EntityTypeVectorResponse.h @@ -29,7 +29,7 @@ #include #include "ngsi/Request.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "orionTypes/EntityTypeVector.h" @@ -42,7 +42,7 @@ class EntityTypeVectorResponse { public: EntityTypeVector entityTypeVector; - StatusCode statusCode; + OrionError error; void release(void); std::string toJson(bool values); diff --git a/src/lib/orionTypes/QueryContextResponseVector.cpp b/src/lib/orionTypes/QueryContextResponseVector.cpp index 35877ec3d8..f2464819c1 100644 --- a/src/lib/orionTypes/QueryContextResponseVector.cpp +++ b/src/lib/orionTypes/QueryContextResponseVector.cpp @@ -101,7 +101,7 @@ void QueryContextResponseVector::populate(QueryContextResponse* responseP) // // Special case: vector is empty: translate to 404 // - responseP->errorCode.fill(SccContextElementNotFound); + responseP->error.fill(SccContextElementNotFound); } else if ((vec.size() == 1) && (vec[0]->contextElementResponseVector.size() == 0)) { @@ -109,15 +109,15 @@ void QueryContextResponseVector::populate(QueryContextResponse* responseP) // Special case: only one QueryContextResponse in vec, and it has 0 contextElementResponses // This is clearly a Not Found ... // - responseP->errorCode.fill(SccContextElementNotFound); - vec[0]->errorCode.fill(SccContextElementNotFound); + responseP->error.fill(SccContextElementNotFound); + vec[0]->error.fill(SccContextElementNotFound); } else { // // We have found something, so, all good // - responseP->errorCode.fill(SccOk); + responseP->error.fill(SccOk); } for (unsigned int qIx = 0; qIx < vec.size(); ++qIx) @@ -128,11 +128,11 @@ void QueryContextResponseVector::populate(QueryContextResponse* responseP) // if (vec[qIx]->contextElementResponseVector.size() == 0) { - if ((vec[qIx]->errorCode.code == SccOk) || (vec[qIx]->errorCode.code == SccNone)) + if ((vec[qIx]->error.code == SccOk) || (vec[qIx]->error.code == SccNone)) { ContextElementResponse* cerP = new ContextElementResponse(); - cerP->statusCode.fill(SccContextElementNotFound); + cerP->error.fill(SccContextElementNotFound); responseP->contextElementResponseVector.push_back(cerP); } } @@ -141,7 +141,7 @@ void QueryContextResponseVector::populate(QueryContextResponse* responseP) { ContextElementResponse* cerP = vec[qIx]->contextElementResponseVector[cerIx]; - if ((cerP->statusCode.code != SccOk) && (cerP->statusCode.code != SccNone)) // Error - not to be added to output + if ((cerP->error.code != SccOk) && (cerP->error.code != SccNone)) // Error - not to be added to output { continue; } @@ -160,7 +160,7 @@ void QueryContextResponseVector::populate(QueryContextResponse* responseP) { ContextElementResponse* newCerP = new ContextElementResponse(cerP); - newCerP->statusCode.fill(SccOk); + newCerP->error.fill(SccOk); responseP->contextElementResponseVector.push_back(newCerP); } } diff --git a/src/lib/rest/OrionError.cpp b/src/lib/rest/OrionError.cpp index 59db1973c1..991c99d17e 100644 --- a/src/lib/rest/OrionError.cpp +++ b/src/lib/rest/OrionError.cpp @@ -28,7 +28,6 @@ #include "common/string.h" #include "common/JsonHelper.h" #include "rest/ConnectionInfo.h" -#include "ngsi/StatusCode.h" #include "rest/OrionError.h" @@ -61,15 +60,16 @@ OrionError::OrionError(HttpStatusCode _code, const std::string& _description, co + /* **************************************************************************** * -* OrionError::OrionError - +* OrionError::fill - */ -OrionError::OrionError(StatusCode& sc) +void OrionError::fill(HttpStatusCode _code, const std::string& _description, const std::string& _error) { - code = sc.code; - error = httpStatusCodeString(code); - description = sc.details; + code = _code; + error = _error.empty()? httpStatusCodeString(code) : _error; + description = _description; filled = true; } @@ -79,12 +79,20 @@ OrionError::OrionError(StatusCode& sc) * * OrionError::fill - */ -void OrionError::fill(HttpStatusCode _code, const std::string& _description, const std::string& _error) +void OrionError::fill(const OrionError& oe) { - code = _code; - error = _error.empty()? httpStatusCodeString(code) : _error; - description = _description; - filled = true; + fill(oe.code, oe.description, oe.error); +} + + + +/* **************************************************************************** +* +* OrionError::fill - +*/ +void OrionError::fill(OrionError* oeP) +{ + fill(oeP->code, oeP->description, oeP->error); } diff --git a/src/lib/rest/OrionError.h b/src/lib/rest/OrionError.h index b62e2ac04d..5e8fd7c516 100644 --- a/src/lib/rest/OrionError.h +++ b/src/lib/rest/OrionError.h @@ -29,7 +29,7 @@ #include "common/globals.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "rest/HttpStatusCode.h" @@ -47,13 +47,13 @@ typedef struct OrionError bool filled; OrionError(); - OrionError(StatusCode& statusCode); OrionError(HttpStatusCode _code, const std::string& _description = "", const std::string& _error = ""); - std::string smartRender(void); std::string setSCAndRender(HttpStatusCode* scP); std::string toJson(void); void fill(HttpStatusCode _code, const std::string& _description, const std::string& _error = ""); + void fill(const OrionError& oe); + void fill(OrionError* oeP); void fillOrAppend(HttpStatusCode _code, const std::string& fullDetails, const std::string& appendDetail, const std::string& _error); } OrionError; diff --git a/src/lib/rest/restReply.cpp b/src/lib/rest/restReply.cpp index abdb79f16e..dae9891410 100644 --- a/src/lib/rest/restReply.cpp +++ b/src/lib/rest/restReply.cpp @@ -28,7 +28,6 @@ #include "common/MimeType.h" #include "common/limits.h" -#include "ngsi/StatusCode.h" #include "metricsMgr/metricsMgr.h" #include "ngsi10/QueryContextResponse.h" diff --git a/src/lib/serviceRoutines/postQueryContext.cpp b/src/lib/serviceRoutines/postQueryContext.cpp index fe2771434c..cd98780df6 100644 --- a/src/lib/serviceRoutines/postQueryContext.cpp +++ b/src/lib/serviceRoutines/postQueryContext.cpp @@ -131,7 +131,7 @@ static void getProviderCount(std::string cpResponse, long long* totalCount) * 3. Send the request to the providing application (and await the response) * 4. Parse the response and fill in a binary QueryContextResponse * 5. Fill in the response from the redirection into the response of this function -* 6. 'Fix' StatusCode +* 6. 'Fix' OrionError * 7. Freeing memory * */ @@ -405,15 +405,15 @@ static bool queryForward } else { - qcrsP->errorCode.fill(SccContextElementNotFound); + qcrsP->error.fill(SccContextElementNotFound); } // - // 6. 'Fix' StatusCode + // 6. 'Fix' OrionError // - if (qcrsP->errorCode.code == SccNone) + if (qcrsP->error.code == SccNone) { - qcrsP->errorCode.fill(SccOk); + qcrsP->error.fill(SccOk); } @@ -496,7 +496,7 @@ void postQueryContext // // 01. Call mongoBackend/mongoQueryContext // - qcrsP->errorCode.fill(SccOk); + qcrsP->error.fill(SccOk); TIMED_MONGO(ciP->httpStatusCode = mongoQueryContext(qcrP, qcrsP, @@ -506,10 +506,10 @@ void postQueryContext ciP->uriParamOptions, countP)); - if ((qcrsP->errorCode.code == SccBadRequest) || (qcrsP->errorCode.code == SccReceiverInternalError)) + if ((qcrsP->error.code == SccBadRequest) || (qcrsP->error.code == SccReceiverInternalError)) { // Bad Input or Internal Error detected by Mongo Backend - request ends here ! - OrionError oe(qcrsP->errorCode); + OrionError oe(qcrsP->error); qcrP->release(); return; @@ -726,7 +726,7 @@ void postQueryContext } qP = new QueryContextResponse(); - qP->errorCode.fill(SccOk); + qP->error.fill(SccOk); if (queryForward(ciP, requestV[fIx], regIdsV[fIx], providerLimit, providerOffset, countP, fIx + 1, qP) == true) { @@ -750,7 +750,7 @@ void postQueryContext } else { - qP->errorCode.fill(SccContextElementNotFound, "invalid context provider response"); + qP->error.fill(SccContextElementNotFound, "invalid context provider response"); responseV.push_back(qP); } } diff --git a/src/lib/serviceRoutines/postUpdateContext.cpp b/src/lib/serviceRoutines/postUpdateContext.cpp index 80a07a8f26..2e9dfe1dfb 100644 --- a/src/lib/serviceRoutines/postUpdateContext.cpp +++ b/src/lib/serviceRoutines/postUpdateContext.cpp @@ -98,7 +98,7 @@ static bool forwardsPending(UpdateContextResponse* upcrsP) * 3. Send the request to the providing application (and await the response) * 4. Parse the response and fill in a binary UpdateContextResponse * 5. Fill in the response from the redirection into the response of this function -* 6. 'Fix' StatusCode +* 6. 'Fix' OrionError * 7. Freeing memory * */ @@ -128,7 +128,7 @@ static bool updateForward // Somehow, if we accepted this providing application, it is the brokers fault ... // SccBadRequest should have been returned before, when it was registered! // - upcrsP->errorCode.fill(SccContextElementNotFound, ""); + upcrsP->error.fill(SccContextElementNotFound, ""); return false; } @@ -230,7 +230,7 @@ static bool updateForward if (r != 0) { - upcrsP->errorCode.fill(SccContextElementNotFound, "error forwarding update"); + upcrsP->error.fill(SccContextElementNotFound, "error forwarding update"); logInfoFwdRequest(regId.c_str(), verb.c_str(), (upcrP->contextProvider + op).c_str(), payload.c_str(), "", out.c_str()); alarmMgr.forwardingError(url, "forwarding failure for sender-thread: " + out); return false; @@ -242,11 +242,13 @@ static bool updateForward LM_T(LmtCPrForwardResponsePayload, ("forward updateContext response payload: %s", out.c_str())); + cleanPayload = jsonPayloadClean(out.c_str()); + // // If NGSIv1 (legacyProviderFormat): // 4. Parse the response and fill in a binary UpdateContextResponse // 5. Fill in the response from the redirection into the response of this function - // 6. 'Fix' StatusCode + // 6. 'Fix' OrionError // 7. Free up memory // // If NGSIv2: @@ -262,8 +264,6 @@ static bool updateForward EntityVector entities; OrionError oe; - cleanPayload = jsonPayloadClean(out.c_str()); - if ((cleanPayload == NULL) || (cleanPayload[0] == 0)) { // @@ -271,7 +271,7 @@ static bool updateForward // It is not in the orion broker though, so 404 is returned // alarmMgr.forwardingError(url, "context provider response to UpdateContext is empty"); - upcrsP->errorCode.fill(SccContextElementNotFound, "invalid context provider response"); + upcrsP->error.fill(SccContextElementNotFound, "invalid context provider response"); return false; } @@ -289,14 +289,14 @@ static bool updateForward ciP->verb = POST; ciP->method = "POST"; - parseData.upcrs.res.errorCode.fill(SccOk); + parseData.upcrs.res.error.fill(SccOk); result = parseEntitiesResponseV1(ciP, cleanPayload, &entities, &oe); if (!result) { alarmMgr.forwardingError(url, "error parsing reply from context provider: " + oe.error + " (" + oe.description + ")"); - upcrsP->errorCode.fill(SccContextElementNotFound, ""); + upcrsP->error.fill(SccContextElementNotFound, ""); parseData.upcr.res.release(); parseData.upcrs.res.release(); return false; @@ -310,16 +310,16 @@ static bool updateForward // - // 6. 'Fix' StatusCode + // 6. 'Fix' OrionError // - if (upcrsP->errorCode.code == SccNone) + if (upcrsP->error.code == SccNone) { - upcrsP->errorCode.fill(SccOk); + upcrsP->error.fill(SccOk); } - if ((upcrsP->contextElementResponseVector.size() == 1) && (upcrsP->contextElementResponseVector[0]->statusCode.code == SccContextElementNotFound)) + if ((upcrsP->contextElementResponseVector.size() == 1) && (upcrsP->contextElementResponseVector[0]->error.code == SccContextElementNotFound)) { - upcrsP->errorCode.fill(SccContextElementNotFound); + upcrsP->error.fill(SccContextElementNotFound); } // @@ -334,7 +334,7 @@ static bool updateForward { // NGSIv2 forward - no payload to be received - logInfoFwdRequest(regId.c_str(), verb.c_str(), (upcrP->contextProvider + op).c_str(), payload.c_str(), "", statusCode); + logInfoFwdRequest(regId.c_str(), verb.c_str(), (upcrP->contextProvider + op).c_str(), payload.c_str(), cleanPayload, statusCode); if (statusCode == SccNoContent) { @@ -349,7 +349,7 @@ static bool updateForward } alarmMgr.forwardingError(url, "unexpected response from context provider: %s" + out); - upcrsP->errorCode.fill(SccReceiverInternalError); + upcrsP->error.fill(SccReceiverInternalError); return false; } @@ -398,9 +398,9 @@ static void foundAndNotFoundAttributeSeparation(UpdateContextResponse* upcrsP, U // if ((noOfFounds == 0) && (noOfNotFounds > 0)) { - if ((cerP->statusCode.code == SccOk) || (cerP->statusCode.code == SccNone)) + if ((cerP->error.code == SccOk) || (cerP->error.code == SccNone)) { - cerP->statusCode.fill(SccContextElementNotFound, cerP->entity.entityId.id); + cerP->error.fill(SccContextElementNotFound, cerP->entity.entityId.id); } } else if ((noOfFounds > 0) && (noOfNotFounds > 0)) @@ -411,14 +411,14 @@ static void foundAndNotFoundAttributeSeparation(UpdateContextResponse* upcrsP, U notFoundCerP->entity.fill(cerP->entity.entityId); // - // Filling in StatusCode (SccContextElementNotFound) for NotFound + // Filling in OrionError (SccContextElementNotFound) for NotFound // - notFoundCerP->statusCode.fill(SccContextElementNotFound, cerP->entity.entityId.id); + notFoundCerP->error.fill(SccContextElementNotFound, cerP->entity.entityId.id); // - // Setting StatusCode to OK for Found + // Setting OrionError to OK for Found // - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); // // And, pushing to NotFound-vector @@ -446,11 +446,11 @@ static void foundAndNotFoundAttributeSeparation(UpdateContextResponse* upcrsP, U } // - // Add EntityId::id to StatusCode::details if 404, but only if StatusCode::details is empty + // Add EntityId::id to OrionError::details if 404, but only if OrionError::description is empty // - if ((cerP->statusCode.code == SccContextElementNotFound) && (cerP->statusCode.details.empty())) + if ((cerP->error.code == SccContextElementNotFound) && (cerP->error.description.empty())) { - cerP->statusCode.details = cerP->entity.entityId.id; + cerP->error.description = cerP->entity.entityId.id; } } @@ -473,9 +473,9 @@ static void foundAndNotFoundAttributeSeparation(UpdateContextResponse* upcrsP, U { if (upcrsP->contextElementResponseVector.size() == 0) { - if (upcrsP->errorCode.code == SccOk) + if (upcrsP->error.code == SccOk) { - upcrsP->errorCode.fill(SccContextElementNotFound, upcrP->entityVector[0]->entityId.id); + upcrsP->error.fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY); } } } @@ -485,17 +485,19 @@ static void foundAndNotFoundAttributeSeparation(UpdateContextResponse* upcrsP, U // Add entityId::id to details if Not Found and only one element in response. // And, if 0 elements in response, take entityId::id from the request. // - if (upcrsP->errorCode.code == SccContextElementNotFound) + // FIXME PR: this should be no longer needed. == 0 is redundant (the previous fill does that) + // == 1 is no longer needed is we remove the "internal" OrionError + /*if (upcrsP->error.code == SccContextElementNotFound) { if (upcrsP->contextElementResponseVector.size() == 1) { - upcrsP->errorCode.details = upcrsP->contextElementResponseVector[0]->entity.entityId.id; + upcrsP->error.description = upcrsP->contextElementResponseVector[0]->entity.entityId.id; } else if (upcrsP->contextElementResponseVector.size() == 0) { - upcrsP->errorCode.details = upcrP->entityVector[0]->entityId.id; + upcrsP->error.description = upcrP->entityVector[0]->entityId.id; } - } + }*/ } @@ -555,7 +557,7 @@ void postUpdateContext // if (ciP->servicePathV.size() > 1) { - upcrsP->errorCode.fill(SccBadRequest, "more than one service path in context update request"); + upcrsP->error.fill(SccBadRequest, "more than one service path in context update request"); alarmMgr.badInput(clientIp, "more than one service path for an update request"); upcrP->release(); @@ -570,7 +572,7 @@ void postUpdateContext std::string res = servicePathCheck(ciP->servicePathV[0].c_str()); if (res != "OK") { - upcrsP->errorCode.fill(SccBadRequest, res); + upcrsP->error.fill(SccBadRequest, res); upcrP->release(); return; } @@ -579,7 +581,6 @@ void postUpdateContext // // 02. Send the request to mongoBackend/mongoUpdateContext // - upcrsP->errorCode.fill(SccOk); attributesToNotFound(upcrP); HttpStatusCode httpStatusCode; @@ -663,7 +664,7 @@ void postUpdateContext std::vector regIdsV; - response.errorCode.fill(SccOk); + response.error.fill(SccOk); for (unsigned int cerIx = 0; cerIx < upcrsP->contextElementResponseVector.size(); ++cerIx) { ContextElementResponse* cerP = upcrsP->contextElementResponseVector[cerIx]; @@ -790,7 +791,7 @@ void postUpdateContext { ContextElementResponse *cerP = response.contextElementResponseVector[ix]; - if (cerP->statusCode.code != SccOk) + if (cerP->error.code != SccOk) { failures++; @@ -809,16 +810,16 @@ void postUpdateContext } // - // Note that we modify parseDataP->upcrs.res.oe and not response.oe, as the former is the + // Note that we modify parseDataP->upcrs.res.error and not response.oe, as the former is the // one used by the calling postBatchUpdate() function at serviceRoutineV2 library // if ((forwardOk == true) && (failures == 0)) { - parseDataP->upcrs.res.oe.fill(SccNone, ""); + parseDataP->upcrs.res.error.fill(SccNone, ""); } else if (failures == response.contextElementResponseVector.size()) { - parseDataP->upcrs.res.oe.fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY, ERROR_NOT_FOUND); + parseDataP->upcrs.res.error.fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY, ERROR_NOT_FOUND); } else if (failures > 0) { @@ -826,12 +827,12 @@ void postUpdateContext failing = failing.substr(0, failing.size() - 2); // If some CER (but not all) fail, then it is a partial update - parseDataP->upcrs.res.oe.fill(SccContextElementNotFound, "Some of the following attributes were not updated: { " + failing + " }", ERROR_PARTIAL_UPDATE); + parseDataP->upcrs.res.error.fill(SccContextElementNotFound, "Some of the following attributes were not updated: { " + failing + " }", ERROR_PARTIAL_UPDATE); } else // failures == 0 { // No failure, so invalidate any possible OrionError filled by mongoBackend on the mongoUpdateContext step - parseDataP->upcrs.res.oe.fill(SccNone, ""); + parseDataP->upcrs.res.error.fill(SccNone, ""); } // @@ -840,7 +841,6 @@ void postUpdateContext upcrP->release(); requestV.release(); upcrsP->release(); - upcrsP->fill(&response); response.release(); return; diff --git a/src/lib/serviceRoutinesV2/deleteEntity.cpp b/src/lib/serviceRoutinesV2/deleteEntity.cpp index b0065a3b4d..009876bacd 100644 --- a/src/lib/serviceRoutinesV2/deleteEntity.cpp +++ b/src/lib/serviceRoutinesV2/deleteEntity.cpp @@ -91,16 +91,16 @@ std::string deleteEntity postUpdateContext(ciP, components, compV, parseDataP); // Adjust error code if needed - adaptErrorCodeForSingleEntityOperation(&(parseDataP->upcrs.res.oe), true); + adaptErrorCodeForSingleEntityOperation(&(parseDataP->upcrs.res.error), true); ciP->outMimeType = JSON; // Check for potential error string answer = ""; - if (parseDataP->upcrs.res.oe.code != SccNone ) + if ((parseDataP->upcrs.res.error.code != SccNone ) && (parseDataP->upcrs.res.error.code != SccOk)) { - TIMED_RENDER(answer = parseDataP->upcrs.res.oe.toJson()); - ciP->httpStatusCode = parseDataP->upcrs.res.oe.code; + TIMED_RENDER(answer = parseDataP->upcrs.res.error.toJson()); + ciP->httpStatusCode = parseDataP->upcrs.res.error.code; } else { diff --git a/src/lib/serviceRoutinesV2/getEntities.cpp b/src/lib/serviceRoutinesV2/getEntities.cpp index aa41db5f54..7c0b8bcf66 100644 --- a/src/lib/serviceRoutinesV2/getEntities.cpp +++ b/src/lib/serviceRoutinesV2/getEntities.cpp @@ -56,7 +56,7 @@ */ static void fillEntityVector(const QueryContextResponse& qcrs, EntityVector* enVP, OrionError* oeP) { - if (qcrs.errorCode.code == SccContextElementNotFound) + if (qcrs.error.code == SccContextElementNotFound) { // // If no entities are found, we respond with a 200 OK @@ -66,28 +66,27 @@ static void fillEntityVector(const QueryContextResponse& qcrs, EntityVector* enV oeP->fill(SccOk, "", "OK"); return; } - else if (qcrs.errorCode.code != SccOk) + else if (qcrs.error.code != SccOk) { // // If any other error - use the error for the response // - oeP->fill(qcrs.errorCode.code, qcrs.errorCode.details, qcrs.errorCode.reasonPhrase); + oeP->fill(qcrs.error.code, qcrs.error.description, qcrs.error.error); return; } for (unsigned int ix = 0; ix < qcrs.contextElementResponseVector.size(); ++ix) { Entity* eP = &qcrs.contextElementResponseVector[ix]->entity; - StatusCode* scP = &qcrs.contextElementResponseVector[ix]->statusCode; - if (scP->code == SccReceiverInternalError) + if ((&qcrs.contextElementResponseVector[ix]->error)->code == SccReceiverInternalError) { // FIXME P4: Do we need to release the memory allocated in 'vec' before returning? I don't // think so, as the releasing logic in the upper layer will deal with that but // let's do anyway just in case... (we don't have a ft covering this, so valgrind suite // cannot help here and it is better to ensure) - oeP->fill(SccReceiverInternalError, scP->details, "InternalServerError"); + oeP->fill(&qcrs.contextElementResponseVector[ix]->error); enVP->release(); return; } @@ -369,7 +368,7 @@ std::string getEntities postQueryContext(ciP, components, compV, parseDataP); // 03. Check Internal Errors - if (parseDataP->qcrs.res.errorCode.code == SccReceiverInternalError) + if (parseDataP->qcrs.res.error.code == SccReceiverInternalError) { OrionError oe; fillEntityVector(parseDataP->qcrs.res, &entities, &oe); diff --git a/src/lib/serviceRoutinesV2/getEntity.cpp b/src/lib/serviceRoutinesV2/getEntity.cpp index f2117d12f3..8add44a5e8 100644 --- a/src/lib/serviceRoutinesV2/getEntity.cpp +++ b/src/lib/serviceRoutinesV2/getEntity.cpp @@ -116,7 +116,7 @@ std::string getEntity parseDataP->qcr.res.metadataList.stringV)); // response code the same of the wrapped operation - ciP->httpStatusCode = parseDataP->qcrs.res.errorCode.code; + ciP->httpStatusCode = parseDataP->qcrs.res.error.code; } else { diff --git a/src/lib/serviceRoutinesV2/getEntityAttribute.cpp b/src/lib/serviceRoutinesV2/getEntityAttribute.cpp index 545125171e..854fd44375 100644 --- a/src/lib/serviceRoutinesV2/getEntityAttribute.cpp +++ b/src/lib/serviceRoutinesV2/getEntityAttribute.cpp @@ -113,7 +113,7 @@ std::string getEntityAttribute else { // the same of the wrapped operation - ciP->httpStatusCode = parseDataP->qcrs.res.errorCode.code; + ciP->httpStatusCode = parseDataP->qcrs.res.error.code; } // 04. Cleanup and return result diff --git a/src/lib/serviceRoutinesV2/getEntityAttributeValue.cpp b/src/lib/serviceRoutinesV2/getEntityAttributeValue.cpp index c41899896f..0110d4edbc 100644 --- a/src/lib/serviceRoutinesV2/getEntityAttributeValue.cpp +++ b/src/lib/serviceRoutinesV2/getEntityAttributeValue.cpp @@ -94,7 +94,7 @@ std::string getEntityAttributeValue std::string attributeType = caP->type; // the same of the wrapped operation - ciP->httpStatusCode = parseDataP->qcrs.res.errorCode.code; + ciP->httpStatusCode = parseDataP->qcrs.res.error.code; // Remove unwanted fields from attribute before rendering caP->type = ""; diff --git a/src/lib/serviceRoutinesV2/patchEntity.cpp b/src/lib/serviceRoutinesV2/patchEntity.cpp index d0a57b4e98..d88c752819 100644 --- a/src/lib/serviceRoutinesV2/patchEntity.cpp +++ b/src/lib/serviceRoutinesV2/patchEntity.cpp @@ -86,13 +86,13 @@ std::string patchEntity postUpdateContext(ciP, components, compV, parseDataP); // Adjust error code if needed - adaptErrorCodeForSingleEntityOperation(&(parseDataP->upcrs.res.oe), false); + adaptErrorCodeForSingleEntityOperation(&(parseDataP->upcrs.res.error), false); // 03. Check output from mongoBackend - any errors? - if (parseDataP->upcrs.res.oe.code != SccNone ) + if ((parseDataP->upcrs.res.error.code != SccNone ) && (parseDataP->upcrs.res.error.code != SccOk)) { - TIMED_RENDER(answer = parseDataP->upcrs.res.oe.toJson()); - ciP->httpStatusCode = parseDataP->upcrs.res.oe.code; + TIMED_RENDER(answer = parseDataP->upcrs.res.error.toJson()); + ciP->httpStatusCode = parseDataP->upcrs.res.error.code; } else { diff --git a/src/lib/serviceRoutinesV2/postBatchQuery.cpp b/src/lib/serviceRoutinesV2/postBatchQuery.cpp index 5ff115c25d..3f84a3b05d 100644 --- a/src/lib/serviceRoutinesV2/postBatchQuery.cpp +++ b/src/lib/serviceRoutinesV2/postBatchQuery.cpp @@ -55,7 +55,7 @@ */ static void fillEntityVector(const QueryContextResponse& qcrs, EntityVector* enVP, OrionError* oeP) { - if (qcrs.errorCode.code == SccContextElementNotFound) + if (qcrs.error.code == SccContextElementNotFound) { // // If no entities are found, we respond with a 200 OK @@ -65,28 +65,27 @@ static void fillEntityVector(const QueryContextResponse& qcrs, EntityVector* enV oeP->fill(SccOk, "", "OK"); return; } - else if (qcrs.errorCode.code != SccOk) + else if (qcrs.error.code != SccOk) { // // If any other error - use the error for the response // - oeP->fill(qcrs.errorCode.code, qcrs.errorCode.details, qcrs.errorCode.reasonPhrase); + oeP->fill(qcrs.error.code, qcrs.error.description, qcrs.error.error); return; } for (unsigned int ix = 0; ix < qcrs.contextElementResponseVector.size(); ++ix) { Entity* eP = &qcrs.contextElementResponseVector[ix]->entity; - StatusCode* scP = &qcrs.contextElementResponseVector[ix]->statusCode; - if (scP->code == SccReceiverInternalError) + if ((&qcrs.contextElementResponseVector[ix]->error)->code == SccReceiverInternalError) { // FIXME P4: Do we need to release the memory allocated in 'vec' before returning? I don't // think so, as the releasing logic in the upper layer will deal with that but // let's do anyway just in case... (we don't have a ft covering this, so valgrind suite // cannot help here and it is better to ensure) - oeP->fill(SccReceiverInternalError, scP->details, "InternalServerError"); + oeP->fill(&qcrs.contextElementResponseVector[ix]->error); enVP->release(); return; } diff --git a/src/lib/serviceRoutinesV2/postBatchUpdate.cpp b/src/lib/serviceRoutinesV2/postBatchUpdate.cpp index 04e261181f..22871bfda8 100644 --- a/src/lib/serviceRoutinesV2/postBatchUpdate.cpp +++ b/src/lib/serviceRoutinesV2/postBatchUpdate.cpp @@ -86,10 +86,10 @@ std::string postBatchUpdate postUpdateContext(ciP, components, compV, parseDataP); // Check potential error - if (parseDataP->upcrs.res.oe.code != SccNone ) + if ((parseDataP->upcrs.res.error.code != SccNone ) && (parseDataP->upcrs.res.error.code != SccOk)) { - TIMED_RENDER(answer = parseDataP->upcrs.res.oe.toJson()); - ciP->httpStatusCode = parseDataP->upcrs.res.oe.code; + TIMED_RENDER(answer = parseDataP->upcrs.res.error.toJson()); + ciP->httpStatusCode = parseDataP->upcrs.res.error.code; } else { diff --git a/src/lib/serviceRoutinesV2/postEntities.cpp b/src/lib/serviceRoutinesV2/postEntities.cpp index 68312cd544..7ccb0247b7 100644 --- a/src/lib/serviceRoutinesV2/postEntities.cpp +++ b/src/lib/serviceRoutinesV2/postEntities.cpp @@ -124,15 +124,10 @@ std::string postEntities // FIXME P4: make postUpdateContext have ONE way to return errors. See github issue #2763 // std::string answer = ""; - if (parseDataP->upcrs.res.oe.code != SccNone) + if (parseDataP->upcrs.res.error.code != SccOk) { - TIMED_RENDER(answer = parseDataP->upcrs.res.oe.toJson()); - ciP->httpStatusCode = parseDataP->upcrs.res.oe.code; - } - else if (parseDataP->upcrs.res.errorCode.code != SccOk) - { - ciP->httpStatusCode = parseDataP->upcrs.res.errorCode.code; - TIMED_RENDER(answer = parseDataP->upcrs.res.errorCode.toJson()); + ciP->httpStatusCode = parseDataP->upcrs.res.error.code; + TIMED_RENDER(answer = parseDataP->upcrs.res.error.toJson()); ciP->answer = answer; } else diff --git a/src/lib/serviceRoutinesV2/postEntity.cpp b/src/lib/serviceRoutinesV2/postEntity.cpp index 56375810b1..d89c17fb5d 100644 --- a/src/lib/serviceRoutinesV2/postEntity.cpp +++ b/src/lib/serviceRoutinesV2/postEntity.cpp @@ -92,10 +92,10 @@ std::string postEntity // Any error in the response? std::string answer = ""; - if (parseDataP->upcrs.res.oe.code != SccNone) + if ((parseDataP->upcrs.res.error.code != SccNone ) && (parseDataP->upcrs.res.error.code != SccOk)) { - TIMED_RENDER(answer = parseDataP->upcrs.res.oe.toJson()); - ciP->httpStatusCode = parseDataP->upcrs.res.oe.code; + TIMED_RENDER(answer = parseDataP->upcrs.res.error.toJson()); + ciP->httpStatusCode = parseDataP->upcrs.res.error.code; } else { diff --git a/src/lib/serviceRoutinesV2/putEntity.cpp b/src/lib/serviceRoutinesV2/putEntity.cpp index 8ee0f5dd00..b614f090b7 100644 --- a/src/lib/serviceRoutinesV2/putEntity.cpp +++ b/src/lib/serviceRoutinesV2/putEntity.cpp @@ -85,14 +85,14 @@ std::string putEntity postUpdateContext(ciP, components, compV, parseDataP); // Adjust error code if needed - adaptErrorCodeForSingleEntityOperation(&(parseDataP->upcrs.res.oe), false); + adaptErrorCodeForSingleEntityOperation(&(parseDataP->upcrs.res.error), false); // 03. Check error std::string answer = ""; - if (parseDataP->upcrs.res.oe.code != SccNone ) + if ((parseDataP->upcrs.res.error.code != SccNone ) && (parseDataP->upcrs.res.error.code != SccOk)) { - TIMED_RENDER(answer = parseDataP->upcrs.res.oe.toJson()); - ciP->httpStatusCode = parseDataP->upcrs.res.oe.code; + TIMED_RENDER(answer = parseDataP->upcrs.res.error.toJson()); + ciP->httpStatusCode = parseDataP->upcrs.res.error.code; } else { diff --git a/src/lib/serviceRoutinesV2/putEntityAttribute.cpp b/src/lib/serviceRoutinesV2/putEntityAttribute.cpp index c7f1be3db1..ae831c53cb 100644 --- a/src/lib/serviceRoutinesV2/putEntityAttribute.cpp +++ b/src/lib/serviceRoutinesV2/putEntityAttribute.cpp @@ -86,15 +86,15 @@ std::string putEntityAttribute postUpdateContext(ciP, components, compV, parseDataP); // Adjust error code if needed - adaptErrorCodeForSingleEntityOperation(&(parseDataP->upcrs.res.oe), true); + adaptErrorCodeForSingleEntityOperation(&(parseDataP->upcrs.res.error), true); // 03. Check error std::string answer = ""; - if (parseDataP->upcrs.res.oe.code != SccNone ) + if ((parseDataP->upcrs.res.error.code != SccNone ) && (parseDataP->upcrs.res.error.code != SccOk)) { - TIMED_RENDER(answer = parseDataP->upcrs.res.oe.toJson()); - alarmMgr.badInput(clientIp, parseDataP->upcrs.res.oe.description); - ciP->httpStatusCode = parseDataP->upcrs.res.oe.code; + TIMED_RENDER(answer = parseDataP->upcrs.res.error.toJson()); + alarmMgr.badInput(clientIp, parseDataP->upcrs.res.error.description); + ciP->httpStatusCode = parseDataP->upcrs.res.error.code; } else { diff --git a/src/lib/serviceRoutinesV2/putEntityAttributeValue.cpp b/src/lib/serviceRoutinesV2/putEntityAttributeValue.cpp index 25f43eb8ef..95c85fc2a2 100644 --- a/src/lib/serviceRoutinesV2/putEntityAttributeValue.cpp +++ b/src/lib/serviceRoutinesV2/putEntityAttributeValue.cpp @@ -93,14 +93,14 @@ std::string putEntityAttributeValue postUpdateContext(ciP, components, compV, parseDataP); // Adjust error code if needed - adaptErrorCodeForSingleEntityOperation(&(parseDataP->upcrs.res.oe), true); + adaptErrorCodeForSingleEntityOperation(&(parseDataP->upcrs.res.error), true); // 03. Check output from mongoBackend std::string answer = ""; - if (parseDataP->upcrs.res.oe.code != SccNone) + if ((parseDataP->upcrs.res.error.code != SccNone ) && (parseDataP->upcrs.res.error.code != SccOk)) { - TIMED_RENDER(answer = parseDataP->upcrs.res.oe.toJson()); - ciP->httpStatusCode = parseDataP->upcrs.res.oe.code; + TIMED_RENDER(answer = parseDataP->upcrs.res.error.toJson()); + ciP->httpStatusCode = parseDataP->upcrs.res.error.code; } else { diff --git a/test/unittests/CMakeLists.txt b/test/unittests/CMakeLists.txt index 84148a0350..a9830b6d87 100644 --- a/test/unittests/CMakeLists.txt +++ b/test/unittests/CMakeLists.txt @@ -95,7 +95,6 @@ SET (SOURCES ngsi/MetadataVector_test.cpp ngsi/Request_test.cpp ngsi/ScopeVector_test.cpp - ngsi/StatusCode_test.cpp apiTypesV2/Entity_test.cpp apiTypesV2/EntityVector_test.cpp diff --git a/test/unittests/mongoBackend/mongoContextProvidersUpdate_test.cpp b/test/unittests/mongoBackend/mongoContextProvidersUpdate_test.cpp index 3b26324cab..bbb211ac6f 100644 --- a/test/unittests/mongoBackend/mongoContextProvidersUpdate_test.cpp +++ b/test/unittests/mongoBackend/mongoContextProvidersUpdate_test.cpp @@ -33,7 +33,7 @@ #include "mongoBackend/MongoGlobal.h" #include "mongoBackend/mongoConnectionPool.h" #include "mongoBackend/mongoUpdateContext.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "ngsi/EntityId.h" #include "ngsi/Scope.h" #include "ngsi10/UpdateContextRequest.h" diff --git a/test/unittests/mongoBackend/mongoDiscoverContextAvailability_test.cpp b/test/unittests/mongoBackend/mongoDiscoverContextAvailability_test.cpp index 09b6694682..e8904b8490 100644 --- a/test/unittests/mongoBackend/mongoDiscoverContextAvailability_test.cpp +++ b/test/unittests/mongoBackend/mongoDiscoverContextAvailability_test.cpp @@ -30,7 +30,7 @@ #include "mongoBackend/MongoGlobal.h" #include "mongoBackend/mongoConnectionPool.h" #include "mongoBackend/mongoDiscoverContextAvailability.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "ngsi/EntityId.h" #include "ngsi/Scope.h" #include "ngsi9/DiscoverContextAvailabilityRequest.h" diff --git a/test/unittests/mongoBackend/mongoNotifyContext_test.cpp b/test/unittests/mongoBackend/mongoNotifyContext_test.cpp index 2c708f18ed..ae697b02fd 100644 --- a/test/unittests/mongoBackend/mongoNotifyContext_test.cpp +++ b/test/unittests/mongoBackend/mongoNotifyContext_test.cpp @@ -197,7 +197,7 @@ TEST(mongoNotifyContextRequest, Ent1Attr1) cerP->entity.fill("E1", "T1", "false"); ContextAttribute* caP = new ContextAttribute("A1", "TA1", "new_val"); cerP->entity.attributeVector.push_back(caP); - cerP->statusCode.fill(SccOk, ""); + cerP->error.fill(SccOk, ""); req.contextElementResponseVector.push_back(cerP); /* Invoke the function in mongoBackend library */ @@ -339,7 +339,7 @@ TEST(mongoNotifyContextRequest, Ent1AttrN) ContextAttribute* ca2P = new ContextAttribute("A2", "TA2", "new_val2"); cerP->entity.attributeVector.push_back(ca1P); cerP->entity.attributeVector.push_back(ca2P); - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); req.contextElementResponseVector.push_back(cerP); /* Invoke the function in mongoBackend library */ @@ -481,12 +481,12 @@ TEST(mongoNotifyContextRequest, EntNAttr1) cer1P->entity.fill("E1", "T1", "false"); ContextAttribute* ca1P = new ContextAttribute("A1", "TA1", "new_val"); cer1P->entity.attributeVector.push_back(ca1P); - cer1P->statusCode.fill(SccOk); + cer1P->error.fill(SccOk); req.contextElementResponseVector.push_back(cer1P); cer2P->entity.fill("E2", "T2", "false"); ContextAttribute* ca2P = new ContextAttribute("A3", "TA3", "new_val2"); cer2P->entity.attributeVector.push_back(ca2P); - cer2P->statusCode.fill(SccOk); + cer2P->error.fill(SccOk); req.contextElementResponseVector.push_back(cer2P); /* Invoke the function in mongoBackend library */ @@ -630,14 +630,14 @@ TEST(mongoNotifyContextRequest, EntNAttrN) ContextAttribute* ca2P = new ContextAttribute("A2", "TA2", "new_val2"); cer1P->entity.attributeVector.push_back(ca1P); cer1P->entity.attributeVector.push_back(ca2P); - cer1P->statusCode.fill(SccOk); + cer1P->error.fill(SccOk); req.contextElementResponseVector.push_back(cer1P); cer2P->entity.fill("E2", "T2", "false"); ContextAttribute* ca3P = new ContextAttribute("A3", "TA3", "new_val3"); ContextAttribute* ca4P = new ContextAttribute("A4", "TA4", "new_val4"); cer2P->entity.attributeVector.push_back(ca3P); cer2P->entity.attributeVector.push_back(ca4P); - cer2P->statusCode.fill(SccOk); + cer2P->error.fill(SccOk); req.contextElementResponseVector.push_back(cer2P); /* Invoke the function in mongoBackend library */ @@ -777,7 +777,7 @@ TEST(mongoNotifyContextRequest, createEntity) cerP->entity.fill("E10", "T10", "false"); ContextAttribute* caP = new ContextAttribute("A1", "TA1", "new_val"); cerP->entity.attributeVector.push_back(caP); - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); req.contextElementResponseVector.push_back(cerP); /* Invoke the function in mongoBackend library */ diff --git a/test/unittests/mongoBackend/mongoQueryTypes_test.cpp b/test/unittests/mongoBackend/mongoQueryTypes_test.cpp index 950f2160c9..1cbb63f84b 100644 --- a/test/unittests/mongoBackend/mongoQueryTypes_test.cpp +++ b/test/unittests/mongoBackend/mongoQueryTypes_test.cpp @@ -222,9 +222,9 @@ TEST(mongoQueryTypes, queryAllType) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); ASSERT_EQ(3, res.entityTypeVector.size()); ContextAttribute* ca; @@ -340,9 +340,9 @@ TEST(mongoQueryTypes, queryAllPaginationDetails) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("Count: 3", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("Count: 3", res.error.details); ASSERT_EQ(3, res.entityTypeVector.size()); ContextAttribute* ca; @@ -457,9 +457,9 @@ TEST(mongoQueryTypes, queryAllPaginationAll) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); ASSERT_EQ(3, res.entityTypeVector.size()); ContextAttribute* ca; @@ -574,9 +574,9 @@ TEST(mongoQueryTypes, queryAllPaginationOnlyFirst) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); ASSERT_EQ(1, res.entityTypeVector.size()); ContextAttribute* ca; @@ -647,9 +647,9 @@ TEST(mongoQueryTypes, queryAllPaginationOnlySecond) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); ASSERT_EQ(1, res.entityTypeVector.size()); ContextAttribute* ca; @@ -699,9 +699,9 @@ TEST(mongoQueryTypes, queryAllPaginationRange) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); ASSERT_EQ(2, res.entityTypeVector.size()); ContextAttribute* ca; @@ -777,9 +777,9 @@ TEST(mongoQueryTypes, queryAllPaginationNonExisting) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccContextElementNotFound, res.statusCode.code); - EXPECT_EQ("No context element found", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccContextElementNotFound, res.error.code); + EXPECT_EQ("No context element found", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); ASSERT_EQ(0, res.entityTypeVector.size()); @@ -809,9 +809,9 @@ TEST(mongoQueryTypes, queryAllPaginationNonExistingOverlap) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); ASSERT_EQ(1, res.entityTypeVector.size()); ContextAttribute* ca; @@ -869,9 +869,9 @@ TEST(mongoQueryTypes, queryAllPaginationNonExistingDetails) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccContextElementNotFound, res.statusCode.code); - EXPECT_EQ("No context element found", res.statusCode.reasonPhrase); - EXPECT_EQ("Number of types: 3. Offset is 7", res.statusCode.details); + EXPECT_EQ(SccContextElementNotFound, res.error.code); + EXPECT_EQ("No context element found", res.error.reasonPhrase); + EXPECT_EQ("Number of types: 3. Offset is 7", res.error.details); ASSERT_EQ(0, res.entityTypeVector.size()); @@ -905,8 +905,8 @@ TEST(mongoQueryTypes, queryAllDbException) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccReceiverInternalError, res.statusCode.code); - EXPECT_EQ("Internal Server Error", res.statusCode.reasonPhrase); + EXPECT_EQ(SccReceiverInternalError, res.error.code); + EXPECT_EQ("Internal Server Error", res.error.reasonPhrase); EXPECT_EQ("Database Error (collection: utest " "- runCommand(): { aggregate: \"entities\", " "cursor: { batchSize: 1000 }, " @@ -916,7 +916,7 @@ TEST(mongoQueryTypes, queryAllDbException) "{ $unwind: \"$attrNames\" }, " "{ $group: { _id: { $cond: [ { $in: [ \"$_id.type\", [ null, \"\" ] ] }, \"\", \"$_id.type\" ] }, attrs: { $addToSet: \"$attrNames\" } } }, " "{ $sort: { _id: 1 } }, { $skip: 0 }, { $limit: 20 } ] } " - "- exception: boom!!)", res.statusCode.details); + "- exception: boom!!)", res.error.details); EXPECT_EQ(0, res.entityTypeVector.size()); /* Restore real DB connection */ @@ -958,8 +958,8 @@ TEST(mongoQueryTypes, queryAllGenericException) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccReceiverInternalError, res.statusCode.code); - EXPECT_EQ("Internal Server Error", res.statusCode.reasonPhrase); + EXPECT_EQ(SccReceiverInternalError, res.error.code); + EXPECT_EQ("Internal Server Error", res.error.reasonPhrase); EXPECT_EQ("Database Error (collection: utest " "- runCommand(): { aggregate: \"entities\", " "cursor: { batchSize: 1000 }, " @@ -969,7 +969,7 @@ TEST(mongoQueryTypes, queryAllGenericException) "{ $unwind: \"$attrNames\" }, " "{ $group: { _id: { $cond: [ { $in: [ \"$_id.type\", [ null, \"\" ] ] }, \"\", \"$_id.type\" ] }, attrs: { $addToSet: \"$attrNames\" } } }, " "{ $sort: { _id: 1 } }, { $skip: 0 }, { $limit: 20 } ] } " - "- exception: std::exception)", res.statusCode.details); + "- exception: std::exception)", res.error.details); EXPECT_EQ(0, res.entityTypeVector.size()); /* Restore real DB connection */ @@ -1004,9 +1004,9 @@ TEST(mongoQueryTypes, queryGivenTypeBasic) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); EXPECT_EQ(3, res.entityType.count); ASSERT_EQ(5, res.entityType.contextAttributeVector.size()); @@ -1072,9 +1072,9 @@ TEST(mongoQueryTypes, queryGivenTypePaginationDetails) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("Count: 5", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("Count: 5", res.error.details); EXPECT_EQ(3, res.entityType.count); ASSERT_EQ(5, res.entityType.contextAttributeVector.size()); @@ -1140,9 +1140,9 @@ TEST(mongoQueryTypes, queryGivenTypePaginationAll) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); EXPECT_EQ(3, res.entityType.count); ASSERT_EQ(5, res.entityType.contextAttributeVector.size()); @@ -1208,9 +1208,9 @@ TEST(mongoQueryTypes, queryGivenTypePaginationOnlyFirst) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); ASSERT_EQ(1, res.entityType.contextAttributeVector.size()); @@ -1248,9 +1248,9 @@ TEST(mongoQueryTypes, queryGivenTypePaginationOnlySecond) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); EXPECT_EQ(3, res.entityType.count); ASSERT_EQ(1, res.entityType.contextAttributeVector.size()); @@ -1289,9 +1289,9 @@ TEST(mongoQueryTypes, queryGivenTypePaginationRange) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); EXPECT_EQ(3, res.entityType.count); ASSERT_EQ(3, res.entityType.contextAttributeVector.size()); @@ -1344,9 +1344,9 @@ TEST(mongoQueryTypes, queryGivenTypePaginationNonExisting) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccContextElementNotFound, res.statusCode.code); - EXPECT_EQ("No context element found", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccContextElementNotFound, res.error.code); + EXPECT_EQ("No context element found", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); ASSERT_EQ(0, res.entityType.contextAttributeVector.size()); @@ -1377,9 +1377,9 @@ TEST(mongoQueryTypes, queryGivenTypePaginationNonExistingOverlap) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); EXPECT_EQ(3, res.entityType.count); ASSERT_EQ(2, res.entityType.contextAttributeVector.size()); @@ -1425,9 +1425,9 @@ TEST(mongoQueryTypes, queryGivenTypePaginationNonExistingDetails) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccContextElementNotFound, res.statusCode.code); - EXPECT_EQ("No context element found", res.statusCode.reasonPhrase); - EXPECT_EQ("Number of attributes: 5. Offset is 7", res.statusCode.details); + EXPECT_EQ(SccContextElementNotFound, res.error.code); + EXPECT_EQ("No context element found", res.error.reasonPhrase); + EXPECT_EQ("Number of attributes: 5. Offset is 7", res.error.details); ASSERT_EQ(0, res.entityType.contextAttributeVector.size()); @@ -1462,8 +1462,8 @@ TEST(mongoQueryTypes, queryGivenTypeDbException) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccReceiverInternalError, res.statusCode.code); - EXPECT_EQ("Internal Server Error", res.statusCode.reasonPhrase); + EXPECT_EQ(SccReceiverInternalError, res.error.code); + EXPECT_EQ("Internal Server Error", res.error.reasonPhrase); EXPECT_EQ("Database Error (collection: utest " "- runCommand(): { aggregate: \"entities\", " "cursor: { batchSize: 1000 }, " @@ -1474,7 +1474,7 @@ TEST(mongoQueryTypes, queryGivenTypeDbException) "{ $unwind: \"$attrs\" }, " "{ $group: { _id: \"$attrs\" } }, " "{ $sort: { _id: 1 } } ] } " - "- exception: boom!!)", res.statusCode.details); + "- exception: boom!!)", res.error.details); EXPECT_EQ(0, res.entityType.contextAttributeVector.size()); /* Restore real DB connection */ @@ -1514,8 +1514,8 @@ TEST(mongoQueryTypes, queryGivenTypeGenericException) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccReceiverInternalError, res.statusCode.code); - EXPECT_EQ("Internal Server Error", res.statusCode.reasonPhrase); + EXPECT_EQ(SccReceiverInternalError, res.error.code); + EXPECT_EQ("Internal Server Error", res.error.reasonPhrase); EXPECT_EQ("Database Error (collection: utest " "- runCommand(): { aggregate: \"entities\", " "cursor: { batchSize: 1000 }, " @@ -1526,7 +1526,7 @@ TEST(mongoQueryTypes, queryGivenTypeGenericException) "{ $unwind: \"$attrs\" }, " "{ $group: { _id: \"$attrs\" } }, " "{ $sort: { _id: 1 } } ] } " - "- exception: std::exception)", res.statusCode.details); + "- exception: std::exception)", res.error.details); EXPECT_EQ(0, res.entityType.contextAttributeVector.size()); /* Restore real DB connection */ diff --git a/test/unittests/mongoBackend/mongoRegisterContext_test.cpp b/test/unittests/mongoBackend/mongoRegisterContext_test.cpp index efe0ed1788..0fa9452dc3 100644 --- a/test/unittests/mongoBackend/mongoRegisterContext_test.cpp +++ b/test/unittests/mongoBackend/mongoRegisterContext_test.cpp @@ -35,7 +35,7 @@ #include "mongoBackend/MongoGlobal.h" #include "mongoBackend/mongoConnectionPool.h" #include "mongoBackend/mongoRegisterContext.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "ngsi/ContextRegistration.h" #include "ngsi/EntityId.h" #include "ngsi/ContextRegistrationAttribute.h" diff --git a/test/unittests/mongoBackend/mongoRegisterContext_update_test.cpp b/test/unittests/mongoBackend/mongoRegisterContext_update_test.cpp index d3dd252c26..ef678ecfe6 100644 --- a/test/unittests/mongoBackend/mongoRegisterContext_update_test.cpp +++ b/test/unittests/mongoBackend/mongoRegisterContext_update_test.cpp @@ -38,7 +38,7 @@ #include "ngsi/EntityId.h" #include "ngsi/ContextRegistrationAttribute.h" #include "ngsi/Metadata.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "ngsi9/RegisterContextRequest.h" #include "ngsi9/RegisterContextResponse.h" diff --git a/test/unittests/mongoBackend/mongoUnsubscribeContext_test.cpp b/test/unittests/mongoBackend/mongoUnsubscribeContext_test.cpp index 6a4ce9f849..2be5b17459 100644 --- a/test/unittests/mongoBackend/mongoUnsubscribeContext_test.cpp +++ b/test/unittests/mongoBackend/mongoUnsubscribeContext_test.cpp @@ -133,9 +133,9 @@ TEST(mongoUnsubscribeContext, subscriptionNotFound) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); EXPECT_EQ("51307b66f481db11bf869999", res.subscriptionId.get()); - EXPECT_EQ(SccContextElementNotFound, res.statusCode.code); - EXPECT_EQ("No context element found", res.statusCode.reasonPhrase); - EXPECT_EQ("subscriptionId: /51307b66f481db11bf869999/", res.statusCode.details); + EXPECT_EQ(SccContextElementNotFound, res.error.code); + EXPECT_EQ("No context element found", res.error.reasonPhrase); + EXPECT_EQ("subscriptionId: /51307b66f481db11bf869999/", res.error.details); /* Check database (untouched) */ DBClientBase* connection = getMongoConnection(); @@ -173,9 +173,9 @@ TEST(mongoUnsubscribeContext, unsubscribe) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); EXPECT_EQ("51307b66f481db11bf860001", res.subscriptionId.get()); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ(0, res.statusCode.details.size()); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ(0, res.error.details.size()); /* Check database (one document, but not the deleted one) */ DBClientBase* connection = getMongoConnection(); @@ -225,11 +225,11 @@ TEST(mongoUnsubscribeContext, MongoDbFindOneFail) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); EXPECT_EQ("51307b66f481db11bf860001", res.subscriptionId.get()); - EXPECT_EQ(SccReceiverInternalError, res.statusCode.code); - EXPECT_EQ("Internal Server Error", res.statusCode.reasonPhrase); + EXPECT_EQ(SccReceiverInternalError, res.error.code); + EXPECT_EQ("Internal Server Error", res.error.reasonPhrase); EXPECT_EQ("Database Error (collection: utest.csubs " "- findOne(): { _id: ObjectId('51307b66f481db11bf860001') } " - "- exception: boom!!)", res.statusCode.details); + "- exception: boom!!)", res.error.details); // Sleeping a little to "give mongod time to process its input". // Without this sleep, this tests fails around 10% of the times (in Ubuntu 13.04) @@ -297,11 +297,11 @@ TEST(mongoUnsubscribeContext, MongoDbRemoveFail) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); EXPECT_EQ("51307b66f481db11bf860001", res.subscriptionId.get()); - EXPECT_EQ(SccReceiverInternalError, res.statusCode.code); - EXPECT_EQ("Internal Server Error", res.statusCode.reasonPhrase); + EXPECT_EQ(SccReceiverInternalError, res.error.code); + EXPECT_EQ("Internal Server Error", res.error.reasonPhrase); EXPECT_EQ("Database Error (collection: utest.csubs " "- remove(): { _id: ObjectId('51307b66f481db11bf860001') } " - "- exception: boom!!)", res.statusCode.details); + "- exception: boom!!)", res.error.details); // Sleeping a little to "give mongod time to process its input". usleep(1000); diff --git a/test/unittests/ngsi/ContextElementResponseVector_test.cpp b/test/unittests/ngsi/ContextElementResponseVector_test.cpp index 5f4ccd78e9..656d8e8b7d 100644 --- a/test/unittests/ngsi/ContextElementResponseVector_test.cpp +++ b/test/unittests/ngsi/ContextElementResponseVector_test.cpp @@ -51,7 +51,7 @@ TEST(ContextElementResponseVector, render) cer.entity.entityId.id = "ID"; cer.entity.entityId.type = "Type"; - cer.statusCode.fill(SccOk, "details"); + cer.error.fill(SccOk, "details"); utExit(); } diff --git a/test/unittests/ngsi/ContextElementResponse_test.cpp b/test/unittests/ngsi/ContextElementResponse_test.cpp index 940ed68d38..005b800bb9 100644 --- a/test/unittests/ngsi/ContextElementResponse_test.cpp +++ b/test/unittests/ngsi/ContextElementResponse_test.cpp @@ -48,7 +48,7 @@ TEST(ContextElementResponse, render) cer.entity.entityId.id = "ID"; cer.entity.entityId.type = "Type"; - cer.statusCode.fill(SccOk, "details"); + cer.error.fill(SccOk, "details"); out = cer.toJson(NGSI_V2_NORMALIZED, emptyV, false, emptyV, NULL);; EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; diff --git a/test/unittests/ngsi/StatusCode_test.cpp b/test/unittests/ngsi/StatusCode_test.cpp deleted file mode 100644 index 144e437681..0000000000 --- a/test/unittests/ngsi/StatusCode_test.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/StatusCode.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* render - -*/ -TEST(StatusCode, render) -{ - utInit(); - - StatusCode sc1; - StatusCode sc2; - std::string out; - const char* outfile1 = "ngsi.statusCode.render4.middle.json"; - - sc2.fill(SccOk, "DETAILS"); - out = sc2.toJson(); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - sc1.release(); // just to exercise the code ... - - utExit(); -} - - - -/* **************************************************************************** -* -* fill - -*/ -TEST(StatusCode, fill) -{ - utInit(); - - StatusCode sc; - StatusCode sc2; - StatusCode ec; - std::string out; - - sc.fill(SccForbidden, "D"); - EXPECT_EQ(sc.code, SccForbidden); - EXPECT_STREQ(sc.reasonPhrase.c_str(), "Forbidden"); - EXPECT_STREQ(sc.details.c_str(), "D"); - - sc.fill(SccOk, "Details"); - EXPECT_EQ(sc.code, SccOk); - EXPECT_STREQ(sc.reasonPhrase.c_str(), "OK"); - EXPECT_STREQ(sc.details.c_str(), "Details"); - - sc.fill(SccBadRequest, "Very bad request :-)"); - EXPECT_EQ(sc.code, SccBadRequest); - EXPECT_STREQ(sc.reasonPhrase.c_str(), "BadRequest"); - EXPECT_STREQ(sc.details.c_str(), "Very bad request :-)"); - - utExit(); -} diff --git a/test/unittests/ngsi10/NotifyContextRequest_test.cpp b/test/unittests/ngsi10/NotifyContextRequest_test.cpp index b11800d705..e19fa587d2 100644 --- a/test/unittests/ngsi10/NotifyContextRequest_test.cpp +++ b/test/unittests/ngsi10/NotifyContextRequest_test.cpp @@ -26,7 +26,7 @@ #include "logMsg/traceLevels.h" #include "ngsi/ParseData.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "ngsi10/NotifyContextRequest.h" #include "ngsi10/NotifyContextResponse.h" @@ -66,7 +66,7 @@ TEST(NotifyContextRequest, json_render) EntityId enId1("E01", "", "EType", ""); cerP->entity.fill(enId1); ncrP->contextElementResponseVector.push_back(cerP); - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename2)) << "Error getting test data from '" << filename2 << "'"; rendered = ncrP->toJson(NGSI_V2_NORMALIZED, emptyV, false, emptyV, NULL); @@ -78,7 +78,7 @@ TEST(NotifyContextRequest, json_render) EntityId enId2("E02", "", "EType", ""); cerP->entity.fill(enId2); ncrP->contextElementResponseVector.push_back(cerP); - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename3)) << "Error getting test data from '" << filename3 << "'"; rendered = ncrP->toJson(NGSI_V2_NORMALIZED, emptyV, false, emptyV, NULL);