From 261881a73a077c1df87c5dc2a5152449f6a366de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Dywicki?= Date: Fri, 23 Aug 2024 00:49:30 +0200 Subject: [PATCH] Fix compile errors after updates of opcua driver. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ɓukasz Dywicki --- .../UserIdentityTokenDefinition.java | 166 ------------------ .../java/opcua/context/SecureChannel.java | 15 +- .../opcua/protocol/OpcuaProtocolLogic.java | 2 +- .../protocol/OpcuaSubscriptionHandle.java | 19 +- .../opcua/readwrite/utils/StaticHelper.java | 6 +- 5 files changed, 20 insertions(+), 188 deletions(-) delete mode 100644 plc4j/drivers/opcua/src/main/generated/org/apache/plc4x/java/opcua/readwrite/UserIdentityTokenDefinition.java diff --git a/plc4j/drivers/opcua/src/main/generated/org/apache/plc4x/java/opcua/readwrite/UserIdentityTokenDefinition.java b/plc4j/drivers/opcua/src/main/generated/org/apache/plc4x/java/opcua/readwrite/UserIdentityTokenDefinition.java deleted file mode 100644 index 40c68160bae..00000000000 --- a/plc4j/drivers/opcua/src/main/generated/org/apache/plc4x/java/opcua/readwrite/UserIdentityTokenDefinition.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.plc4x.java.opcua.readwrite; - -import static org.apache.plc4x.java.spi.codegen.fields.FieldReaderFactory.*; -import static org.apache.plc4x.java.spi.codegen.fields.FieldWriterFactory.*; -import static org.apache.plc4x.java.spi.codegen.io.DataReaderFactory.*; -import static org.apache.plc4x.java.spi.codegen.io.DataWriterFactory.*; -import static org.apache.plc4x.java.spi.generation.StaticHelper.*; - -import java.time.*; -import java.util.*; -import org.apache.plc4x.java.api.exceptions.*; -import org.apache.plc4x.java.api.value.*; -import org.apache.plc4x.java.spi.codegen.*; -import org.apache.plc4x.java.spi.codegen.fields.*; -import org.apache.plc4x.java.spi.codegen.io.*; -import org.apache.plc4x.java.spi.generation.*; - -// Code generated by code-generation. DO NOT EDIT. - -public abstract class UserIdentityTokenDefinition implements Message { - - // Abstract accessors for discriminator values. - public abstract String getIdentifier(); - - public UserIdentityTokenDefinition() { - super(); - } - - protected abstract void serializeUserIdentityTokenDefinitionChild(WriteBuffer writeBuffer) - throws SerializationException; - - public void serialize(WriteBuffer writeBuffer) throws SerializationException { - PositionAware positionAware = writeBuffer; - boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - writeBuffer.pushContext("UserIdentityTokenDefinition"); - - // Switch field (Serialize the sub-type) - serializeUserIdentityTokenDefinitionChild(writeBuffer); - - writeBuffer.popContext("UserIdentityTokenDefinition"); - } - - @Override - public int getLengthInBytes() { - return (int) Math.ceil((float) getLengthInBits() / 8.0); - } - - @Override - public int getLengthInBits() { - int lengthInBits = 0; - UserIdentityTokenDefinition _value = this; - boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - - // Length of sub-type elements will be added by sub-type... - - return lengthInBits; - } - - public static UserIdentityTokenDefinition staticParse(ReadBuffer readBuffer, Object... args) - throws ParseException { - PositionAware positionAware = readBuffer; - if ((args == null) || (args.length != 1)) { - throw new PlcRuntimeException( - "Wrong number of arguments, expected 1, but got " + args.length); - } - String identifier; - if (args[0] instanceof String) { - identifier = (String) args[0]; - } else if (args[0] instanceof String) { - identifier = String.valueOf((String) args[0]); - } else { - throw new PlcRuntimeException( - "Argument 0 expected to be of type String or a string which is parseable but was " - + args[0].getClass().getName()); - } - return staticParse(readBuffer, identifier); - } - - public static UserIdentityTokenDefinition staticParse(ReadBuffer readBuffer, String identifier) - throws ParseException { - readBuffer.pullContext("UserIdentityTokenDefinition"); - PositionAware positionAware = readBuffer; - boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - - // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) - UserIdentityTokenDefinitionBuilder builder = null; - if (EvaluationHelper.equals(identifier, (String) "anonymous")) { - builder = - AnonymousIdentityToken.staticParseUserIdentityTokenDefinitionBuilder( - readBuffer, identifier); - } else if (EvaluationHelper.equals(identifier, (String) "username")) { - builder = - UserNameIdentityToken.staticParseUserIdentityTokenDefinitionBuilder( - readBuffer, identifier); - } else if (EvaluationHelper.equals(identifier, (String) "certificate")) { - builder = - X509IdentityToken.staticParseUserIdentityTokenDefinitionBuilder(readBuffer, identifier); - } else if (EvaluationHelper.equals(identifier, (String) "identity")) { - builder = - IssuedIdentityToken.staticParseUserIdentityTokenDefinitionBuilder(readBuffer, identifier); - } - if (builder == null) { - throw new ParseException( - "Unsupported case for discriminated type" - + " parameters [" - + "identifier=" - + identifier - + "]"); - } - - readBuffer.closeContext("UserIdentityTokenDefinition"); - // Create the instance - UserIdentityTokenDefinition _userIdentityTokenDefinition = builder.build(); - return _userIdentityTokenDefinition; - } - - public interface UserIdentityTokenDefinitionBuilder { - UserIdentityTokenDefinition build(); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof UserIdentityTokenDefinition)) { - return false; - } - UserIdentityTokenDefinition that = (UserIdentityTokenDefinition) o; - return true; - } - - @Override - public int hashCode() { - return Objects.hash(); - } - - @Override - public String toString() { - WriteBufferBoxBased writeBufferBoxBased = new WriteBufferBoxBased(true, true); - try { - writeBufferBoxBased.writeSerializable(this); - } catch (SerializationException e) { - throw new RuntimeException(e); - } - return "\n" + writeBufferBoxBased.getBox().toString() + "\n"; - } -} diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannel.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannel.java index bfb1a4b182d..651583b4e9c 100644 --- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannel.java +++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannel.java @@ -591,19 +591,17 @@ private ExtensionObject getIdentityToken(UserTokenType tokenType, String securit switch (tokenType) { case userTokenTypeAnonymous: //If we aren't using authentication tell the server we would like to log in anonymously - AnonymousIdentityToken anonymousIdentityToken = new AnonymousIdentityToken(); + AnonymousIdentityToken anonymousIdentityToken = new AnonymousIdentityToken(new PascalString(securityPolicy)); extExpandedNodeId = new ExpandedNodeId( false, //Namespace Uri Specified false, //Server Index Specified - new NodeIdFourByte((short) 0, OpcuaNodeIdServicesObject.AnonymousIdentityToken_Encoding_DefaultBinary.getValue()), + new NodeIdFourByte((short) 0, anonymousIdentityToken.getExtensionId()), null, null ); - return new WireExtensionObject(extExpandedNodeId, BINARY_ENCODING_MASK, new BinaryWireExtensionObject( - new UserIdentityToken(new PascalString(securityPolicy), anonymousIdentityToken) - )); + return new WireExtensionObject(extExpandedNodeId, BINARY_ENCODING_MASK, new BinaryWireExtensionObject(anonymousIdentityToken)); case userTokenTypeUserName: //Encrypt the password using the server nonce and server public key byte[] remoteNonce = conversation.getRemoteNonce(); @@ -619,6 +617,7 @@ private ExtensionObject getIdentityToken(UserTokenType tokenType, String securit byte[] encryptedPassword = conversation.encryptPassword(encodeablePassword); UserNameIdentityToken userNameIdentityToken = new UserNameIdentityToken( + new PascalString(securityPolicy), new PascalString(this.username), new PascalByteString(encryptedPassword.length, encryptedPassword), new PascalString(PASSWORD_ENCRYPTION_ALGORITHM) @@ -626,13 +625,11 @@ private ExtensionObject getIdentityToken(UserTokenType tokenType, String securit extExpandedNodeId = new ExpandedNodeId(false, //Namespace Uri Specified false, //Server Index Specified - new NodeIdFourByte((short) 0, OpcuaNodeIdServicesObject.UserNameIdentityToken_Encoding_DefaultBinary.getValue()), + new NodeIdFourByte((short) 0, userNameIdentityToken.getExtensionId()), null, null); - return new WireExtensionObject(extExpandedNodeId, BINARY_ENCODING_MASK, new BinaryWireExtensionObject( - new UserIdentityToken(new PascalString(securityPolicy), userNameIdentityToken) - )); + return new WireExtensionObject(extExpandedNodeId, BINARY_ENCODING_MASK, new BinaryWireExtensionObject(userNameIdentityToken)); } return null; } 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 b68063c8859..98b5a2d6912 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 @@ -64,7 +64,7 @@ public class OpcuaProtocolLogic extends Plc4xProtocolBase implements HasConfiguration, PlcSubscriber { private static final Logger LOGGER = LoggerFactory.getLogger(OpcuaProtocolLogic.class); - protected static final PascalString NULL_STRING = new PascalString(""); + protected static final PascalString NULL_STRING = new PascalString(null); private static final ExpandedNodeId NULL_EXPANDED_NODEID = new ExpandedNodeId(false, false, new NodeIdTwoByte((short) 0), diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandle.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandle.java index cec00663606..228716d58b1 100644 --- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandle.java +++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandle.java @@ -119,27 +119,27 @@ public CompletableFuture onSubscribeCreateMonitoredItem new SimpleAttributeOperand(nodeId, Arrays.asList(new QualifiedName(0, new PascalString("EventId"))), AttributeId.Value.getValue(), - null + OpcuaProtocolLogic.NULL_STRING ), new SimpleAttributeOperand(nodeId, Arrays.asList(new QualifiedName(0, new PascalString("EventType"))), AttributeId.Value.getValue(), - null + OpcuaProtocolLogic.NULL_STRING ), new SimpleAttributeOperand(nodeId, Arrays.asList(new QualifiedName(0, new PascalString("Severity"))), AttributeId.Value.getValue(), - null + OpcuaProtocolLogic.NULL_STRING ), new SimpleAttributeOperand(nodeId, Arrays.asList(new QualifiedName(0, new PascalString("Time"))), AttributeId.Value.getValue(), - null + OpcuaProtocolLogic.NULL_STRING ), new SimpleAttributeOperand(nodeId, Arrays.asList(new QualifiedName(0, new PascalString("Message"))), AttributeId.Value.getValue(), - null + OpcuaProtocolLogic.NULL_STRING ) ); @@ -244,11 +244,12 @@ private void sendPublishRequest() { LOGGER.trace("Found a Data Change notification"); List items = ((DataChangeNotification) notification).getMonitoredItems(); onSubscriptionValue(items.stream().toArray(MonitoredItemNotification[]::new)); - } else if (notification instanceof NotificationData) { - NotificationData data = (NotificationData) notification; - System.out.println("Received notification data"); +// } else if (notification instanceof StatusChangeNotification) { +// StatusChangeNotification data = (StatusChangeNotification) notification; +// } else if (notification instanceof EventNotificationList) { +// EventNotificationList data = (EventNotificationList) notification; } else { - LOGGER.warn("Unsupported Notification type"); + LOGGER.warn("Unsupported Notification type {}", notification.getClass().getName()); } } }).whenComplete((result, error) -> { diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/readwrite/utils/StaticHelper.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/readwrite/utils/StaticHelper.java index dc3029bf923..7ae036ec39f 100644 --- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/readwrite/utils/StaticHelper.java +++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/readwrite/utils/StaticHelper.java @@ -36,11 +36,11 @@ public static int pascalLengthToUtf8Length(int slength) { return Math.max(slength, 0); } - public static int extensionId(ExpandedNodeId typeId) { + public static int extensionId(ExpandedNodeId expandedNodeId) { try { - return Integer.parseInt(typeId.getIdentifier()); + return Integer.parseInt(expandedNodeId.getNodeId().getIdentifier()); } catch (NumberFormatException e) { - throw new PlcRuntimeException("Invalid node id, expected integer index, found " + typeId.getIdentifier().getClass()); + throw new PlcRuntimeException("Invalid node id, expected number, found " + expandedNodeId.getNodeId().getClass().getName()); } } }