Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
ClassCastException when subscribing to event
March 13, 2014
11:56, EET
Avatar
Arildn
Member
Members
Forum Posts: 11
Member Since:
October 4, 2013
sp_UserOfflineSmall Offline

Hello,

We are currently integrating towards a production OPC UA server, until now we have been using a mock-server. The mock-server is written using the Prosys SDK, while the production server is not. When subscribing to a specific event in the address space of the production server, we experience the following error:

java.lang.ClassCastException: com.prosysopc.ua.client.MonitoredEventItem cannot be cast to com.prosysopc.ua.client.MonitoredDataItem
at com.prosysopc.ua.client.Subscription.a(Unknown Source) [Prosys-OPC-UA-Java-SDK-Client-Server-Binary-1.4.6-8021.jar:1.4.6.8021]
at com.prosysopc.ua.client.Subscription.handleNotificationDatas(Unknown Source) [Prosys-OPC-UA-Java-SDK-Client-Server-Binary-1.4.6-8021.jar:1.4.6.8021]
at com.prosysopc.ua.client.UaClient$a.b(Unknown Source) [Prosys-OPC-UA-Java-SDK-Client-Server-Binary-1.4.6-8021.jar:1.4.6.8021]
at com.prosysopc.ua.client.UaClient$a.run(Unknown Source) [Prosys-OPC-UA-Java-SDK-Client-Server-Binary-1.4.6-8021.jar:1.4.6.8021]
at java.lang.Thread.run(Thread.java:724) [na:1.7.0_40]

For the mock-server, the relevant address space paths for the specific event, MyEvent, is as follows:

Address space path | Class type | contains EventNotifierClass.SubscribeToEvents
——————————————————————————————–
/Objects/Devices/MyEvent | com.prosysopc.ua.client.nodes.UaObjectImpl | true
/Objects/Devices/Device1 | com.prosysopc.ua.client.nodes.UaObjectImpl | false
/Objects/Devices | com.prosysopc.ua.client.nodes.UaFolder | true
/Objects/Server | com.prosysopc.ua.client.nodes.UaObjectImpl | true
/Objects | com.prosysopc.ua.client.nodes.UaFolder | false

For the production server, the relevant address space paths for the specific event, MyEvent, is as follows:

Address space path | Class type | contains EventNotifierClass.SubscribeToEvents
——————————————————————————————-
/Objects/Devices/Device1/MyEvent/MyEvent | com.prosysopc.ua.client.nodes.UaObjectTypeImpl | N/A (Not a UaObject)
/Objects/Devices/Device1/MyEvent | com.prosysopc.ua.client.nodes.UaObjectImpl | true
/Objects/Devices/Device1 | com.prosysopc.ua.client.nodes.UaFolder | false
/Objects/Devices | com.prosysopc.ua.client.nodes.UaFolder | false
/Objects | com.prosysopc.ua.client.nodes.UaFolder | false
/Objects/Server | com.prosysopc.ua.client.nodes.UaObjectImpl | false

I guess the extra level of MyEvent should not directly be a problem. However, would it be a problem that /Objects/Devices/Device1/MyEvent/MyEvent is of type UaObjectTypeImpl, and therefore does not contain EventNotifierClass.SubscribeToEvents?

March 13, 2014
13:27, EET
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

Yes there should not be an ObjectType under an object instance. Unless it is related with a HasTypeDefinition reference.

The exception looks like there are MonitoredDataItems and MonitoredEventItems in the same subscription – and for some reason they have the same handle, which should not happen.

March 13, 2014
13:30, EET
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

Or the server is sending a DataChangeNotification when it should send an EventNotificationList.

March 17, 2014
9:28, EET
Avatar
Arildn
Member
Members
Forum Posts: 11
Member Since:
October 4, 2013
sp_UserOfflineSmall Offline

Thanks! After hours of stumbling around in Wireshark we figured the server actually sent events as DataChangeNotifications. The problem is now fixed at the server-side.

However, we are now facing a new challenge. The server sends the event as an extension object. In the usual callback for event data:

public void onEvent(MonitoredEventItem item, Variant[] eventFields) {

}

eventFields now contains a single item of type ExtensionObject (instead of each field represented as an item of a primitive type). How do we decode this data? Is the following blog post representative for how this should be done?

http://www.prosysopc.com/blog/2012/07/12/otso/using-complex-datatypes/

As far as I understand, in the blog post the serializer is setup at both the server- and client-side. In our case, we have no control over the server, and it does not use the Prosys SDK, will this be a problem? Are we still able to use the same approach on the client-side? Is the approach in the blog post the only way to handle extension objects in the Prosys SDK?

Moreover, we experience the following stack trace right before the onEvent() callback:

