我们在测试导游应用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菜谱http://fiware.github.io/context.Orion/api/v2/cookbook/中的JSON更新属性的详细说明进行操作
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错误。
复制步骤:
cd fiware-devguide-app/docker/compose
和docker-compose -f docker-compose.yml up
有关猎户座版的信息:
<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-compose,我们也遇到了相同的错误。
这是有关上一版本的信息:
{
"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"
}
}
我们已经在调试模式下执行了Context Broker,如果我们执行:
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
答案 0 :(得分:0)
我试图在有限的环境中重现您的问题(只是创建实体&#39; Elizalde&#39;)但没有成功。对我来说它很好......
首先,以下一行:
/v2/Entities/Elizalde/attrs/aggregateRating/value?Type=Restaurant
是不正确的。它必须是.../value?type=Restaurant
,因为URI参数区分大小写。
使用Type而不是type意味着忽略Type并且type不存在,因此PUT将攻击称为Elizalde的所有实体,无论其类型如何。你可能只有一个,所以“好的”#39;如果您有多个名为Elizalde的实体,那么您将获得409(冲突)作为响应,而这不是您的情况,因为您看到404(未找到)。
现在,我不知道你为什么会得到404.在我的简单测试中,一切正常(我使用的是经纪人的最新版本,但这不应该改变任何东西)。
为了尝试解决您的问题,我建议您让代理以详细模式启动(使用-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中更改类型=餐馆 类型=餐馆,则应该看到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