milo:Bad_SessionIdInvalid,会话ID无效

时间:2019-07-12 13:58:51

标签: opc-ua milo

我收到“会话ID无效”的信息。读取节点的值时出现异常,但是只是有时候,我知道会话没有超时,所以为什么?

例外:

 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)
Caused by: UaServiceFaultException: status=Bad_SessionIdInvalid, message=The session id is not valid.
at org.eclipse.milo.opcua.stack.client.UaTcpStackClient.lambda$receiveResponse$16(UaTcpStackClient.java:367)
at org.eclipse.milo.opcua.stack.core.util.ExecutionQueue$PollAndExecute.run(ExecutionQueue.java:107)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
... 3 more

线程“ pool-2-thread-2”中的异常java.lang.NullPointerException     在com.ggnykj.smartems.cloud.server.autocontrol.controller.OpcClientServerController.readNode(OpcClientServerController.java:116)     在com.ggnykj.smartems.cloud.server.autocontrol.server.SaveExOpcData.run(SaveExOpcData.java:59)     在java.base / java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)     在java.base / java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:628)     在java.base / java.lang.Thread.run(Thread.java:834)

有我的代码:

MyX509IdentityProvider x509IdentityProvider = new MyX509IdentityProvider(clientOption.opcServer.getCertFilePath(),
            clientOption.opcServer.getPrivateKeyPath());
    X509Certificate cert = 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;
}

当我读取节点时,出现了问题:

value = client.readValue(0.0, TimestampsToReturn.Both, nodeId).get();

但我不知道为什么

1 个答案:

答案 0 :(得分:0)

此StatusCode来自服务器。

也许您可以在Wireshark上捕获此行为,以确保您确实使用了自己认为的同一OpcUaClient实例,而不是某个会话超时的实例。或者,当您在新创建的Session上进行读取时,捕获可能会显示服务器有故障,并返回此StatusCode。