You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@plc4x.apache.org by Torsten Uhr <to...@sql-ag.de> on 2021/10/21 11:12:04 UTC

ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse

Hi all,

if I create an OPCUA connection (to milo) and wait 5 minutes before sending a read request the error attached below is logged and the read execution blocks infinitely.
I'm used codebase 0.9.0 and 0.10.0 snapshot.
Note: The wait simulates a connection created earlier and get from a connection pool in a managed environment like application server.
I think theres a timeout for pending connections on the server side. I would expect, that the driver should throw an exception rather blocking?

[nioEventLoopGroup-2-1] WARN io.netty.channel.DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
io.netty.handler.codec.DecoderException: java.lang.ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse (org.apache.plc4x.java.opcua.readwrite.ServiceFault and org.apache.plc4x.java.opcua.readwrite.ReadResponse are in unnamed module of loader 'app')
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:98)
        at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
        at io.netty.handler.codec.ByteToMessageCodec.channelRead(ByteToMessageCodec.java:103)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse (org.apache.plc4x.java.opcua.readwrite.ServiceFault and org.apache.plc4x.java.opcua.readwrite.ReadResponse are in unnamed module of loader 'app')
        at org.apache.plc4x.java.opcua.protocol.OpcuaProtocolLogic.lambda$read$0(OpcuaProtocolLogic.java:177)
        at org.apache.plc4x.java.opcua.context.SecureChannel.lambda$4(SecureChannel.java:212)
        at org.apache.plc4x.java.spi.Plc4xNettyWrapper.decode(Plc4xNettyWrapper.java:175)
        at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88)
        ... 23 more


JUnit regeression test:

import org.apache.plc4x.java.PlcDriverManager;
import org.apache.plc4x.java.api.PlcConnection;
import org.apache.plc4x.java.api.messages.PlcReadRequest;
import org.junit.Assert;
import org.junit.jupiter.api.Test;

public class RegressionTest
{
   @Test
   public void Timeout()
   {
      String connectionString = "opcua:tcp://localhost:12686/milo?discovery=false";
      final int TIMEOUT = 300 * 1000;

      try (PlcConnection plcConnection = new PlcDriverManager().getConnection( connectionString ))
      {
         Thread.sleep( TIMEOUT );

         PlcReadRequest.Builder builder = plcConnection.readRequestBuilder();
         builder.addItem("value", "ns=2;s=HelloWorld/ScalarTypes/String");

         builder.build().execute().get();
      }
      catch( Throwable thr )
      {
         Assert.fail( thr.getMessage() );
      }
   }
}


With best regards
Torsten Uhr


AW: AW: AW: ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse

Posted by Torsten Uhr <to...@sql-ag.de>.
Hi Chris,

sounds good and abstracts from OPCUA.

Torsten
Leiter Entwicklung TRANSCONNECT®




SQL Projekt AG  ▪ Franklinstraße 25 a  ▪ 01069 Dresden

Telefon:	(0351) 87619-0
Telefax:	(0351) 87619-99
E-Mail: 	torsten.uhr@sql-ag.de
Web:	www.sql-ag.de 

Aufsichtsratsvorsitzender: Jürgen Bittner
Vorstand: Stefan Ehrlich, Jens Gärtner (Sprecher)
Handelsregister: HRB 38924 Amtsgericht Dresden
Die Zertifizierungsstelle der TÜV SÜD Management Service GmbH bescheinigt, dass die SQL Projekt AG für den Geltungsbereich "Entwicklung 
und Vertrieb von Datenbank- und Integrationslösungen sowie Beratung, Training und Support auf dem Gebiet datenbankgestützter 
Softwareprodukte" ein Qualitätsmanagementsystem eingeführt hat und anwendet.


Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. 
Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail oder Inhalte ist nicht gestattet. 

This e-mail may contain confidential and/or privileged information. 
If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

-----Ursprüngliche Nachricht-----
Von: Christofer Dutz <ch...@c-ware.de> 
Gesendet: Freitag, 22. Oktober 2021 13:22
An: dev@plc4x.apache.org
Betreff: AW: AW: AW: ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse

Hi,

I think we only had the status codes in there that we needed so far.
However it would be cool if the codes wouldn't differ for each connection type.
So how about adding a "CONNECTION_INVALID" code? 

I guess an OPC-UA Session is what other protocols consider a connection - right?

Just my thoughts to that.

Chris

-----Ursprüngliche Nachricht-----
Von: Torsten Uhr <to...@sql-ag.de>
Gesendet: Freitag, 22. Oktober 2021 12:46
An: dev@plc4x.apache.org
Betreff: AW: AW: AW: ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse

Hi Łukasz,

may be should extend PlcResponseCode to have a new value SESSION_INVALID. Optionally a method forOPCStatucCode( long opcCode ) could be there to get a suitable code fort he passed OPC code.
E.g. 2149908480 will map to SESSION_INVALID.

                        PlcResponseCode code = PlcResponseCode.INTERNAL_ERROR;
                        if (reply instanceof ServiceFault) {
                            ExtensionObjectDefinition header = ((ServiceFault) reply).getResponseHeader();
                            code = PlcResponseCode.forOPCStatucCode( ((org.apache.plc4x.java.opcua.readwrite.ResponseHeader) header).getServiceResult().getStatusCode() );
                            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<>(code, null));
                        }
                        future.complete(new DefaultPlcReadResponse(request, status));
                        return;

But current solution works and is OK for me.

with best regards Torsten

SQL Projekt AG  ▪ Franklinstraße 25 a  ▪ 01069 Dresden

Telefon:        (0351) 87619-0
Telefax:        (0351) 87619-99
E-Mail:         torsten.uhr@sql-ag.de
Web:    www.sql-ag.de

Aufsichtsratsvorsitzender: Jürgen Bittner
Vorstand: Stefan Ehrlich, Jens Gärtner (Sprecher)
Handelsregister: HRB 38924 Amtsgericht Dresden Die Zertifizierungsstelle der TÜV SÜD Management Service GmbH bescheinigt, dass die SQL Projekt AG für den Geltungsbereich "Entwicklung und Vertrieb von Datenbank- und Integrationslösungen sowie Beratung, Training und Support auf dem Gebiet datenbankgestützter Softwareprodukte" ein Qualitätsmanagementsystem eingeführt hat und anwendet.


Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen.
Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail oder Inhalte ist nicht gestattet.

