无法使用旅游指南应用程序更新餐厅价值



我们在测试tourguide应用程序时发现了一个问题https://github.com/Fiware/tutorials.TourGuide-App.

如果我们试图从餐厅获得属性值:

curl  <cb_host>:<cb_port>/v2/Entities/Elizalde/attrs/aggregateRating/value -s -S --header 'Content-Type: application/json' --header 'x-auth-token:<token>' --header 'Fiware-service: tourguide'

我们得到了预期的属性值:

{"reviewCount":1,"ratingValue":3}

但是,如果我们尝试按照更新属性值的说明更新值http://fiware.github.io/context.Orion/api/v2/:

curl -v -X PUT <cb_host>:<cb_port>/v2/Entities/Elizalde/attrs/aggregateRating/value?Type=Restaurant -s -S --header 'Content-Type: application/json' --header 'x-auth-token:<token>' --header 'Fiware-service: tourguide' -d '{"reviewCount": 1,"ratingValue": 10}'

我们得到一个404错误。

如果我们遵循API食谱中更新属性的详细说明,则为JSONhttp://fiware.github.io/context.Orion/api/v2/cookbook/

curl -v -X PUT <cb_host>:<cb_port>/v2/Entities/Elizalde/attrs/aggregateRating/value -s -S --header 'Content-Type: application/json' --header 'x-auth-token:<token>' --header 'Fiware-service: tourguide' -d '{"value": {"reviewCount": 1,"ratingValue": 10}}'

我们还得到一个404错误。

复制步骤:

  • 克隆tourguide存储库
  • 部署docker容器:cd fiware-devguide-app/docker/composedocker-compose -f docker-compose.yml up
  • 获取令牌,如下所述:https://github.com/Fiware/tutorials.TourGuide-App#how-检索oauth令牌以使用api
  • 执行指定的请求

关于orion版本的信息:

<orion>
   <version>0.28.0</version>
    <uptime>0 d, 1 h, 12 m, 25 s</uptime>
    <git_hash>aaf8020a5de680b6d7e0c00c70cf425bcc4f39c8</git_hash>
    <compile_time>Mon Mar 21 13:20:37 UTC 2016</compile_time>
    <compiled_by>root</compiled_by>
    <compiled_in>838a42ae8431</compiled_in>
</orion>

已更新

为了使用Docker上提供的Orion CB的最后一个版本,我们更新了tourguide应用程序的Docker组件,但也出现了同样的错误。

这是关于最后一个版本的信息:

{
  "orion" : {
  "version" : "1.0.0-next",
  "uptime" : "0 d, 0 h, 8 m, 20 s",
  "git_hash" : "9a35f04739a4236711bdf5b48152eaa21c3377b2",
  "compile_time" : "Wed Apr 20 11:41:57 UTC 2016",
  "compiled_by" : "root",
  "compiled_in" : "838a42ae8431"
 }
}

我们已经在调试模式下执行了上下文代理,如果我们执行:

curl -v -X PUT orion:1026/v2/Entities/Elizalde/attrs/aggregateRating/value?type=Restaurant -s -S --header 'Content-Type: application/json' --header 'x-auth-token:HuUUHhQ6Qh8myI3o3uI2rYeOIK1Ym1' --header 'Fiware-service: tourguide' -d '{"reviewCount": 1,"ratingValue": 10}'

我们得到这个输出:

