简体   繁体   English

固件[NGSI] Orion-Cygnus-Hadoop HTTPBadRequestException:通过Orion订阅获得的“ fiware-servicepath”

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

I want to persist some historical data from my server. 我想保留服务器中的一些历史数据。 So the documentation says that you must first send a subscription to Orion and then Orion will send the notification to Cygnus. 因此,文档说明您必须先向Orion发送订阅,然后Orion会将通知发送给Cygnus。

I made the subscription like this: 我这样订阅:

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);

And the creation of entities: 并创建实体:

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);

Then, Cygnus log tell me: 然后,天鹅座日志告诉我:

HTTPBadRequestException: 'fiware-servicepath' header value does not match the number of notified context responses [...]

Do any of you know why this is happening? 你们当中有人知道为什么会这样吗? The creation of the headers should be done by Orion or, failing that, by using the configuration of the Cygnus... 标头的创建应由Orion完成,否则,应使用Cygnus的配置...

Thank you in advance. 先感谢您。

UPDATE: 更新:

I have changed the http client of the server to make it easier to incorporate headers. 我更改了服务器的http客户端,以使其更易于合并标头。

My subscription: 我的订阅:

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) {

My update context: 我的更新上下文:

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();

And the trace I generate is like this: 我生成的跟踪如下所示:

TRACE1

TRACE2

TRACE3

Thank you again. 再次感谢你。

The error message you are receiving would seem to indicate that you are attempting to send a subscription to Cygnus using the newer NGSI v2 format however the current Cygnus release only accepts notifications in the older NGSI v1 format- the attrsFormat=legacy attribute is therefore required when setting up the subscription 您收到的错误消息似乎表明您正在尝试使用较新的NGSI v2格式发送对Cygnus的订阅,但是当前的Cygnus版本仅接受较旧的NGSI v1格式的attrsFormat=legacy因此,在以下情况下需要attrsFormat=legacy属性设置订阅

See this question for more details about how to fix it. 有关如何修复此问题的更多详细信息,请参见此问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM