我想从我的服务器中保留一些历史数据。所以文档说你必须首先向 Orion 发送订阅,然后 Orion 会将通知发送给 Cygnus。
我是这样订阅的:
Entity payload = Entity.json("{\r\n" +
" \"entities\": [{\r\n" +
" \"type\": \"Usuario\",\r\n" +
" \"isPattern\": \"true\",\r\n" +
" \"id\": \"Usuario*\"\r\n" +
" }],\r\n" +
" \"attributes\": [],\r\n" +
" \"reference\": \"http://192.168.10.3:5050/notify\",\r\n" +
" \"duration\": \"P4Y\",\r\n" +
" \"notifyConditions\": [{\r\n" +
" \"type\": \"ONCHANGE\",\r\n" +
" \"condValues\": [\r\n" +
" \"speed\"\r\n" +
" ]\r\n" +
" }],\r\n" +
" \"throttling\": \"PT0.001S\"\r\n" +
"}");
Response response = client.target("http://192.168.10.3:1026/v1/subscribeContext")
.request(MediaType.APPLICATION_JSON_TYPE)
.post(payload);
以及实体的创建:
Entity payload = Entity.json("{ \"type\": \"Usuario\", \"id\": \"Usuario22\", \"temperature\": { \"value\": \"80.0\" }, \"location\": { \"value\": \""+latitud+", "+altitud+"\", \"type\": \"geo:point\", \"metadata\": { \"crs\": { \"value\": \"WGS84\" } } }}");
Response response = client.target("http://192.168.10.3:1026/v2/entities")
.request(MediaType.APPLICATION_JSON_TYPE)
.post(payload);
然后,天鹅座日志告诉我:
HTTPBadRequestException: 'fiware-servicepath' header value does not match the number of notified context responses [...]
你们中有人知道为什么会这样吗?标头的创建应该由 Orion 完成,或者,如果失败,则使用 Cygnus 的配置...
先感谢您。
更新:
我已经更改了服务器的 http 客户端,以便更容易合并标头。
我的订阅:
CloseableHttpClient client = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("http://192.168.10.3:1026/v1/subscribeContext");
String json = "{\r\n" +
" \"entities\": [{\r\n" +
" \"type\": \"cargador\",\r\n" +
" \"isPattern\": \"true\",\r\n" +
" \"id\": \"cargador*\"\r\n" +
" }],\r\n" +
" \"attributes\": [\"speed\"],\r\n" +
" \"reference\": \"http://192.168.10.3:5050/notify\",\r\n" +
" \"duration\": \"P4Y\",\r\n" +
" \"notifyConditions\": [{\r\n" +
" \"type\": \"ONCHANGE\",\r\n" +
" \"condValues\": [\r\n" +
" \"speed\"\r\n" +
" ]\r\n" +
" }],\r\n" +
" \"throttling\": \"PT0.001S\"\r\n" +
"}";
StringEntity entity;
try {
entity = new StringEntity(json);
httpPost.setEntity(entity);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
httpPost.setHeader("fiware-servicepath", "/");
CloseableHttpResponse response;
response = client.execute(httpPost);
System.out.println(response.getStatusLine());
client.close();
} catch (UnsupportedEncodingException e1) {
我的更新上下文:
CloseableHttpClient client = HttpClients.custom().setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build()).build();
HttpPost httpPost = new HttpPost("http://192.168.10.3:1026/v1/updateContext");
String json = "{\r\n" +
" \"contextElements\": \r\n" +
"\r\n" +
" \r\n" +
"\r\n" +
" [\r\n" +
" {\r\n" +
" \"type\": \"cargador\",\r\n" +
" \"isPattern\": \"false\",\r\n" +
" \"id\": \"cargador48\",\r\n" +
" \"attributes\": [\r\n" +
" {\r\n" +
" \"name\": \"speed\",\r\n" +
" \"type\": \"float\",\r\n" +
" \"value\": \"798\"\r\n" +
" }\r\n" +
" ]\r\n" +
" }\r\n" +
" ],\r\n" +
" \"updateAction\": \"APPEND\"\r\n" +
" }";
StringEntity entity;
try {
entity = new StringEntity(json);
httpPost.setEntity(entity);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
httpPost.setHeader("fiware-servicepath", "/");
CloseableHttpResponse response;
response = client.execute(httpPost);
System.out.println(response.getStatusLine());
client.close();
我生成的跟踪是这样的:
再次感谢你。