ottobackwards commented on a change in pull request #225:
URL: https://github.com/apache/plc4x/pull/225#discussion_r561135913
##
File path:
plc4j/integrations/opcua-server/src/main/java/org/apache/plc4x/java/opcuaserver/backend/Plc4xCommunication.java
##
@@ -195,93 +169,110 @@ public static NodeId getNodeId(String plcValue) {
}
public DataValue getValue(AttributeFilterContext.GetAttributeContext ctx,
String tag, String connectionString) {
-PlcConnection connection = null;
DataValue resp = new DataValue(new Variant(null), StatusCode.BAD);
Review comment:
Maybe we should have a static constant, Datavalue resp =
DataValue.BAD_STATUS
##
File path:
plc4j/integrations/opcua-server/src/main/java/org/apache/plc4x/java/opcuaserver/backend/Plc4xCommunication.java
##
@@ -195,93 +169,110 @@ public static NodeId getNodeId(String plcValue) {
}
public DataValue getValue(AttributeFilterContext.GetAttributeContext ctx,
String tag, String connectionString) {
-PlcConnection connection = null;
DataValue resp = new DataValue(new Variant(null), StatusCode.BAD);
+PlcConnection connection = null;
+try {
-//Check if we just polled the connection and it failed. Wait for the
backoff counter to expire before we try again.
-if (failedConnectionList.containsKey(connectionString)) {
-if (System.currentTimeMillis() >
failedConnectionList.get(connectionString) + DEFAULT_RETRY_BACKOFF) {
-failedConnectionList.remove(connectionString);
-} else {
-logger.debug("Waiting for back off timer - " +
((failedConnectionList.get(connectionString) + DEFAULT_RETRY_BACKOFF) -
System.currentTimeMillis()) + " ms left");
-return resp;
+//Check if we just polled the connection and it failed. Wait for
the backoff counter to expire before we try again.
+if (failedConnectionList.containsKey(connectionString)) {
+if (System.currentTimeMillis() >
failedConnectionList.get(connectionString) + DEFAULT_RETRY_BACKOFF) {
+failedConnectionList.remove(connectionString);
+} else {
+logger.debug("Waiting for back off timer - " +
((failedConnectionList.get(connectionString) + DEFAULT_RETRY_BACKOFF) -
System.currentTimeMillis()) + " ms left");
+return resp;
+}
}
-}
-//Try to connect to PLC
-try {
-connection = driverManager.getConnection(connectionString);
-logger.debug(connectionString + " Connected");
-} catch (PlcConnectionException e) {
-logger.error("Failed to connect to device, error raised - " + e);
-failedConnectionList.put(connectionString,
System.currentTimeMillis());
-return resp;
-}
-
-if (!connection.getMetadata().canRead()) {
-logger.error("This connection doesn't support reading.");
+//Try to connect to PLC
try {
Review comment:
Question, as this is a PLC4x client that exposes things as OPCUA,
wouldn't we want the client to be using the pool?
##
File path:
plc4j/integrations/opcua-server/src/main/java/org/apache/plc4x/java/opcuaserver/context/Encryption.java
##
@@ -0,0 +1,122 @@
+/*
+ * 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
+ *
+ * http://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.opcuaserver.context;
+
+import org.apache.commons.lang3.RandomUtils;
+import org.bouncycastle.asn1.DERSequence;
+import org.bouncycastle.asn1.x500.X500NameBuilder;
+import org.bouncycastle.asn1.x500.style.BCStyle;
+import org.bouncycastle.asn1.x509.Extension;
+import org.bouncycastle.asn1.x509.GeneralName;
+import org.bouncycastle.asn1.x509.GeneralNames;
+import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
+import org.bouncycastle.cert.X509CertificateHolder;
+import org.bouncycastle.cert.X509v3CertificateBuilder;
+import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.operator.ContentSigner;