This e-mail may contain confidential and/or privileged information.
If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

-----Ursprüngliche Nachricht-----
Von: Łukasz Dywicki <lu...@code-house.org>
Gesendet: Freitag, 22. Oktober 2021 11:18
An: dev@plc4x.apache.org
Betreff: Re: AW: AW: ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse

REMOTE_ERROR could be better, but to make it right we need to look into actual ServiceFault header and its result code. Possibly we will find there a better indication of what the error is.

If you will look at my last commit on develop you will find right place to put OPC <> PLC4X status mapping logic.

Kind regards,
Łukasz


On 22.10.2021 09:59, Torsten Uhr wrote:
> Hi Łukasz,
>
> thanks for the very quick response. It works as expected.
> Did You think the response code "REMOTE_ERROR" might more suite than "INTERNAL_ERROR"?
>
> With best regards
>
> Torsten Uhr
> SQL Projekt AG  ▪ Franklinstraße 25 a  ▪ 01069 Dresden
>
> Telefon:      (0351) 87619-0
> Telefax:      (0351) 87619-99
> E-Mail:       torsten.uhr@sql-ag.de<ma...@sql-ag.de>
> Web:  www.sql-ag.de<http://www.sql-ag.de>
>
> Aufsichtsratsvorsitzender: Jürgen Bittner
> Vorstand: Stefan Ehrlich, Jens Gärtner (Sprecher)
> Handelsregister: HRB 38924 Amtsgericht Dresden Die 
> Zertifizierungsstelle der TÜV SÜD Management Service GmbH bescheinigt, 
> dass die SQL Projekt AG für den Geltungsbereich "Entwicklung und 
> Vertrieb von Datenbank- und Integrationslösungen sowie Beratung, Training und Support auf dem Gebiet datenbankgestützter Softwareprodukte" ein Qualitätsmanagementsystem eingeführt hat und anwendet.
>
>
> Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen.
> Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail oder Inhalte ist nicht gestattet.
>
> This e-mail may contain confidential and/or privileged information.
> If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
>
> -----Ursprüngliche Nachricht-----
> Von: Łukasz Dywicki <lu...@code-house.org>>
> Gesendet: Donnerstag, 21. Oktober 2021 23:21
> An: dev@plc4x.apache.org<ma...@plc4x.apache.org>
> Betreff: Re: AW: ClassCastException: class 
> org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to 
> class org.apache.plc4x.java.opcua.readwrite.ReadResponse
>
> Thank you for test case.
>
> I've implemented basic fix for issue based on my sparse knowledge of OPC UA. Issue was missing a callback call when server returned an error.
>
> I improved that, now you sohuld get at least failed answer back.
> Original reply is logged. I did not map yet status code from server.
>
> Pushed to developer for 0.10, please test.
>
> Best,
> Łukasz
>
>
> On 21.10.2021 14:03, Christofer Dutz wrote:
>> Hi Thorsten,
>>
>> first of all: Thank you for providing a Unit Test for demonstrating 
>> your problem ... that makes our lives a lot easier :-)
>>
>> I'm sure someone on the community will have a look at the issue soon. I'll try to ping the right people for that.
>>
>> Chris
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Torsten Uhr
>> <to...@sql-ag.de>>
>> Gesendet: Donnerstag, 21. Oktober 2021 13:12
>> An: dev@plc4x.apache.org<ma...@plc4x.apache.org>
>> Betreff: ClassCastException: class
>> org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to 
>> class org.apache.plc4x.java.opcua.readwrite.ReadResponse
>>
>> Hi all,
>>
>> if I create an OPCUA connection (to milo) and wait 5 minutes before sending a read request the error attached below is logged and the read execution blocks infinitely.
>> I'm used codebase 0.9.0 and 0.10.0 snapshot.
>> Note: The wait simulates a connection created earlier and get from a connection pool in a managed environment like application server.
>> I think theres a timeout for pending connections on the server side. I would expect, that the driver should throw an exception rather blocking?
>>
>> [nioEventLoopGroup-2-1] WARN io.netty.channel.DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
>> io.netty.handler.codec.DecoderException: java.lang.ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse (org.apache.plc4x.java.opcua.readwrite.ServiceFault and org.apache.plc4x.java.opcua.readwrite.ReadResponse are in unnamed module of loader 'app')
>>           at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:98)
>>           at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
>>           at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
>>           at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
>>           at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
>>           at io.netty.handler.codec.ByteToMessageCodec.channelRead(ByteToMessageCodec.java:103)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
>>           at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
>>           at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
>>           at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
>>           at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
>>           at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
>>           at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
>>           at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
>>           at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
>>           at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
>>           at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
>>           at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
>>           at java.base/java.lang.Thread.run(Thread.java:834)
>> Caused by: java.lang.ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse (org.apache.plc4x.java.opcua.readwrite.ServiceFault and org.apache.plc4x.java.opcua.readwrite.ReadResponse are in unnamed module of loader 'app')
>>           at org.apache.plc4x.java.opcua.protocol.OpcuaProtocolLogic.lambda$read$0(OpcuaProtocolLogic.java:177)
>>           at org.apache.plc4x.java.opcua.context.SecureChannel.lambda$4(SecureChannel.java:212)
>>           at org.apache.plc4x.java.spi.Plc4xNettyWrapper.decode(Plc4xNettyWrapper.java:175)
>>           at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81)
>>           at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88)
>>           ... 23 more
>>
>>
>> JUnit regeression test:
>>
>> import org.apache.plc4x.java.PlcDriverManager;
>> import org.apache.plc4x.java.api.PlcConnection;
>> import org.apache.plc4x.java.api.messages.PlcReadRequest;
>> import org.junit.Assert;
>> import org.junit.jupiter.api.Test;
>>
>> public class RegressionTest
>> {
>>      @Test
>>      public void Timeout()
>>      {
>>         String connectionString = "opcua:tcp://localhost:12686/milo?discovery=false";
>>         final int TIMEOUT = 300 * 1000;
>>
>>         try (PlcConnection plcConnection = new PlcDriverManager().getConnection( connectionString ))
>>         {
>>            Thread.sleep( TIMEOUT );
>>
>>            PlcReadRequest.Builder builder = plcConnection.readRequestBuilder();
>>            builder.addItem("value",
>> "ns=2;s=HelloWorld/ScalarTypes/String");
>>
>>            builder.build().execute().get();
>>         }
>>         catch( Throwable thr )
>>         {
>>            Assert.fail( thr.getMessage() );
>>         }
>>      }
>> }
>>
>>
>> With best regards
>> Torsten Uhr
>>


