Java client implementation for NGSI and ContextBroker communications

≡放荡痞女 提交于 2019-12-24 04:26:11

问题


In order to not reinventing the wheel I am looking for some existing library for connecting to Orion Context Broker from Java code.

I have found that at fiware.org there is published sample code but I do not like it as it does not hide raw XML usage.

I have also found some code at github

Some people seems to have worked on it but I did not find the sources.

Is there some open library becoming popular reference on it? being API clean and easy to use and hiding low level things? (XML parsing, NGSI communications, REST, etc.)


回答1:


We have build a NGSI V1 (JSON only) client library for the Fiware-Cepheus project.

In your pom.xml:

<dependency>
    <groupId>com.orange.cepheus</groupId>
    <artifactId>cepheus-ngsi</artifactId>
    <version>4.4.3-SNAPSHOT</version>
</dependency>

In your code :

@Autowired
NgsiClient ngsiClient;

...

// Prepare UpdateContext  
UpdateContext updateContext = new UpdateContext(UpdateAction.UPDATE);
ContextElement contextElement = new ContextElement();
contextElement.setEntityId(new EntityId("Room1", "Room", false));
ContextAttribute attr = new ContextAttribute("temp", "double", "20");
contextElement.setContextAttributeList(Collections.singletonList(attr);
updateContext.setContextElements(Collections.singletonList(contextElement));

// Synchronous call
ngsiClient.updateContext("http://broker:port", null, updateContext).get();

// Asynchronous call
ngsiClient.updateContext("http://broker:port", null, updateContext).addCallback(
      updateContextResponse -> { /* success response */ },
      throwable -> { /* error response */ });

This library is still under development (available as SNAPSHOT only on the Sonatype repository) and is not considered stable yet, but is fully tested.

It is missing support for many NGSI9 requests, but if your main use is NGSI10, you should be covered.



来源:https://stackoverflow.com/questions/30594550/java-client-implementation-for-ngsi-and-contextbroker-communications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!