2014-03-17 10:34:27,604 WARN [Variant ] Unknown ExtensionObject
org.opcfoundation.ua.encoding.DecodingException: Bad_DecodingError (code=0x80070000, description="Cannot decode null")
at org.opcfoundation.ua.encoding.utils.SerializerComposition.getEncodeable(Unknown Source) [opc.ua.stack-1.01.330.14.jar:1.01.330.14]
at org.opcfoundation.ua.builtintypes.ExtensionObject.decode(Unknown Source) [opc.ua.stack-1.01.330.14.jar:1.01.330.14]
at org.opcfoundation.ua.builtintypes.ExtensionObject.decode(Unknown Source) [opc.ua.stack-1.01.330.14.jar:1.01.330.14]
at org.opcfoundation.ua.builtintypes.Variant.<init>(Unknown Source) [opc.ua.stack-1.01.330.14.jar:1.01.330.14]
at org.opcfoundation.ua.encoding.binary.BinaryDecoder.getVariant(Unknown Source) [opc.ua.stack-1.01.330.14.jar:1.01.330.14]
at org.opcfoundation.ua.encoding.binary.BinaryDecoder.getVariantArray(Unknown Source) [opc.ua.stack-1.01.330.14.jar:1.01.330.14]
at org.opcfoundation.ua.core.EncodeableSerializer$179.getEncodeable(Unknown Source) [opc.ua.stack-1.01.330.14.jar:1.01.330.14]
at org.opcfoundation.ua.encoding.utils.AbstractSerializer.getEncodeable(Unknown Source) [opc.ua.stack-1.01.330.14.jar:1.01.330.14]
at org.opcfoundation.ua.encoding.utils.SerializerComposition.getEncodeable(Unknown Source) [opc.ua.stack-1.01.330.14.jar:1.01.330.14]
at org.opcfoundation.ua.encoding.binary.BinaryDecoder.getEncodeableArray(Unknown Source) [opc.ua.stack-1.01.330.14.jar:1.01.330.14]
at org.opcfoundation.ua.core.EncodeableSerializer$178.getEncodeable(Unknown Source) [opc.ua.stack-1.01.330.14.jar:1.01.330.14]
at org.opcfoundation.ua.encoding.utils.AbstractSerializer.getEncodeable(Unknown Source) [opc.ua.stack-1.01.330.14.jar:1.01.330.14]
at org.opcfoundation.ua.encoding.utils.SerializerComposition.getEncodeable(Unknown Source) [opc.ua.stack-1.01.330.14.jar:1.01.330.14]
at org.opcfoundation.ua.builtintypes.ExtensionObject.decode(Unknown Source) [opc.ua.stack-1.01.330.14.jar:1.01.330.14]
at org.opcfoundation.ua.builtintypes.ExtensionObject.decode(Unknown Source) [opc.ua.stack-1.01.330.14.jar:1.01.330.14]
at com.prosysopc.ua.client.Subscription.a(Unknown Source) [prosys-opc-ua-java-sdk-client-server-binary-1.4.8-8731.jar:1.4.8.8731]
at com.prosysopc.ua.client.Subscription.handleNotificationDatas(Unknown Source) [prosys-opc-ua-java-sdk-client-server-binary-1.4.8-8731.jar:1.4.8.8731]
at com.prosysopc.ua.client.UaClient$a.b(Unknown Source) [prosys-opc-ua-java-sdk-client-server-binary-1.4.8-8731.jar:1.4.8.8731]
at com.prosysopc.ua.client.UaClient$a.run(Unknown Source) [prosys-opc-ua-java-sdk-client-server-binary-1.4.8-8731.jar:1.4.8.8731]
March 17, 2014
9:43, EET
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

The message sent by the server is still not correct. You need to get the server send correct messages before it can work.

March 17, 2014
9:53, EET
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

Or having another look at the stack trace, maybe the problem is indeed that there is a field that cannot be decoded. However, the server may be encoding all the fields in one ExtensionObject, although it should send them as separate values. Which is not correct. After all, you define in the client which fields you want, and should know that they have known data types, e.g. ‘LocalizedText Message’, etc.

March 18, 2014
6:17, EET
Avatar
Nils-H
Member
Members
Forum Posts: 21
Member Since:
March 18, 2014
sp_UserOfflineSmall Offline

The latter seems to be the case. The event data is returned as one item, the ExtensionObject. The ExtensionObject is marked with the node id of a complex type defined within Types/EventTypes on the server. We have successfully decoded the object by registering a serializer for this type, and “manually” extract the data in the correct order from the BinaryDecoder that is passed into the “getEncodable” method. However, I would expect this to be done automatically by the SDK since the type of the object is known already. Why is this not the case? It appears to my that having to do it this way kind of defeats the purpose of the type definition.

If this is because the event data is not sent as the SDK expects it to, is there some reference to the OPC UA specification that describes the “proper” way of emitting events?

March 18, 2014
16:37, EET
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

Yes, that’s not the proper way to define the event data. The NotificationData is defined in Part 4. of the specification.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
10 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

rocket science: 77

ibrahim: 75

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

fred: 41

Member Stats:

Guest Posters: 0

Members: 680

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1467

Posts: 6259

Newest Members:

DonaldPooma, fidelduke938316, Jan-Pfizer, DavidROunc, fen.pang@woodside.com, aytule, rashadbrownrigg, christi10l, ahamad1, Flores Frederick

Moderators: Jouni Aro: 1009, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 983, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 26, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 321, Lusetti: 0, Ari-Pekka Soikkeli: 5

Administrators: admin: 1