AW: AW: AW: ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse

Posted by Christofer Dutz <ch...@c-ware.de>.
Hi,

I think we only had the status codes in there that we needed so far.
However it would be cool if the codes wouldn't differ for each connection type.
So how about adding a "CONNECTION_INVALID" code? 

I guess an OPC-UA Session is what other protocols consider a connection - right?

Just my thoughts to that.

Chris

-----Ursprüngliche Nachricht-----
Von: Torsten Uhr <to...@sql-ag.de> 
Gesendet: Freitag, 22. Oktober 2021 12:46
An: dev@plc4x.apache.org
Betreff: AW: AW: AW: ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse

Hi Łukasz,

may be should extend PlcResponseCode to have a new value SESSION_INVALID. Optionally a method forOPCStatucCode( long opcCode ) could be there to get a suitable code fort he passed OPC code.
E.g. 2149908480 will map to SESSION_INVALID.

                        PlcResponseCode code = PlcResponseCode.INTERNAL_ERROR;
                        if (reply instanceof ServiceFault) {
                            ExtensionObjectDefinition header = ((ServiceFault) reply).getResponseHeader();
                            code = PlcResponseCode.forOPCStatucCode( ((org.apache.plc4x.java.opcua.readwrite.ResponseHeader) header).getServiceResult().getStatusCode() );
                            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<>(code, null));
                        }
                        future.complete(new DefaultPlcReadResponse(request, status));
                        return;

But current solution works and is OK for me.

with best regards Torsten

SQL Projekt AG  ▪ Franklinstraße 25 a  ▪ 01069 Dresden

Telefon:        (0351) 87619-0
Telefax:        (0351) 87619-99
E-Mail:         torsten.uhr@sql-ag.de
Web:    www.sql-ag.de

Aufsichtsratsvorsitzender: Jürgen Bittner
Vorstand: Stefan Ehrlich, Jens Gärtner (Sprecher)
Handelsregister: HRB 38924 Amtsgericht Dresden Die Zertifizierungsstelle der TÜV SÜD Management Service GmbH bescheinigt, dass die SQL Projekt AG für den Geltungsbereich "Entwicklung und Vertrieb von Datenbank- und Integrationslösungen sowie Beratung, Training und Support auf dem Gebiet datenbankgestützter Softwareprodukte" ein Qualitätsmanagementsystem eingeführt hat und anwendet.


Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen.
Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail oder Inhalte ist nicht gestattet.

This e-mail may contain confidential and/or privileged information.
If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

-----Ursprüngliche Nachricht-----
Von: Łukasz Dywicki <lu...@code-house.org>
Gesendet: Freitag, 22. Oktober 2021 11:18
An: dev@plc4x.apache.org
Betreff: Re: AW: AW: ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse

REMOTE_ERROR could be better, but to make it right we need to look into actual ServiceFault header and its result code. Possibly we will find there a better indication of what the error is.

If you will look at my last commit on develop you will find right place to put OPC <> PLC4X status mapping logic.

Kind regards,
Łukasz


