Proton-CEP 接收事件 API NGSI/XML NullPointerException
Proton-CEP Receiving events API NGSI/XML NullPointerException
我无法将 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
将以下 JSON 事件直接发送到 CEP 有效:
{"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 格式问题。
phqp JSON 对象被接受,但 NGSI/XML 对象失败的原因是什么?
事实证明,使用 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 中提供(隐藏?)。
当NGSI/xml消息被CEP解析时,NGSI消息和CEP输入事件之间有一个翻译过程。
CEP 中定义的匹配输入事件必须具有名称 <entity type>ContextUpdate
,在您的情况下为 DeviceContextUpdate
此输入事件必须具有以下属性:
- entityId – 字符串类型。此属性保存消息中提供的 entityId 值
- entityType – 字符串类型。此属性保存消息中提供的实体类型
详细信息和示例可以在 CEP user guide appendix
中找到
我无法将 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
将以下 JSON 事件直接发送到 CEP 有效:
{"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 格式问题。
phqp JSON 对象被接受,但 NGSI/XML 对象失败的原因是什么?
事实证明,使用 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 中提供(隐藏?)。
当NGSI/xml消息被CEP解析时,NGSI消息和CEP输入事件之间有一个翻译过程。
CEP 中定义的匹配输入事件必须具有名称 <entity type>ContextUpdate
,在您的情况下为 DeviceContextUpdate
此输入事件必须具有以下属性:
- entityId – 字符串类型。此属性保存消息中提供的 entityId 值
- entityType – 字符串类型。此属性保存消息中提供的实体类型
详细信息和示例可以在 CEP user guide appendix
中找到