Skip to content

Commit

Permalink
Merge pull request #21 from telefonicaid/task/refactorContextRouteHan…
Browse files Browse the repository at this point in the history
…dling

ADD New alternative routes to handle by the Context Server
  • Loading branch information
dmoranj committed Jan 22, 2015
2 parents 493e2b7 + 401f45e commit e36619f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
53 changes: 29 additions & 24 deletions lib/services/contextServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/services/ngsiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
6 changes: 3 additions & 3 deletions test/unit/active-devices-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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'));
Expand All @@ -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'));
Expand Down
6 changes: 3 additions & 3 deletions test/unit/contextBrokerSecurityAccess-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e36619f

Please sign in to comment.