On 22.10.2021 09:59, Torsten Uhr wrote:
> Hi Łukasz,
>
> thanks for the very quick response. It works as expected.
> Did You think the response code "REMOTE_ERROR" might more suite than "INTERNAL_ERROR"?
>
> With best regards
>
> Torsten Uhr
> SQL Projekt AG  ▪ Franklinstraße 25 a  ▪ 01069 Dresden
>
> Telefon:      (0351) 87619-0
> Telefax:      (0351) 87619-99
> E-Mail:       torsten.uhr@sql-ag.de<ma...@sql-ag.de>
> Web:  www.sql-ag.de<http://www.sql-ag.de>
>
> Aufsichtsratsvorsitzender: Jürgen Bittner
> Vorstand: Stefan Ehrlich, Jens Gärtner (Sprecher)
> Handelsregister: HRB 38924 Amtsgericht Dresden Die 
> Zertifizierungsstelle der TÜV SÜD Management Service GmbH bescheinigt, 
> dass die SQL Projekt AG für den Geltungsbereich "Entwicklung und 
> Vertrieb von Datenbank- und Integrationslösungen sowie Beratung, Training und Support auf dem Gebiet datenbankgestützter Softwareprodukte" ein Qualitätsmanagementsystem eingeführt hat und anwendet.
>
>
> Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen.
> Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail oder Inhalte ist nicht gestattet.
>
> This e-mail may contain confidential and/or privileged information.
> If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
>
> -----Ursprüngliche Nachricht-----
> Von: Łukasz Dywicki <lu...@code-house.org>>
> Gesendet: Donnerstag, 21. Oktober 2021 23:21
> An: dev@plc4x.apache.org<ma...@plc4x.apache.org>
> Betreff: Re: AW: ClassCastException: class 
> org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to 
> class org.apache.plc4x.java.opcua.readwrite.ReadResponse
>
> Thank you for test case.
>
> I've implemented basic fix for issue based on my sparse knowledge of OPC UA. Issue was missing a callback call when server returned an error.
>
> I improved that, now you sohuld get at least failed answer back.
> Original reply is logged. I did not map yet status code from server.
>
> Pushed to developer for 0.10, please test.
>
> Best,
> Łukasz
>
>
> On 21.10.2021 14:03, Christofer Dutz wrote:
>> Hi Thorsten,
>>
>> first of all: Thank you for providing a Unit Test for demonstrating 
>> your problem ... that makes our lives a lot easier :-)
>>
>> I'm sure someone on the community will have a look at the issue soon. I'll try to ping the right people for that.
>>
>> Chris
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Torsten Uhr 
>> <to...@sql-ag.de>>
>> Gesendet: Donnerstag, 21. Oktober 2021 13:12
>> An: dev@plc4x.apache.org<ma...@plc4x.apache.org>
>> Betreff: ClassCastException: class
>> org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to 
>> class org.apache.plc4x.java.opcua.readwrite.ReadResponse
>>
>> Hi all,
>>
>> if I create an OPCUA connection (to milo) and wait 5 minutes before sending a read request the error attached below is logged and the read execution blocks infinitely.
>> I'm used codebase 0.9.0 and 0.10.0 snapshot.
>> Note: The wait simulates a connection created earlier and get from a connection pool in a managed environment like application server.
>> I think theres a timeout for pending connections on the server side. I would expect, that the driver should throw an exception rather blocking?
>>
>> [nioEventLoopGroup-2-1] WARN io.netty.channel.DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
>> io.netty.handler.codec.DecoderException: java.lang.ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse (org.apache.plc4x.java.opcua.readwrite.ServiceFault and org.apache.plc4x.java.opcua.readwrite.ReadResponse are in unnamed module of loader 'app')
>>           at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:98)
>>           at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
>>           at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
>>           at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
>>           at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
>>           at io.netty.handler.codec.ByteToMessageCodec.channelRead(ByteToMessageCodec.java:103)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
>>           at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
>>           at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
>>           at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
>>           at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
>>           at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
>>           at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
>>           at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
>>           at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
>>           at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
>>           at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
>>           at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
>>           at java.base/java.lang.Thread.run(Thread.java:834)
>> Caused by: java.lang.ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse (org.apache.plc4x.java.opcua.readwrite.ServiceFault and org.apache.plc4x.java.opcua.readwrite.ReadResponse are in unnamed module of loader 'app')
>>           at org.apache.plc4x.java.opcua.protocol.OpcuaProtocolLogic.lambda$read$0(OpcuaProtocolLogic.java:177)
>>           at org.apache.plc4x.java.opcua.context.SecureChannel.lambda$4(SecureChannel.java:212)
>>           at org.apache.plc4x.java.spi.Plc4xNettyWrapper.decode(Plc4xNettyWrapper.java:175)
>>           at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81)
>>           at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88)
>>           ... 23 more
>>
>>
>> JUnit regeression test:
>>
>> import org.apache.plc4x.java.PlcDriverManager;
>> import org.apache.plc4x.java.api.PlcConnection;
>> import org.apache.plc4x.java.api.messages.PlcReadRequest;
>> import org.junit.Assert;
>> import org.junit.jupiter.api.Test;
>>
>> public class RegressionTest
>> {
>>      @Test
>>      public void Timeout()
>>      {
>>         String connectionString = "opcua:tcp://localhost:12686/milo?discovery=false";
>>         final int TIMEOUT = 300 * 1000;
>>
>>         try (PlcConnection plcConnection = new PlcDriverManager().getConnection( connectionString ))
>>         {
>>            Thread.sleep( TIMEOUT );
>>
>>            PlcReadRequest.Builder builder = plcConnection.readRequestBuilder();
>>            builder.addItem("value",
>> "ns=2;s=HelloWorld/ScalarTypes/String");
>>
>>            builder.build().execute().get();
>>         }
>>         catch( Throwable thr )
>>         {
>>            Assert.fail( thr.getMessage() );
>>         }
>>      }
>> }
>>
>>
>> With best regards
>> Torsten Uhr
>>


AW: AW: AW: ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse

Posted by Torsten Uhr <to...@sql-ag.de>.
Hi Łukasz,

may be should extend PlcResponseCode to have a new value SESSION_INVALID. Optionally a method forOPCStatucCode( long opcCode ) could be there to get a suitable code fort he passed OPC code.
E.g. 2149908480 will map to SESSION_INVALID.

                        PlcResponseCode code = PlcResponseCode.INTERNAL_ERROR;
                        if (reply instanceof ServiceFault) {
                            ExtensionObjectDefinition header = ((ServiceFault) reply).getResponseHeader();
                            code = PlcResponseCode.forOPCStatucCode( ((org.apache.plc4x.java.opcua.readwrite.ResponseHeader) header).getServiceResult().getStatusCode() );
                            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<>(code, null));
                        }
                        future.complete(new DefaultPlcReadResponse(request, status));
                        return;

But current solution works and is OK for me.

with best regards Torsten

SQL Projekt AG  ▪ Franklinstraße 25 a  ▪ 01069 Dresden

Telefon:        (0351) 87619-0
Telefax:        (0351) 87619-99
E-Mail:         torsten.uhr@sql-ag.de
Web:    www.sql-ag.de

Aufsichtsratsvorsitzender: Jürgen Bittner
Vorstand: Stefan Ehrlich, Jens Gärtner (Sprecher)
Handelsregister: HRB 38924 Amtsgericht Dresden
Die Zertifizierungsstelle der TÜV SÜD Management Service GmbH bescheinigt, dass die SQL Projekt AG für den Geltungsbereich "Entwicklung
und Vertrieb von Datenbank- und Integrationslösungen sowie Beratung, Training und Support auf dem Gebiet datenbankgestützter
Softwareprodukte" ein Qualitätsmanagementsystem eingeführt hat und anwendet.


Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen.
Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail oder Inhalte ist nicht gestattet.

This e-mail may contain confidential and/or privileged information.
If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

-----Ursprüngliche Nachricht-----
Von: Łukasz Dywicki <lu...@code-house.org>
Gesendet: Freitag, 22. Oktober 2021 11:18
An: dev@plc4x.apache.org
Betreff: Re: AW: AW: ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse

REMOTE_ERROR could be better, but to make it right we need to look into actual ServiceFault header and its result code. Possibly we will find there a better indication of what the error is.

If you will look at my last commit on develop you will find right place to put OPC <> PLC4X status mapping logic.

Kind regards,
Łukasz


