簡體   English   中英

固件[NGSI] Orion-Cygnus-Hadoop HTTPBadRequestException:通過Orion訂閱獲得的“ fiware-servicepath”

[英]FIWARE [NGSI] Orion-Cygnus-Hadoop HTTPBadRequestException: 'fiware-servicepath' through an Orion subscription

我想保留服務器中的一些歷史數據。 因此,文檔說明您必須先向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();

我生成的跟蹤如下所示:

TRACE1

TRACE2

TRACE3

再次感謝你。

您收到的錯誤消息似乎表明您正在嘗試使用較新的NGSI v2格式發送對Cygnus的訂閱,但是當前的Cygnus版本僅接受較舊的NGSI v1格式的attrsFormat=legacy因此,在以下情況下需要attrsFormat=legacy屬性設置訂閱

有關如何修復此問題的更多詳細信息,請參見此問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM