[ 
https://issues.apache.org/jira/browse/PLC4X-291?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Ben Hutcheson resolved PLC4X-291.
---------------------------------
    Resolution: Fixed

> DefaultPlcSubscriptionField cannot be cast to class OpcuaField 
> ---------------------------------------------------------------
>
>                 Key: PLC4X-291
>                 URL: https://issues.apache.org/jira/browse/PLC4X-291
>             Project: Apache PLC4X
>          Issue Type: Bug
>          Components: API
>    Affects Versions: 0.8.0
>            Reporter: Souquières Adam
>            Priority: Major
>             Fix For: 0.9.0
>
>
> {code:java}
> @Test
> public void shoudlWorkWithSubscriptionRequest() throws 
> PlcConnectionException, InterruptedException {
>   var plcConnection = new 
> PlcDriverManager().getConnection("opcua:tcp://localhost:62541/Quickstarts/ReferenceServer")
>       
>   // Connection OK : lets subscribe
>   var subBuilder = plcConnection.subscriptionRequestBuilder();
>   subBuilder.addChangeOfStateField("machine1", 
> "ns=2;s=Fabrication_Id_1:STRING");
>   var subscriptionRequest = subBuilder.build();
>   var subResponse = subscriptionRequest.execute();
>   subResponse.whenComplete(
>       (response, ex) -> {
>           System.out.println("Result : "+ response + " - "+ex);
>           
>         for (String subscriptionName : response.getFieldNames()) {
>           final var subscriptionHandle = 
> response.getSubscriptionHandle(subscriptionName);
>           subscriptionHandle.register(System.out::println);
>         }
>       });
>   
>   Thread.sleep(1000000000);
> }
> {code}
> The code above always return this specific exception in the whenComplete 
> callback:
> {code:java}
> java.lang.ClassCastException: class 
> org.apache.plc4x.java.spi.model.DefaultPlcSubscriptionField cannot be cast to 
> class org.apache.plc4x.java.opcua.protocol.OpcuaField 
> (org.apache.plc4x.java.spi.model.DefaultPlcSubscriptionField and 
> org.apache.plc4x.java.opcua.protocol.OpcuaField are in unnamed module of 
> loader 'app')
> {code}
>  
> Dependencies used in this maven project are :
> {code:xml}
> <dependency> <groupId>org.apache.plc4x</groupId> 
> <artifactId>plc4j-api</artifactId> <version>0.8.0</version> </dependency> 
> <dependency> <groupId>org.apache.plc4x</groupId> 
> <artifactId>plc4j-driver-opcua</artifactId> <version>0.8.0</version> 
> <scope>runtime</scope> </dependency>
> {code}
>  
> Diagnosis :
> It appears that DefaultPlcSubscriptionField is composed of a 
> PlcField/OpcuaField on api side, but expected as an direct OpcuaField on 
> driver side.
> I do not have the general knowledge of the design of this repository so i'm 
> not confident enough to propose you a pull request.
> Fix proposal :
> -> Add already existing getField from DefaultPlcSubscriptionField in 
> PlcSubscriptionField interface and assume the composition strategy for 
> PlcSubscriptionField + Modify OpcuaTcpPlcConnection to get real field from 
> this new method ( may have an impact on other driver implementation too !)
> I stay available to give you some more information.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to