From da07666e8a792d80b681e38f1d838c3df5993bb0 Mon Sep 17 00:00:00 2001 From: Kevin Herron Date: Fri, 6 Jun 2025 04:20:02 -0700 Subject: [PATCH] Add a new `OpcUaClient.create` overload Adds a new `OpcUaClient.create` overload that accepts an `OpcUaClientConfig` and a callback that can be used to configure an `OpcTcpClientTransportConfigBuilder`. fixes #1486 --- .../milo/opcua/sdk/client/OpcUaClient.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/opc-ua-sdk/sdk-client/src/main/java/org/eclipse/milo/opcua/sdk/client/OpcUaClient.java b/opc-ua-sdk/sdk-client/src/main/java/org/eclipse/milo/opcua/sdk/client/OpcUaClient.java index 6e9444f29..18948a69d 100644 --- a/opc-ua-sdk/sdk-client/src/main/java/org/eclipse/milo/opcua/sdk/client/OpcUaClient.java +++ b/opc-ua-sdk/sdk-client/src/main/java/org/eclipse/milo/opcua/sdk/client/OpcUaClient.java @@ -178,8 +178,8 @@ public class OpcUaClient { * Create an {@link OpcUaClient} configured with {@code config}. * * @param config the {@link OpcUaClientConfig}. - * @return an {@link OpcUaClient} configured with {@code config}. - * @throws UaException if the client could not be created (e.g. transport/encoding not supported). + * @return a new {@link OpcUaClient} configured with {@code config}. + * @throws UaException if the client could not be created. */ public static OpcUaClient create(OpcUaClientConfig config) throws UaException { OpcTcpClientTransportConfig transportConfig = OpcTcpClientTransportConfig.newBuilder().build(); @@ -188,6 +188,27 @@ public static OpcUaClient create(OpcUaClientConfig config) throws UaException { return new OpcUaClient(config, transport); } + /** + * Create an {@link OpcUaClient} configured with {@code config}. + * + * @param config the {@link OpcUaClientConfig}. + * @param configureTransport a Consumer that receives an {@link + * OpcTcpClientTransportConfigBuilder} that can be used to configure the transport. + * @return a new {@link OpcUaClient} configured with {@code config}. + * @throws UaException if the client could not be created. + */ + public static OpcUaClient create( + OpcUaClientConfig config, Consumer configureTransport) + throws UaException { + + var transportConfigBuilder = OpcTcpClientTransportConfig.newBuilder(); + configureTransport.accept(transportConfigBuilder); + + OpcTcpClientTransportConfig transportConfig = transportConfigBuilder.build(); + + return new OpcUaClient(config, new OpcTcpClientTransport(transportConfig)); + } + /** * Select the first endpoint with no security that allows anonymous connections and create an * {@link OpcUaClient} with the default configuration.