On 22.10.2021 09:59, Torsten Uhr wrote:
> Hi Łukasz,
>
> thanks for the very quick response. It works as expected.
> Did You think the response code "REMOTE_ERROR" might more suite than "INTERNAL_ERROR"?
>
> With best regards
>
> Torsten Uhr
> SQL Projekt AG  ▪ Franklinstraße 25 a  ▪ 01069 Dresden
>
> Telefon:      (0351) 87619-0
> Telefax:      (0351) 87619-99
> E-Mail:       torsten.uhr@sql-ag.de<ma...@sql-ag.de>
> Web:  www.sql-ag.de<http://www.sql-ag.de>
>
> Aufsichtsratsvorsitzender: Jürgen Bittner
> Vorstand: Stefan Ehrlich, Jens Gärtner (Sprecher)
> Handelsregister: HRB 38924 Amtsgericht Dresden Die
> Zertifizierungsstelle der TÜV SÜD Management Service GmbH bescheinigt,
> dass die SQL Projekt AG für den Geltungsbereich "Entwicklung und
> Vertrieb von Datenbank- und Integrationslösungen sowie Beratung, Training und Support auf dem Gebiet datenbankgestützter Softwareprodukte" ein Qualitätsmanagementsystem eingeführt hat und anwendet.
>
>
> Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen.
> Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail oder Inhalte ist nicht gestattet.
>
> This e-mail may contain confidential and/or privileged information.
> If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
>
> -----Ursprüngliche Nachricht-----
> Von: Łukasz Dywicki <lu...@code-house.org>>
> Gesendet: Donnerstag, 21. Oktober 2021 23:21
> An: dev@plc4x.apache.org<ma...@plc4x.apache.org>
> Betreff: Re: AW: ClassCastException: class
> org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to
> class org.apache.plc4x.java.opcua.readwrite.ReadResponse
>
> Thank you for test case.
>
> I've implemented basic fix for issue based on my sparse knowledge of OPC UA. Issue was missing a callback call when server returned an error.
>
> I improved that, now you sohuld get at least failed answer back.
> Original reply is logged. I did not map yet status code from server.
>
> Pushed to developer for 0.10, please test.
>
> Best,
> Łukasz
>
>
> On 21.10.2021 14:03, Christofer Dutz wrote:
>> Hi Thorsten,
>>
>> first of all: Thank you for providing a Unit Test for demonstrating
>> your problem ... that makes our lives a lot easier :-)
>>
>> I'm sure someone on the community will have a look at the issue soon. I'll try to ping the right people for that.
>>
>> Chris
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Torsten Uhr <to...@sql-ag.de>>
>> Gesendet: Donnerstag, 21. Oktober 2021 13:12
>> An: dev@plc4x.apache.org<ma...@plc4x.apache.org>
>> Betreff: ClassCastException: class
>> org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to
>> class org.apache.plc4x.java.opcua.readwrite.ReadResponse
>>
>> Hi all,
>>
>> if I create an OPCUA connection (to milo) and wait 5 minutes before sending a read request the error attached below is logged and the read execution blocks infinitely.
>> I'm used codebase 0.9.0 and 0.10.0 snapshot.
>> Note: The wait simulates a connection created earlier and get from a connection pool in a managed environment like application server.
>> I think theres a timeout for pending connections on the server side. I would expect, that the driver should throw an exception rather blocking?
>>
>> [nioEventLoopGroup-2-1] WARN io.netty.channel.DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
>> io.netty.handler.codec.DecoderException: java.lang.ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse (org.apache.plc4x.java.opcua.readwrite.ServiceFault and org.apache.plc4x.java.opcua.readwrite.ReadResponse are in unnamed module of loader 'app')
>>           at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:98)
>>           at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
>>           at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
>>           at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
>>           at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
>>           at io.netty.handler.codec.ByteToMessageCodec.channelRead(ByteToMessageCodec.java:103)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
>>           at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
>>           at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
>>           at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
>>           at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
>>           at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
>>           at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
>>           at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
>>           at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
>>           at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
>>           at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
>>           at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
>>           at java.base/java.lang.Thread.run(Thread.java:834)
>> Caused by: java.lang.ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse (org.apache.plc4x.java.opcua.readwrite.ServiceFault and org.apache.plc4x.java.opcua.readwrite.ReadResponse are in unnamed module of loader 'app')
>>           at org.apache.plc4x.java.opcua.protocol.OpcuaProtocolLogic.lambda$read$0(OpcuaProtocolLogic.java:177)
>>           at org.apache.plc4x.java.opcua.context.SecureChannel.lambda$4(SecureChannel.java:212)
>>           at org.apache.plc4x.java.spi.Plc4xNettyWrapper.decode(Plc4xNettyWrapper.java:175)
>>           at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81)
>>           at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88)
>>           ... 23 more
>>
>>
>> JUnit regeression test:
>>
>> import org.apache.plc4x.java.PlcDriverManager;
>> import org.apache.plc4x.java.api.PlcConnection;
>> import org.apache.plc4x.java.api.messages.PlcReadRequest;
>> import org.junit.Assert;
>> import org.junit.jupiter.api.Test;
>>
>> public class RegressionTest
>> {
>>      @Test
>>      public void Timeout()
>>      {
>>         String connectionString = "opcua:tcp://localhost:12686/milo?discovery=false";
>>         final int TIMEOUT = 300 * 1000;
>>
>>         try (PlcConnection plcConnection = new PlcDriverManager().getConnection( connectionString ))
>>         {
>>            Thread.sleep( TIMEOUT );
>>
>>            PlcReadRequest.Builder builder = plcConnection.readRequestBuilder();
>>            builder.addItem("value",
>> "ns=2;s=HelloWorld/ScalarTypes/String");
>>
>>            builder.build().execute().get();
>>         }
>>         catch( Throwable thr )
>>         {
>>            Assert.fail( thr.getMessage() );
>>         }
>>      }
>> }
>>
>>
>> With best regards
>> Torsten Uhr
>>


Re: AW: AW: ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse

Posted by Łukasz Dywicki <lu...@code-house.org>.
REMOTE_ERROR could be better, but to make it right we need to look into 
actual ServiceFault header and its result code. Possibly we will find 
there a better indication of what the error is.

If you will look at my last commit on develop you will find right place 
to put OPC <> PLC4X status mapping logic.

Kind regards,
Łukasz