orion_1        | DEBUG@07:33:12  rest.cpp[955]: 
orion_1        | DEBUG@07:33:12  rest.cpp[956]: --------------------- Serving request PUT /v2/Entities/Elizalde/attrs/aggregateRating/value -----------------
orion_1        | DEBUG@07:33:12  rest.cpp[274]: HTTP Header:   User-Agent: curl/7.35.0
orion_1        | DEBUG@07:33:12  rest.cpp[274]: HTTP Header:   Host: orion:1026
orion_1        | DEBUG@07:33:12  rest.cpp[274]: HTTP Header:   Accept: */*
orion_1        | DEBUG@07:33:12  rest.cpp[274]: HTTP Header:   Content-Type: application/json
orion_1        | DEBUG@07:33:12  rest.cpp[274]: HTTP Header:   x-auth-token: HuUUHhQ6Qh8myI3o3uI2rYeOIK1Ym1
orion_1        | DEBUG@07:33:12  rest.cpp[274]: HTTP Header:   Fiware-service: tourguide
orion_1        | DEBUG@07:33:12  rest.cpp[274]: HTTP Header:   Content-Length: 36
orion_1        | DEBUG@07:33:12  sem.cpp[276]: transactionIdSet taking the 'trans' semaphore for 'changing the transaction id'
orion_1        | DEBUG@07:33:12  sem.cpp[297]: transactionIdSet has the 'trans' semaphore
orion_1        | DEBUG@07:33:12  sem.cpp[373]: transactionIdSet gives the 'trans' semaphore for 'changing the transaction id'
orion_1        | INFO@07:33:12  logMsg.h[1805]: Starting transaction from 172.17.0.1:48854/v2/Entities/Elizalde/attrs/aggregateRating/value
orion_1        | DEBUG@07:33:12  rest.cpp[225]: URI parameter:   type: Restaurant
orion_1        | DEBUG@07:33:12  rest.cpp[1059]: Got 36 of payload of 36 bytes
orion_1        | DEBUG@07:33:12  ContextAttribute.cpp[259]: Creating a ContextAttribute 1
orion_1        | DEBUG@07:33:12  ContextAttribute.cpp[259]: Creating a ContextAttribute 1
orion_1        | DEBUG@07:33:12  ContextAttribute.cpp[259]: Creating a ContextAttribute 1
orion_1        | DEBUG@07:33:12  RestService.cpp[411]: Parsing payload for URL '/v2/Entities/Elizalde/attrs/aggregateRating/value', method 'PUT', service vector index: 12
orion_1        | DEBUG@07:33:12  RestService.cpp[413]: Parsing payload '{"reviewCount": 1,"ratingValue": 10}'
orion_1        | DEBUG@07:33:12  RestService.cpp[101]: parsing data for service 'EntityAttributeValueRequest'. Method: 'PUT'
orion_1        | DEBUG@07:33:12  RestService.cpp[102]: outFormat: JSON
orion_1        | DEBUG@07:33:12  CompoundValueNode.cpp[59]: Created EMPTY compound node at 0x7f0754001720
orion_1        | DEBUG@07:33:12  CompoundValueNode.cpp[59]: Created EMPTY compound node at 0x7f0754001800
orion_1        | DEBUG@07:33:12  CompoundValueNode.cpp[59]: Created EMPTY compound node at 0x7f0754001910
orion_1        | DEBUG@07:33:12  RestService.cpp[127]: result: 'OK'
orion_1        | DEBUG@07:33:12  RestService.cpp[128]: outFormat: JSON
orion_1        | DEBUG@07:33:12  RestService.cpp[415]: payloadParse returns 'OK'
orion_1        | DEBUG@07:33:12  RestService.cpp[437]: Treating service PUT /v2/Entities/Elizalde/attrs/aggregateRating/value
orion_1        | DEBUG@07:33:12  RestService.cpp[483]: tenant: 'tourguide'
orion_1        | DEBUG@07:33:12  ContextAttribute.cpp[309]: Creating a ContextAttribute: compoundValueP at 0x7f0754001720 for attribute 'aggregateRating' at 0x7f0754001c20
orion_1        | DEBUG@07:33:12  sem.cpp[147]: mongoUpdateContext taking the 'req' semaphore for 'ngsi10 update request'
orion_1        | DEBUG@07:33:12  sem.cpp[168]: mongoUpdateContext has the 'req' semaphore
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[684]: Service Path JSON string: '{ $in: [ null, /^/$/ ] }'
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[420]: database name composed: 'orion-tourguide'
orion_1        | DEBUG@07:33:12  connectionOperations.cpp[203]: count() in 'orion-tourguide.entities' collection: '{ _id.id: "Elizalde", _id.type: "Restaurant", _id.servicePath: { $in: [ null, /^/$/ ] } }'
orion_1        | INFO@07:33:12  connectionOperations.cpp[210]: Database Operation Successful (count: { _id.id: "Elizalde", _id.type: "Restaurant", _id.servicePath: { $in: [ null, /^/$/ ] } })
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[420]: database name composed: 'orion-tourguide'
orion_1        | DEBUG@07:33:12  connectionOperations.cpp[65]: query() in 'orion-tourguide.entities' collection: '{ _id.id: "Elizalde", _id.type: "Restaurant", _id.servicePath: { $in: [ null, /^/$/ ] } }'
orion_1        | INFO@07:33:12  connectionOperations.cpp[79]: Database Operation Successful (query: { _id.id: "Elizalde", _id.type: "Restaurant", _id.servicePath: { $in: [ null, /^/$/ ] } })
orion_1        | DEBUG@07:33:12  MongoCommonUpdate.cpp[2891]: Docs found: 0
orion_1        | DEBUG@07:33:12  ContextAttribute.cpp[342]: Creating a string ContextAttribute 'aggregateRating':'none':'', setting its compound to NULL
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[1514]: Entity discovery: {id: Elizalde, type: Restaurant}
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[1526]: Attribute discovery: 'aggregateRating'
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[684]: Service Path JSON string: '{ $in: [ null, /^/$/ ] }'
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[1566]: Offset: 0, Limit: 0, Details: false
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[420]: database name composed: 'orion-tourguide'
orion_1        | DEBUG@07:33:12  connectionOperations.cpp[134]: query() in 'orion-tourguide.registrations' collection limit=0, offset=0: '{ query: { $or: [ { contextRegistration.entities: { $in: [ { id: "Elizalde", type: "Restaurant" }, { type: "Restaurant", id: "Elizalde" } ] } }, { contextRegistration.entities.id: { $in: [] } } ], expiration: { $gt: 1461223992 }, contextRegistration.attrs.name: { $in: [ "aggregateRating" ] }, servicePath: { $in: [ null, /^/$/ ] } }, orderby: { _id: 1 } }'
orion_1        | INFO@07:33:12  connectionOperations.cpp[153]: Database Operation Successful (query: { query: { $or: [ { contextRegistration.entities: { $in: [ { id: "Elizalde", type: "Restaurant" }, { type: "Restaurant", id: "Elizalde" } ] } }, { contextRegistration.entities.id: { $in: [] } } ], expiration: { $gt: 1461223992 }, contextRegistration.attrs.name: { $in: [ "aggregateRating" ] }, servicePath: { $in: [ null, /^/$/ ] } }, orderby: { _id: 1 } })
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[1514]: Entity discovery: {id: Elizalde, type: Restaurant}
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[684]: Service Path JSON string: '{ $in: [ null, /^/$/ ] }'
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[1566]: Offset: 0, Limit: 0, Details: false
orion_1        | DEBUG@07:33:12  MongoGlobal.cpp[420]: database name composed: 'orion-tourguide'
orion_1        | DEBUG@07:33:12  connectionOperations.cpp[134]: query() in 'orion-tourguide.registrations' collection limit=0, offset=0: '{ query: { $or: [ { contextRegistration.entities: { $in: [ { id: "Elizalde", type: "Restaurant" }, { type: "Restaurant", id: "Elizalde" } ] } }, { contextRegistration.entities.id: { $in: [] } } ], expiration: { $gt: 1461223992 }, servicePath: { $in: [ null, /^/$/ ] } }, orderby: { _id: 1 } }'
orion_1        | INFO@07:33:12  connectionOperations.cpp[153]: Database Operation Successful (query: { query: { $or: [ { contextRegistration.entities: { $in: [ { id: "Elizalde", type: "Restaurant" }, { type: "Restaurant", id: "Elizalde" } ] } }, { contextRegistration.entities.id: { $in: [] } } ], expiration: { $gt: 1461223992 }, servicePath: { $in: [ null, /^/$/ ] } }, orderby: { _id: 1 } })
orion_1        | DEBUG@07:33:12  sem.cpp[353]: mongoUpdateContext gives the 'req' semaphore for 'ngsi10 update request'
orion_1        | DEBUG@07:33:12  CompoundValueNode.cpp[228]: Destroying node 0x7f0754001720: name: 'TOP', path '/' at 0x7f0754001720 (with 2 children)
orion_1        | DEBUG@07:33:12  CompoundValueNode.cpp[234]: Deleting child 0, at 0x7f0754001800
orion_1        | DEBUG@07:33:12  CompoundValueNode.cpp[228]: Destroying node 0x7f0754001800: name: 'reviewCount', path '/reviewCount' at 0x7f0754001800 (with 0 children)
orion_1        | DEBUG@07:33:12  CompoundValueNode.cpp[234]: Deleting child 1, at 0x7f0754001910
orion_1        | DEBUG@07:33:12  CompoundValueNode.cpp[228]: Destroying node 0x7f0754001910: name: 'ratingValue', path '/ratingValue' at 0x7f0754001910 (with 0 children)
orion_1        | DEBUG@07:33:12  restReply.cpp[67]: Response 76: responding with 0 bytes, Status Code 404
orion_1        | DEBUG@07:33:12  restReply.cpp[68]: Response payload: ''
orion_1        | DEBUG@07:33:12  UpdateContextResponse.cpp[77]: destroyed
orion_1        | DEBUG@07:33:12  RegisterContextResponse.cpp[56]: destroyed
orion_1        | INFO@07:33:12  logMsg.h[1889]: Transaction ended

我试图在有限的环境中重现您的问题(只是创建实体"Elizalde"),但没有成功。对我来说效果很好。。。

首先,下面一行:
/v2/Entities/Elizalde/attrs/aggregateRating/value?Type=Restaurant 不正确。它必须是.../value?type=Restaurant,因为URI参数区分大小写。

使用Type而不是Type意味着Type被忽略,并且类型不存在,因此PUT将攻击所有名为Elizalde的实体,而不管它们的类型如何。你可能只有一个,所以没关系。如果你有不止一个名为Elizalde的实体,你会得到一个409(冲突)作为响应,但事实并非如此,因为你看到的是一个404(未找到)。

我不知道你为什么得了404分。在我的简单测试中,一切都正常(我使用的是最新版本的broker,但这不会真正改变任何事情)。

为了尝试解决您的问题,我建议您以详细模式启动代理(使用-t0-255 -logLevel DEBUG),并在收到失败的PUT请求时发布代理的输出。

此外,为了缩小范围,你可能想使用我组装的脚本在我的机器中测试它(希望它在你的机器中失败——对我来说它是有效的):

echo "01. Create Entity Elizalde, type Restaurant, with compound attribute 'aggregateRating'"
echo "======================================================================================"
curl -X POST localhost:1026/v2/Entities  -s -S --header 'Content-Type: application/json' --header 'x-auth-token:<token>' --header 'Fiware-service: tourguide' -d '{"id": "Elizalde", "type": "Restaurant", "aggr
egateRating": { "value": { "reviewCount": 1, "ratingValue": 10 }}}'
echo
echo
echo "02. Create Entity Elizalde, type Restaurant2, with compound attribute 'aggregateRating'"
echo "======================================================================================"
curl -X POST localhost:1026/v2/Entities  -s -S --header 'Content-Type: application/json' --header 'x-auth-token:<token>' --header 'Fiware-service: tourguide' -d '{"id": "Elizalde", "type": "Restaurant2", "agg
regateRating": { "value": { "reviewCount": 1, "ratingValue": 10 }}}'
echo
echo
echo "03. Get Entity Elizalde, see ratingValue == 10"
echo "=============================================="
curl localhost:1026/v2/Entities/Elizalde?type=Restaurant
echo
echo
echo "04. Change value of aggregateRating, setting ratingValue to 20 (was 10)"
echo "======================================================================="
curl -X PUT localhost:1026/v2/Entities/Elizalde/attrs/aggregateRating/value?type=Restaurant -s -S --header 'Content-Type: application/json' --header 'x-auth-token:<token>' --header 'Fiware-service: tourguide'
 -d '{"reviewCount": 1,"ratingValue": 20}'
echo
echo
echo "05. Get Entity Elizalde, see ratingValue == 20"
echo "=============================================="
curl localhost:1026/v2/Entities/Elizalde?type=Restaurant
echo
echo
echo "06. Delete Elizalde, type Restaurant"
echo "===================================="
curl -X DELETE localhost:1026/v2/Entities/Elizalde?type=Restaurant
echo
echo
echo "07. Delete Elizalde, type Restaurant2"
echo "====================================="
curl -X DELETE localhost:1026/v2/Entities/Elizalde
echo
echo
echo "08. Intent to Get Entity Elizalde - nothing found"
echo "================================================="
curl localhost:1026/v2/Entities/Elizalde
echo
echo

启动此测试之前,请先清理数据库。

[如果您在步骤04中将type=Restaurant更改为type=Restau餐厅,您应该会看到一个409,因为有两个实体的id为Elizalde]

我使用的经纪人版本是:

"version" : "1.0.0-next",
"uptime" : "0 d, 0 h, 54 m, 42 s",
"git_hash" : "70cc445d0555cbed50134452ae9858a7ddc05d7e",
"compile_time" : "Wed Apr 20 12:35:23 CEST 2016",
"compiled_by" : "kz",
"compiled_in" : "hoppe"

git hash:70cc445d0555cbed50134452ae9858a7ddc05d7e

最新更新