13:50, EEST
September 12, 2024
I am currently transfering our custom implementation of UaNode Types to a Code generated version. I created an UaNodeSet, code generation is already working and am able to register the generated ServerInformationModel from the source code.
However I am getting multiple ModelExceptions when I try to load the model into the address space. Seems like none of the defined references are created.
Failed to create reference: ns=2;i=1008—>nsu=http://xxx/opcua;i=1009 forward:true type: i=46java.lang.NullPointerException: Cannot invoke “com.prosysopc.ua.server.ServerUserIdentity.getType()” because the return value of “com.prosysopc.ua.server.Session.getUserIdentity()” is null (near line -1)
Failed to create reference: ns=2;i=1008—>nsu=http://xxx/opcua;i=1010 forward:true type: i=47java.lang.NullPointerException: Cannot invoke.
“com.prosysopc.ua.server.ServerUserIdentity.getType()” because the return value of “com.prosysopc.ua.server.Session.getUserIdentity()” is null (near line -1)
Failed to create reference: ns=2;i=1008—>nsu=http://opcfoundation.org/UA/;i=2041 forward:false type: i=45java.lang.NullPointerException: Cannot invoke “com.prosysopc.ua.server.ServerUserIdentity.getType()” because the return value of “com.prosysopc.ua.server.Session.getUserIdentity()” is null (near line -1)
….
I had a look at the tutorial and i am not sure what causes this error to happen. Can you give me some hints how to solve this?
Kind regards,
Susanne
14:26, EEST
April 3, 2012
Hi,
Generally speaking a Session should have nothing to with information model loading, thus the error is odd. Or well historically there was an idea that maybe one could do that from the Client side, but that doesn’t basically exist nowadays. You could add individual nodes however and some APIs are related to that, which possibly could have been used accidentally here.
Thus, please look at the com.prosysopc.ua.samples.server.SampleConsoleServer.loadInformationModels() in the sampleconsoleserver example. It contains (commented) examples of loading nodesets. Copied as-is the method contents:
// // Register generated classes
// server.registerModel(DiServerInformationModel.MODEL);
// server.registerModel(AdiServerInformationModel.MODEL);
//
// // Load the standard information models
// try {
// // You can reference these bundled models either directly
// server.getAddressSpace().loadModel(DiServerInformationModel.class.getResource(“Opc.Ua.Di.NodeSet2.xml”).toURI());
//
// // or via the codegenerated helper getLocationURI() method
// server.getAddressSpace().loadModel(AdiServerInformationModel.getLocationURI());
//
// // You can also register and load model in one call
// server.registerAndLoadModel(PlcServerInformationModel.MODEL,
// PlcServerInformationModel.getLocationURI());
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
If that doesn’t help, can you tell how you are loading the model?
P.S.
Technically if the resources outputs of Codegen are on the classpath, SDK can automatically discover and do the registerModel automatically (models must be loaded manually).
11:05, EEST
September 12, 2024
In my first take I put the model xml in my resources folder and only added the generated sources to the classpath using the build-helpaer-maven-plugin.
I originally used the following code for loading the model
server.registerModel(ServerInformationModel.MODEL);
server.getAddressSpace().loadModel(getClass().getClassLoader().getResourceAsStream(“MyTypes.xml”));
I noticed that server.getAddressSpace().loadModel(ServerInformationModel.getLocationURI()); returns null in that setup.
I have now updated my pom file to add the resources to classpath as well. I also removed the model xml from the resources folder, just in case. ServerInformationModel.getLocationURI() returns a valid result now, but loading the model results in the same error I reported above, no matter if I call registerModel explicitly or not (I suppose this now works automatically).
Could there be something wrong in the order I initialize the server and the NodeManager?
13:05, EEST
April 3, 2012
I have a theory.
Normally there shouldn’t be anything that could cause “java.lang.NullPointerException: Cannot invoke “com.prosysopc.ua.server.ServerUserIdentity.getType()” because the return value of “com.prosysopc.ua.server.Session.getUserIdentity()”, since nothing related to model loading should be Session-related.
However (and I did test this as well now), IF you have taken com.prosysopc.ua.samples.server.MyNodeManagerListener in the sampleconsoleserver as-is and added that to the NodeManagerUaNode to which you are trying to load the model, our sample code
public void onAddReference(ServiceContext serviceContext, NodeId sourceNodeId, UaNode sourceNode,
ExpandedNodeId targetNodeId, UaNode targetNode, NodeId referenceTypeId, UaReferenceType referenceType,
boolean isForward) throws StatusException {
// Notification of a reference addition request.
// Note that NodeManagerTable#setNodeManagementEnabled(true) must be
// called to enable these methods.
// Anyway, we just check the user access.
checkUserAccess(serviceContext);
}
+
// Do not allow for anonymous users
if (serviceContext.getSession().getUserIdentity().getType().equals(UserTokenType.Anonymous)) {
throw new StatusException(StatusCodes.Bad_UserAccessDenied);
}
}
will cause the error. This should potentially be labeled as our bug, since that doesn’t happen for adding a node, since that internally is checked that is the ServiceContext.isInternal() in which case the listener is not called (and there is a separate protected method (createNodeForNodeSet2) one could override in the NodeManagerUaNode. But there isn’t anything similar to References, so seems we do call that listener method. And the internal context session is null (intentionally).
Thus, you should be able to make this work by changing the ‘checkUserAccess’ (or do similar on your code) to do something like
return;
}
Since the listener methods are only intended for the AddReferences and AddNodes service-calls originating from a client, the server-side loading isn’t “user-specific” or something session-access rights would be checked.
Please let us know if this was the case or not, but I think there is high likelihood that this was the issue. Probably our samples should change a bit to account for this possibility in the future (and/or not call the references methods from nodesetloading).
Most Users Ever Online: 1919
Currently Online:
35 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 144
rocket science: 88
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 726
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1529
Posts: 6471
Newest Members:
gabriellabachus, Deakin, KTP25Zof, Wojciech Kubala, efrennowell431, wilfredostuart, caitlynfajardo, jeromechubb7, franciscagrimwad, adult_galleryModerators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0
Administrators: admin: 1