On 22.10.2021 09:59, Torsten Uhr wrote:
> Hi Łukasz,
> 
> thanks for the very quick response. It works as expected.
> Did You think the response code "REMOTE_ERROR" might more suite than "INTERNAL_ERROR"?
> 
> With best regards
> 
> Torsten Uhr
> SQL Projekt AG  ▪ Franklinstraße 25 a  ▪ 01069 Dresden
> 
> Telefon:	(0351) 87619-0
> Telefax:	(0351) 87619-99
> E-Mail: 	torsten.uhr@sql-ag.de
> Web:	www.sql-ag.de
> 
> Aufsichtsratsvorsitzender: Jürgen Bittner
> Vorstand: Stefan Ehrlich, Jens Gärtner (Sprecher)
> Handelsregister: HRB 38924 Amtsgericht Dresden
> Die Zertifizierungsstelle der TÜV SÜD Management Service GmbH bescheinigt, dass die SQL Projekt AG für den Geltungsbereich "Entwicklung
> und Vertrieb von Datenbank- und Integrationslösungen sowie Beratung, Training und Support auf dem Gebiet datenbankgestützter
> Softwareprodukte" ein Qualitätsmanagementsystem eingeführt hat und anwendet.
> 
> 
> Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen.
> Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail oder Inhalte ist nicht gestattet.
> 
> This e-mail may contain confidential and/or privileged information.
> If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
> 
> -----Ursprüngliche Nachricht-----
> Von: Łukasz Dywicki <lu...@code-house.org>
> Gesendet: Donnerstag, 21. Oktober 2021 23:21
> An: dev@plc4x.apache.org
> Betreff: Re: AW: ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse
> 
> Thank you for test case.
> 
> I've implemented basic fix for issue based on my sparse knowledge of OPC UA. Issue was missing a callback call when server returned an error.
> 
> I improved that, now you sohuld get at least failed answer back.
> Original reply is logged. I did not map yet status code from server.
> 
> Pushed to developer for 0.10, please test.
> 
> Best,
> Łukasz
> 
> 
> On 21.10.2021 14:03, Christofer Dutz wrote:
>> Hi Thorsten,
>>
>> first of all: Thank you for providing a Unit Test for demonstrating
>> your problem ... that makes our lives a lot easier :-)
>>
>> I'm sure someone on the community will have a look at the issue soon. I'll try to ping the right people for that.
>>
>> Chris
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Torsten Uhr <to...@sql-ag.de>
>> Gesendet: Donnerstag, 21. Oktober 2021 13:12
>> An: dev@plc4x.apache.org
>> Betreff: ClassCastException: class
>> org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to
>> class org.apache.plc4x.java.opcua.readwrite.ReadResponse
>>
>> Hi all,
>>
>> if I create an OPCUA connection (to milo) and wait 5 minutes before sending a read request the error attached below is logged and the read execution blocks infinitely.
>> I'm used codebase 0.9.0 and 0.10.0 snapshot.
>> Note: The wait simulates a connection created earlier and get from a connection pool in a managed environment like application server.
>> I think theres a timeout for pending connections on the server side. I would expect, that the driver should throw an exception rather blocking?
>>
>> [nioEventLoopGroup-2-1] WARN io.netty.channel.DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
>> io.netty.handler.codec.DecoderException: java.lang.ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse (org.apache.plc4x.java.opcua.readwrite.ServiceFault and org.apache.plc4x.java.opcua.readwrite.ReadResponse are in unnamed module of loader 'app')
>>           at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:98)
>>           at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
>>           at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
>>           at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
>>           at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
>>           at io.netty.handler.codec.ByteToMessageCodec.channelRead(ByteToMessageCodec.java:103)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
>>           at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
>>           at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
>>           at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
>>           at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
>>           at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
>>           at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
>>           at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
>>           at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
>>           at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
>>           at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
>>           at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
>>           at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
>>           at java.base/java.lang.Thread.run(Thread.java:834)
>> Caused by: java.lang.ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse (org.apache.plc4x.java.opcua.readwrite.ServiceFault and org.apache.plc4x.java.opcua.readwrite.ReadResponse are in unnamed module of loader 'app')
>>           at org.apache.plc4x.java.opcua.protocol.OpcuaProtocolLogic.lambda$read$0(OpcuaProtocolLogic.java:177)
>>           at org.apache.plc4x.java.opcua.context.SecureChannel.lambda$4(SecureChannel.java:212)
>>           at org.apache.plc4x.java.spi.Plc4xNettyWrapper.decode(Plc4xNettyWrapper.java:175)
>>           at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81)
>>           at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88)
>>           ... 23 more
>>
>>
>> JUnit regeression test:
>>
>> import org.apache.plc4x.java.PlcDriverManager;
>> import org.apache.plc4x.java.api.PlcConnection;
>> import org.apache.plc4x.java.api.messages.PlcReadRequest;
>> import org.junit.Assert;
>> import org.junit.jupiter.api.Test;
>>
>> public class RegressionTest
>> {
>>      @Test
>>      public void Timeout()
>>      {
>>         String connectionString = "opcua:tcp://localhost:12686/milo?discovery=false";
>>         final int TIMEOUT = 300 * 1000;
>>
>>         try (PlcConnection plcConnection = new PlcDriverManager().getConnection( connectionString ))
>>         {
>>            Thread.sleep( TIMEOUT );
>>
>>            PlcReadRequest.Builder builder = plcConnection.readRequestBuilder();
>>            builder.addItem("value",
>> "ns=2;s=HelloWorld/ScalarTypes/String");
>>
>>            builder.build().execute().get();
>>         }
>>         catch( Throwable thr )
>>         {
>>            Assert.fail( thr.getMessage() );
>>         }
>>      }
>> }
>>
>>
>> With best regards
>> Torsten Uhr
>>

AW: AW: ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse

Posted by Torsten Uhr <to...@sql-ag.de>.
Hi Łukasz,

thanks for the very quick response. It works as expected. 
Did You think the response code "REMOTE_ERROR" might more suite than "INTERNAL_ERROR"?

With best regards

Torsten Uhr
SQL Projekt AG  ▪ Franklinstraße 25 a  ▪ 01069 Dresden

