首页 文章

Proton-CEP接收事件API NGSI / XML NullPointerException

提问于
浏览
2

我无法将NGSI / XML格式的事件发送到我的Proton-CEP GE . 用例是我需要Orion将事件发送给CEP .

Orion配置为向Proton发送正确接收的事件 . 但是,Proton收到它们时会报告 NullPointerException .

catalina.out的输出是:

Nov 12, 2015 7:30:27 PM com.ibm.hrl.proton.webapp.providers.EventXmlNgsiMessageReader readFrom
INFO: started event message body reader
Nov 12, 2015 7:30:27 PM com.ibm.hrl.proton.webapp.providers.EventXmlNgsiMessageReader readFrom
INFO: Event: DeviceContextUpdate
Nov 12, 2015 7:30:27 PM com.ibm.hrl.proton.webapp.providers.EventXmlNgsiMessageReader readFrom
SEVERE: Could not parse XML NGSI event java.lang.NullPointerException, reason: null
 last attribute name: null last value: null
Nov 12, 2015 7:30:27 PM com.ibm.hrl.proton.webapp.providers.EventXmlNgsiMessageReader readFrom
INFO: finished event message body reader
Nov 12, 2015 7:30:27 PM com.ibm.hrl.proton.webapp.resources.EventResource submitNewEvent
INFO: starting submitNewEvent
Nov 12, 2015 7:30:27 PM com.ibm.hrl.proton.webapp.resources.EventResource submitNewEvent
SEVERE: Could not send event, reason: java.lang.NullPointerException, message: null

直接向CEP发送以下JSON事件:

{"Name": "Device", "datacount5": "10", "lastupdate": "12/11/2015-17:09:08"}

INFO: starting submitNewEvent
Nov 12, 2015 7:31:39 PM com.ibm.hrl.proton.router.EventRouter routeTimedObject
INFO: routeTimedObject: forwarding event Device; EventId=32314f63-75d3-489f-9d8d-dbd0ba4a42b8; Chronon=null; DetectionTime=1447353099831; Name=Device; Certainty=0.0; Cost=0.0; lastupdate=1447344548000; EventSource=; OccurrenceTime=null; datacount5=10; Annotation=; Duration=0.0; ExpirationTime=null;  to consumer...
Nov 12, 2015 7:31:39 PM com.ibm.hrl.proton.webapp.resources.EventResource submitNewEvent
INFO: events sent to proton runtime...

但是,在NGSI / XML中发送它会产生如上所述的NullPointer异常 . 发送的消息是:

<notifyContextRequest>
  <subscriptionId>51a60c7a286043f73ce9606c</subscriptionId>
  <originator>localhost</originator>
  <contextResponseList>
    <contextElementResponse>
      <contextElement>
        <entityId type="Device" isPattern="false">
          <id>Device.imei2</id>
        </entityId>
        <contextAttributeList>
          <contextAttribute>
            <name>datacount5</name>
            <contextValue>5</contextValue>
          </contextAttribute>
        </contextAttributeList>
      </contextElement>
      <statusCode>
        <code>200</code>
        <reasonPhrase>OK</reasonPhrase>
      </statusCode>
    </contextElementResponse>
  </contextResponseList>
</notifyContextRequest>

注意:我也尝试发送the documentation中的消息,我得到相同的NullPointerException,所以我知道它不是XML格式化问题 .

接受JSON对象的phqp是什么原因,但NGSI / XML失败了?

2 回答

  • 0

    当CEP解析NGSI / xml消息时,NGSI消息和CEP输入事件之间存在转换过程 .

    在CEP中定义的匹配输入事件必须具有名称 <entity type>ContextUpdate ,在您的情况下为 DeviceContextUpdate

    此输入事件必须具有以下属性:

    • entityId - 类型为String . 此属性保存消息中提供的entityId值

    • entityType - 类型为String . 此属性保存消息中提供的实体类型

    详细信息和示例可在CEP user guide appendix中找到

  • 2

    事实证明,使用JSON REST发送事件时,事件名称与XML / NGSI格式不同 .

    使用JSON时,事件名称与JSON对象中描述的完全相同

    {"Name": "Device", "datacount5": "10"}
    

    所以, Device .

    在XML / NGSI的情况下,即使实体类型也设置为 Device ,如下所示:

    <entityId type="Device" isPattern="false">
      <id>Device.imei2</id>
    </entityId>
    

    事件名称将转换为 DeviceContextUpdate .

    Appendix A of the user documentation中提供(隐藏?)此信息 .

相关问题