This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new a17bcc8652 fix(plc4j/opcua): OPC UA priority judgment using discovery
parameter (#1157)
a17bcc8652 is described below
commit a17bcc865208a68f521d7688b26422e5c07bb7f2
Author: China.Roger <[email protected]>
AuthorDate: Wed Oct 18 17:08:27 2023 +0800
fix(plc4j/opcua): OPC UA priority judgment using discovery parameter (#1157)
* Priority judgment using discovery parameter
When the parameter discovery=false is configured, prefer using the custom
address. If the transportEndpoint is empty, directly replace it with the
TransportEndpoint returned by the server.
* add setter for transportEndpoint
---
.../apache/plc4x/java/opcua/context/OpcuaDriverContext.java | 4 ++++
.../org/apache/plc4x/java/opcua/context/SecureChannel.java | 13 +++++++++----
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git
a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/OpcuaDriverContext.java
b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/OpcuaDriverContext.java
index 975240234a..b72c303db1 100644
---
a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/OpcuaDriverContext.java
+++
b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/OpcuaDriverContext.java
@@ -117,6 +117,10 @@ public class OpcuaDriverContext implements DriverContext,
HasConfiguration<Opcua
public String getTransportEndpoint() {
return transportEndpoint;
}
+
+ public void setTransportEndpoint(String transportEndpoint) {
+ this.transportEndpoint = transportEndpoint;
+ }
public Boolean getEncrypted() {
return isEncrypted;
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 3574fdfd1b..b9fff8fd82 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
@@ -25,6 +25,7 @@ import static java.util.concurrent.ForkJoinPool.commonPool;
import java.time.Instant;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.plc4x.java.api.authentication.PlcAuthentication;
import
org.apache.plc4x.java.api.authentication.PlcUsernamePasswordAuthentication;
import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
@@ -1220,6 +1221,14 @@ public class SecureChannel {
"Endpoint returned from the server doesn't match the format
'{protocol-code}:({transport-code})?//{transport-host}(:{transport-port})(/{transport-endpoint})'");
}
LOGGER.trace("Using Endpoint {} {} {}",
matcher.group("transportHost"), matcher.group("transportPort"),
matcher.group("transportEndpoint"));
+
+ //When the parameter discovery=false is configured, prefer using the
custom address. If the transportEndpoint is empty,
+ // directly replace it with the TransportEndpoint returned by the
server.
+ if (!configuration.isDiscovery() &&
StringUtils.isBlank(driverContext.getTransportEndpoint())) {
+
driverContext.setTransportEndpoint(matcher.group("transportEndpoint"));
+ return true;
+ }
+
if (configuration.isDiscovery() &&
!this.endpoints.contains(matcher.group("transportHost"))) {
return false;
}
@@ -1232,10 +1241,6 @@ public class SecureChannel {
return false;
}
- if (!configuration.isDiscovery()) {
- driverContext.setHost(matcher.group("transportHost"));
- }
-
return true;
}