You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@plc4x.apache.org by "Souquières Adam (Jira)" <ji...@apache.org> on 2021/04/07 16:03:00 UTC
[jira] [Created] (PLC4X-289) ClassCast exception when using SubscriptionRequest with OPCA Driver implémentation
Souquières Adam created PLC4X-289:
-------------------------------------
Summary: ClassCast exception when using SubscriptionRequest with OPCA Driver implémentation
Key: PLC4X-289
URL: https://issues.apache.org/jira/browse/PLC4X-289
Project: Apache PLC4X
Issue Type: Bug
Components: API
Affects Versions: 0.8.0
Environment: Windows 10, Java 11
confluentinc/kafka-connect-base docker image
Reporter: Souquières Adam
issue PLC4X
{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)