【问题标题】:FIWARE [NGSI] Orion-Cygnus-Hadoop HTTPBadRequestException: 'fiware-servicepath' through an Orion subscriptionFIWARE [NGSI] Orion-Cygnus-Hadoop HTTPBadRequestException: 'fiware-servicepath' 通过 Orion 订阅
【发布时间】:2018-08-30 21:41:18
【问题描述】:

我想从我的服务器中保留一些历史数据。所以文档说你必须先向 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();

而我生成的trace是这样的:

再次感谢您。

【问题讨论】:

  • 您是否指定标题?除了一般的 headers 之外,对于 POST 请求,请查看此链接以了解如何使用 fiware-servicepath 标头:fiware-orion.readthedocs.io/en/master/user/service_path/…。如果您使用标题,请用它们更新您的问题。
  • @DaltonCézane 我刚刚更新了您提供给我的信息。现在我已经对错误进行了跟踪,以防我遗漏了什么。谢谢。
  • 根据你上次的 lof trace Cygnus 与 HDFS 端点的通信有问题,你是否使用容器运行服务?,你能检查一下 HDFS 的主机和端口吗?。
  • 你好@anmunoz,确实,问题出在 Cygnus 和 Hadoop 之间的连接上。 Hadoop 以主机名响应,而 Cygnus 无法将数据发送给他。修改 Cygnus 容器的 /etc/hosts 有效。非常感谢大家的帮助。

标签: fiware fiware-orion fiware-cygnus fiware-cosmos


【解决方案1】:

您收到的错误消息似乎表明您正在尝试使用较新的 NGSI v2 格式向 Cygnus 发送订阅,但是当前的 Cygnus 版本仅接受旧 NGSI v1 格式的通知 - attrsFormat=legacy 属性是因此在设置订阅时需要

有关如何修复它的更多详细信息,请参阅this question

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多