0

我收到“会话 ID 无效”。读取节点值时出现异常,但有时,我知道会话没有超时,那为什么呢?

例外:</p>

java.util.concurrent.ExecutionException: UaServiceFaultException: status=Bad_SessionIdInvalid, message=The session id is not valid.
at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1999)
at com.ggnykj.smartems.cloud.server.autocontrol.client.OpcClientServer.readNode(OpcClientServer.java:230)
at com.ggnykj.smartems.cloud.server.autocontrol.controller.OpcClientServerController.readNode(OpcClientServerController.java:115)
at com.ggnykj.smartems.cloud.server.autocontrol.server.SaveExOpcData.run(SaveExOpcData.java:59)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)

原因:UaServiceFaultException:状态=Bad_SessionIdInvalid,消息=会话 ID 无效。在 org.eclipse.milo.opcua.stack.client.UaTcpStackClient.lambda$receiveResponse$16(UaTcpStackClient.java:367) 在 org.eclipse.milo.opcua.stack.core.util.ExecutionQueue$PollAndExecute.run(ExecutionQueue.java :107) 在 java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264) 的 java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ) 在 java.base/java.util.concurrent.FutureTask.run(FutureTask.java) ... com.ggnykj.smartems.cloud 的线程“pool-2-thread-2”java.lang.NullPointerException 中还有 3 个异常.server.autocontrol.controller.OpcClientServerController.readNode(OpcClientServerController.java:116) 在 com.ggnykj.smartems.cloud.server.autocontrol.server。

我的代码:</p>

MyX509IdentityProvider x509IdentityProvider = new MyX509IdentityProvider(clientOption.opcServer.getCertFilePath(), clientOption.opcServer.getPrivateKeyPath()); X509Certificate 证书 = x509IdentityProvider.getCertificate(); KeyPair keyPair = new KeyPair(cert.getPublicKey(), x509IdentityProvider.getPrivateKey());

    OpcUaClientConfig config = OpcUaClientConfig.builder()
        .setApplicationName(LocalizedText.english(clientOption.opcServer.getOpcServerName()))
        //.setApplicationUri("urn:eclipse:milo:examples:client")
        .setApplicationUri("")
        //.setCertificate(loader.getClientCertificate())
        //.setKeyPair(loader.getClientKeyPair())
        .setCertificate(cert)
        .setKeyPair(keyPair)
        .setEndpoint(endpoint)
        .setIdentityProvider(clientOption.getIdentityProvider())
        .setChannelLifetime(uint(600000000))
        .setSessionTimeout(uint(600000000))
        //.setRequestTimeout(uint(5000))
        .build();

    return new OpcUaClient(config);

 private OpcUaClient getOpcClient(OpcServer opcServer){
    OpcUaClient client = null;
    if(null!=opcClientMap.get(opcServer.getOpcServerId())){
        client = opcClientMap.get(opcServer.getOpcServerId());
    }else{
        try {
            ClientOption clientOption = new ClientOption(opcServer);
            client =  new ClientOptionRunner(clientOption).createClient();
        }catch (Throwable t){
            logger.error("Error getting client: {}", t.getMessage(), t);
        }
        opcClientMap.put(opcServer.getOpcServerId(),client);
    }
    return client;

}

public DataValue readNode(OpcServer opcServer,NodeId nodeId){
    OpcUaClient client = getOpcClient(opcServer);
    DataValue value = null;

    try {
        client.connect().get();  
        value = client.readValue(0.0, TimestampsToReturn.Both, nodeId).get(); 
    }catch (Exception e){
        e.printStackTrace();
    }
    return value;
}
4

0 回答 0