diff --git a/lib/services/contextServer.js b/lib/services/contextServer.js index 563a4b668..55b1cf46d 100644 --- a/lib/services/contextServer.js +++ b/lib/services/contextServer.js @@ -229,31 +229,36 @@ function validateJson(template) { * @param {Object} router Express request router object. */ function loadContextRoutes(router) { + //TODO: remove '//' paths when the appropriate patch comes to Orion + var updateMiddlewares = [ + ensureType, + ngsiParser.readUpdateBody, + validateJson(updateContextTemplate), + handleUpdate + ], + queryMiddlewares = [ + ensureType, + ngsiParser.readQueryBody, + validateJson(queryContextTemplate), + handleQuery + ], + updatePaths = [ + '/v1/updateContext', + '/NGSI10/updateContext', + '//updateContext' + ], + queryPaths = [ + '/v1/queryContext', + '/NGSI10/queryContext', + '//queryContext' + ]; + logger.info(context, 'Loading NGSI Contect server routes'); - router.post('/v1/updateContext', - ensureType, - ngsiParser.readUpdateBody, - validateJson(updateContextTemplate), - handleUpdate); - - router.post('/v1/queryContext', - ensureType, - ngsiParser.readQueryBody, - validateJson(queryContextTemplate), - handleQuery); - - //TODO: remove this paths when the appropriate patch comes to Orion - router.post('//queryContext', - ensureType, - ngsiParser.readQueryBody, - validateJson(queryContextTemplate), - handleQuery); - - router.post('//updateContext', - ensureType, - ngsiParser.readUpdateBody, - validateJson(updateContextTemplate), - handleUpdate); + + for (var i = 0; i < updatePaths.length; i++) { + router.post(updatePaths[i], updateMiddlewares); + router.post(queryPaths[i], queryMiddlewares); + } } exports.loadContextRoutes = loadContextRoutes; diff --git a/lib/services/ngsiService.js b/lib/services/ngsiService.js index 1dc3c2f11..07956775f 100644 --- a/lib/services/ngsiService.js +++ b/lib/services/ngsiService.js @@ -206,7 +206,7 @@ function sendUpdateValue(deviceId, deviceType, attributes, token, callback) { } options = { - url: 'http://' + brokerHost + ':' + brokerPort + '/NGSI10/updateContext', + url: 'http://' + brokerHost + ':' + brokerPort + '/v1/updateContext', method: 'POST', json: { contextElements: [ diff --git a/test/unit/active-devices-test.js b/test/unit/active-devices-test.js index fcec11e80..f8d1f9d91 100644 --- a/test/unit/active-devices-test.js +++ b/test/unit/active-devices-test.js @@ -114,7 +114,7 @@ describe('Active attributes test', function() { contextBrokerMock = nock('http://10.11.128.16:1026') .matchHeader('fiware-service', 'smartGondor') .matchHeader('fiware-servicepath', 'gardens') - .post('/NGSI10/updateContext', + .post('/v1/updateContext', utils.readExampleFile('./test/unit/contextRequests/updateContext1.json')) .reply(200, utils.readExampleFile('./test/unit/contextResponses/updateContext1Success.json')); @@ -138,7 +138,7 @@ describe('Active attributes test', function() { contextBrokerMock = nock('http://10.11.128.16:1026') .matchHeader('fiware-service', 'smartGondor') .matchHeader('fiware-servicepath', 'gardens') - .post('/NGSI10/updateContext', + .post('/v1/updateContext', utils.readExampleFile('./test/unit/contextRequests/updateContext1.json')) .reply(413, utils.readExampleFile('./test/unit/contextResponses/updateContext1Failed.json')); @@ -163,7 +163,7 @@ describe('Active attributes test', function() { contextBrokerMock = nock('http://192.168.1.1:3024') .matchHeader('fiware-service', 'smartGondor') .matchHeader('fiware-servicepath', 'gardens') - .post('/NGSI10/updateContext', + .post('/v1/updateContext', utils.readExampleFile('./test/unit/contextRequests/updateContext2.json')) .reply(200, utils.readExampleFile('./test/unit/contextResponses/updateContext1Success.json')); diff --git a/test/unit/contextBrokerSecurityAccess-test.js b/test/unit/contextBrokerSecurityAccess-test.js index 9e1397811..cbe97930b 100644 --- a/test/unit/contextBrokerSecurityAccess-test.js +++ b/test/unit/contextBrokerSecurityAccess-test.js @@ -123,7 +123,7 @@ describe('Secured access to the Context Broker', function() { .matchHeader('fiware-service', 'smartGondor') .matchHeader('fiware-servicepath', 'electricity') .matchHeader('X-Auth-Token', '12345679ABCDEF') - .post('/NGSI10/updateContext', + .post('/v1/updateContext', utils.readExampleFile('./test/unit/contextRequests/updateContext1.json')) .reply( 200, @@ -165,7 +165,7 @@ describe('Secured access to the Context Broker', function() { .matchHeader('fiware-service', 'smartGondor') .matchHeader('fiware-servicepath', 'electricity') .matchHeader('X-Auth-Token', '12345679ABCDEF') - .post('/NGSI10/updateContext', + .post('/v1/updateContext', utils.readExampleFile('./test/unit/contextRequests/updateContext1.json')) .reply( 403, @@ -197,7 +197,7 @@ describe('Secured access to the Context Broker', function() { .matchHeader('fiware-service', 'smartGondor') .matchHeader('fiware-servicepath', 'electricity') .matchHeader('X-Auth-Token', '12345679ABCDEF') - .post('/NGSI10/updateContext', + .post('/v1/updateContext', utils.readExampleFile('./test/unit/contextRequests/updateContext1.json')) .reply( 200,