Telefon:	(0351) 87619-0
Telefax:	(0351) 87619-99
E-Mail: 	torsten.uhr@sql-ag.de
Web:	www.sql-ag.de 

Aufsichtsratsvorsitzender: Jürgen Bittner
Vorstand: Stefan Ehrlich, Jens Gärtner (Sprecher)
Handelsregister: HRB 38924 Amtsgericht Dresden
Die Zertifizierungsstelle der TÜV SÜD Management Service GmbH bescheinigt, dass die SQL Projekt AG für den Geltungsbereich "Entwicklung 
und Vertrieb von Datenbank- und Integrationslösungen sowie Beratung, Training und Support auf dem Gebiet datenbankgestützter 
Softwareprodukte" ein Qualitätsmanagementsystem eingeführt hat und anwendet.


Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. 
Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail oder Inhalte ist nicht gestattet. 

This e-mail may contain confidential and/or privileged information. 
If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

-----Ursprüngliche Nachricht-----
Von: Łukasz Dywicki <lu...@code-house.org> 
Gesendet: Donnerstag, 21. Oktober 2021 23:21
An: dev@plc4x.apache.org
Betreff: Re: AW: ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse

Thank you for test case.

I've implemented basic fix for issue based on my sparse knowledge of OPC UA. Issue was missing a callback call when server returned an error.

I improved that, now you sohuld get at least failed answer back. 
Original reply is logged. I did not map yet status code from server.

Pushed to developer for 0.10, please test.

Best,
Łukasz


On 21.10.2021 14:03, Christofer Dutz wrote:
> Hi Thorsten,
> 
> first of all: Thank you for providing a Unit Test for demonstrating 
> your problem ... that makes our lives a lot easier :-)
> 
> I'm sure someone on the community will have a look at the issue soon. I'll try to ping the right people for that.
> 
> Chris
> 
> -----Ursprüngliche Nachricht-----
> Von: Torsten Uhr <to...@sql-ag.de>
> Gesendet: Donnerstag, 21. Oktober 2021 13:12
> An: dev@plc4x.apache.org
> Betreff: ClassCastException: class 
> org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to 
> class org.apache.plc4x.java.opcua.readwrite.ReadResponse
> 
> Hi all,
> 
> if I create an OPCUA connection (to milo) and wait 5 minutes before sending a read request the error attached below is logged and the read execution blocks infinitely.
> I'm used codebase 0.9.0 and 0.10.0 snapshot.
> Note: The wait simulates a connection created earlier and get from a connection pool in a managed environment like application server.
> I think theres a timeout for pending connections on the server side. I would expect, that the driver should throw an exception rather blocking?
> 
> [nioEventLoopGroup-2-1] WARN io.netty.channel.DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
> io.netty.handler.codec.DecoderException: java.lang.ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse (org.apache.plc4x.java.opcua.readwrite.ServiceFault and org.apache.plc4x.java.opcua.readwrite.ReadResponse are in unnamed module of loader 'app')
>          at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:98)
>          at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111)
>          at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
>          at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
>          at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
>          at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
>          at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
>          at io.netty.handler.codec.ByteToMessageCodec.channelRead(ByteToMessageCodec.java:103)
>          at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
>          at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
>          at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
>          at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
>          at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
>          at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
>          at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
>          at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
>          at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
>          at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
>          at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
>          at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
>          at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
>          at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
>          at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
>          at java.base/java.lang.Thread.run(Thread.java:834)
> Caused by: java.lang.ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse (org.apache.plc4x.java.opcua.readwrite.ServiceFault and org.apache.plc4x.java.opcua.readwrite.ReadResponse are in unnamed module of loader 'app')
>          at org.apache.plc4x.java.opcua.protocol.OpcuaProtocolLogic.lambda$read$0(OpcuaProtocolLogic.java:177)
>          at org.apache.plc4x.java.opcua.context.SecureChannel.lambda$4(SecureChannel.java:212)
>          at org.apache.plc4x.java.spi.Plc4xNettyWrapper.decode(Plc4xNettyWrapper.java:175)
>          at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81)
>          at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88)
>          ... 23 more
> 
> 
> JUnit regeression test:
> 
> import org.apache.plc4x.java.PlcDriverManager;
> import org.apache.plc4x.java.api.PlcConnection;
> import org.apache.plc4x.java.api.messages.PlcReadRequest;
> import org.junit.Assert;
> import org.junit.jupiter.api.Test;
> 
> public class RegressionTest
> {
>     @Test
>     public void Timeout()
>     {
>        String connectionString = "opcua:tcp://localhost:12686/milo?discovery=false";
>        final int TIMEOUT = 300 * 1000;
> 
>        try (PlcConnection plcConnection = new PlcDriverManager().getConnection( connectionString ))
>        {
>           Thread.sleep( TIMEOUT );
> 
>           PlcReadRequest.Builder builder = plcConnection.readRequestBuilder();
>           builder.addItem("value", 
> "ns=2;s=HelloWorld/ScalarTypes/String");
> 
>           builder.build().execute().get();
>        }
>        catch( Throwable thr )
>        {
>           Assert.fail( thr.getMessage() );
>        }
>     }
> }
> 
> 
> With best regards
> Torsten Uhr
> 

Re: AW: ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse

Posted by Łukasz Dywicki <lu...@code-house.org>.
Thank you for test case.

I've implemented basic fix for issue based on my sparse knowledge of OPC 
UA. Issue was missing a callback call when server returned an error.

I improved that, now you sohuld get at least failed answer back. 
Original reply is logged. I did not map yet status code from server.

Pushed to developer for 0.10, please test.

Best,
Łukasz


