You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by ld...@apache.org on 2021/10/21 21:18:27 UTC

[plc4x] branch develop updated: PLC4X-319 Fix missing call to callback in case of errors/class casts.

This is an automated email from the ASF dual-hosted git repository.

ldywicki pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new 69174f3  PLC4X-319 Fix missing call to callback in case of errors/class casts.
69174f3 is described below

commit 69174f31ded6e5a5406f59ac2500edf38d4eb7c4
Author: Ɓukasz Dywicki <lu...@code-house.org>
AuthorDate: Thu Oct 21 23:17:58 2021 +0200

    PLC4X-319 Fix missing call to callback in case of errors/class casts.
---
 .../java/opcua/protocol/OpcuaProtocolLogic.java    | 24 +++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaProtocolLogic.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaProtocolLogic.java
index aa7dfa3..e7c2d78 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaProtocolLogic.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaProtocolLogic.java
@@ -174,13 +174,27 @@ public class OpcuaProtocolLogic extends Plc4xProtocolBase<OpcuaAPU> implements H
             Consumer<byte []> consumer = opcuaResponse -> {
                 PlcReadResponse response = null;
                 try {
-                    response = new DefaultPlcReadResponse(request, readResponse(request.getFieldNames(), ((ReadResponse) ExtensionObjectIO.staticParse(new ReadBufferByteBased(opcuaResponse, true), false).getBody()).getResults()));
+                    ExtensionObjectDefinition reply = ExtensionObjectIO.staticParse(new ReadBufferByteBased(opcuaResponse, true), false).getBody();
+                    if (reply instanceof ReadResponse) {
+                        future.complete(new DefaultPlcReadResponse(request, readResponse(request.getFieldNames(), ((ReadResponse) reply).getResults())));
+                    } else {
+                        if (reply instanceof ServiceFault) {
+                            ExtensionObjectDefinition header = ((ServiceFault) reply).getResponseHeader();
+                            LOGGER.error("Read request ended up with ServiceFault: {}", header);
+                        } else {
+                            LOGGER.error("Remote party returned an error '{}'", reply);
+                        }
+
+                        Map<String, ResponseItem<PlcValue>> status = new LinkedHashMap<>();
+                        for (String key : request.getFieldNames()) {
+                            status.put(key, new ResponseItem<>(PlcResponseCode.INTERNAL_ERROR, null));
+                        }
+                        future.complete(new DefaultPlcReadResponse(request, status));
+                        return;
+                    }
                 } catch (ParseException e) {
-                    e.printStackTrace();
+                    future.completeExceptionally(new PlcRuntimeException(e));
                 };
-
-                // Pass the response back to the application.
-                future.complete(response);
             };
 
             /* Functional Consumer example using inner class */