milo:Bad_SessionIdInvalid“会话ID无效。”

时间:2019-07-10 15:12:38

标签: 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)

由以下原因引起:UaServiceFaultException:status = 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.Executors $ RunnableAdapter.call(Executors.java:515)     在java.base / java.util.concurrent.FutureTask.run $$$ capture(FutureTask.java:264)     在java.base / java.util.concurrent.FutureTask.run(FutureTask.java)     ...另外3个 线程“ 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 =新的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;
}

0 个答案:

没有答案