On 21.10.2021 14:03, Christofer Dutz wrote:
> Hi Thorsten,
> 
> first of all: Thank you for providing a Unit Test for demonstrating your problem ... that makes our lives a lot easier :-)
> 
> I'm sure someone on the community will have a look at the issue soon. I'll try to ping the right people for that.
> 
> Chris
> 
> -----Ursprüngliche Nachricht-----
> Von: Torsten Uhr <to...@sql-ag.de>
> Gesendet: Donnerstag, 21. Oktober 2021 13:12
> An: dev@plc4x.apache.org
> Betreff: ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse
> 
> Hi all,
> 
> if I create an OPCUA connection (to milo) and wait 5 minutes before sending a read request the error attached below is logged and the read execution blocks infinitely.
> I'm used codebase 0.9.0 and 0.10.0 snapshot.
> Note: The wait simulates a connection created earlier and get from a connection pool in a managed environment like application server.
> I think theres a timeout for pending connections on the server side. I would expect, that the driver should throw an exception rather blocking?
> 
> [nioEventLoopGroup-2-1] WARN io.netty.channel.DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
> io.netty.handler.codec.DecoderException: java.lang.ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse (org.apache.plc4x.java.opcua.readwrite.ServiceFault and org.apache.plc4x.java.opcua.readwrite.ReadResponse are in unnamed module of loader 'app')
>          at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:98)
>          at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111)
>          at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
>          at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
>          at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
>          at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
>          at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
>          at io.netty.handler.codec.ByteToMessageCodec.channelRead(ByteToMessageCodec.java:103)
>          at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
>          at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
>          at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
>          at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
>          at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
>          at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
>          at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
>          at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
>          at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
>          at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
>          at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
>          at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
>          at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
>          at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
>          at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
>          at java.base/java.lang.Thread.run(Thread.java:834)
> Caused by: java.lang.ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse (org.apache.plc4x.java.opcua.readwrite.ServiceFault and org.apache.plc4x.java.opcua.readwrite.ReadResponse are in unnamed module of loader 'app')
>          at org.apache.plc4x.java.opcua.protocol.OpcuaProtocolLogic.lambda$read$0(OpcuaProtocolLogic.java:177)
>          at org.apache.plc4x.java.opcua.context.SecureChannel.lambda$4(SecureChannel.java:212)
>          at org.apache.plc4x.java.spi.Plc4xNettyWrapper.decode(Plc4xNettyWrapper.java:175)
>          at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81)
>          at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88)
>          ... 23 more
> 
> 
> JUnit regeression test:
> 
> import org.apache.plc4x.java.PlcDriverManager;
> import org.apache.plc4x.java.api.PlcConnection;
> import org.apache.plc4x.java.api.messages.PlcReadRequest;
> import org.junit.Assert;
> import org.junit.jupiter.api.Test;
> 
> public class RegressionTest
> {
>     @Test
>     public void Timeout()
>     {
>        String connectionString = "opcua:tcp://localhost:12686/milo?discovery=false";
>        final int TIMEOUT = 300 * 1000;
> 
>        try (PlcConnection plcConnection = new PlcDriverManager().getConnection( connectionString ))
>        {
>           Thread.sleep( TIMEOUT );
> 
>           PlcReadRequest.Builder builder = plcConnection.readRequestBuilder();
>           builder.addItem("value", "ns=2;s=HelloWorld/ScalarTypes/String");
> 
>           builder.build().execute().get();
>        }
>        catch( Throwable thr )
>        {
>           Assert.fail( thr.getMessage() );
>        }
>     }
> }
> 
> 
> With best regards
> Torsten Uhr
> 

AW: ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse

Posted by Christofer Dutz <ch...@c-ware.de>.
Hi Thorsten,

first of all: Thank you for providing a Unit Test for demonstrating your problem ... that makes our lives a lot easier :-)

I'm sure someone on the community will have a look at the issue soon. I'll try to ping the right people for that. 

Chris

-----Ursprüngliche Nachricht-----
Von: Torsten Uhr <to...@sql-ag.de> 
Gesendet: Donnerstag, 21. Oktober 2021 13:12
An: dev@plc4x.apache.org
Betreff: ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse

Hi all,

if I create an OPCUA connection (to milo) and wait 5 minutes before sending a read request the error attached below is logged and the read execution blocks infinitely.
I'm used codebase 0.9.0 and 0.10.0 snapshot.
Note: The wait simulates a connection created earlier and get from a connection pool in a managed environment like application server.
I think theres a timeout for pending connections on the server side. I would expect, that the driver should throw an exception rather blocking?

[nioEventLoopGroup-2-1] WARN io.netty.channel.DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
io.netty.handler.codec.DecoderException: java.lang.ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse (org.apache.plc4x.java.opcua.readwrite.ServiceFault and org.apache.plc4x.java.opcua.readwrite.ReadResponse are in unnamed module of loader 'app')
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:98)
        at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
        at io.netty.handler.codec.ByteToMessageCodec.channelRead(ByteToMessageCodec.java:103)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.ClassCastException: class org.apache.plc4x.java.opcua.readwrite.ServiceFault cannot be cast to class org.apache.plc4x.java.opcua.readwrite.ReadResponse (org.apache.plc4x.java.opcua.readwrite.ServiceFault and org.apache.plc4x.java.opcua.readwrite.ReadResponse are in unnamed module of loader 'app')
        at org.apache.plc4x.java.opcua.protocol.OpcuaProtocolLogic.lambda$read$0(OpcuaProtocolLogic.java:177)
        at org.apache.plc4x.java.opcua.context.SecureChannel.lambda$4(SecureChannel.java:212)
        at org.apache.plc4x.java.spi.Plc4xNettyWrapper.decode(Plc4xNettyWrapper.java:175)
        at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88)
        ... 23 more


JUnit regeression test:

import org.apache.plc4x.java.PlcDriverManager;
import org.apache.plc4x.java.api.PlcConnection;
import org.apache.plc4x.java.api.messages.PlcReadRequest;
import org.junit.Assert;
import org.junit.jupiter.api.Test;

public class RegressionTest
{
   @Test
   public void Timeout()
   {
      String connectionString = "opcua:tcp://localhost:12686/milo?discovery=false";
      final int TIMEOUT = 300 * 1000;

      try (PlcConnection plcConnection = new PlcDriverManager().getConnection( connectionString ))
      {
         Thread.sleep( TIMEOUT );

         PlcReadRequest.Builder builder = plcConnection.readRequestBuilder();
         builder.addItem("value", "ns=2;s=HelloWorld/ScalarTypes/String");

         builder.build().execute().get();
      }
      catch( Throwable thr )
      {
         Assert.fail( thr.getMessage() );
      }
   }
}


With best regards
Torsten Uhr