- public static InetSocketAddress extractTCPNetconfAddress(BundleContext context, String exceptionMessageIfNotFound, boolean forClient) {
-
- Optional<InetSocketAddress> inetSocketAddressOptional = extractSomeNetconfAddress(context, InfixProp.tcp, exceptionMessageIfNotFound, forClient);
-
- if (inetSocketAddressOptional.isPresent() == false) {
- throw new IllegalStateException("Netconf tcp address not found." + exceptionMessageIfNotFound);
- }
- InetSocketAddress inetSocketAddress = inetSocketAddressOptional.get();
- if (inetSocketAddress.getAddress().isAnyLocalAddress()) {
- logger.warn("Unprotected netconf TCP address is configured to ANY local address. This is a security risk. " +
- "Consider changing {} to 127.0.0.1", PREFIX_PROP + InfixProp.tcp + ADDRESS_SUFFIX_PROP);
+ /**
+ * Get extracted address or default.
+ *
+ * @throws java.lang.IllegalStateException if neither address is present.
+ */
+ private static InetSocketAddress getNetconfAddress(final InetSocketAddress defaultAddress, Optional<InetSocketAddress> extractedAddress, InfixProp infix) {
+ InetSocketAddress inetSocketAddress;
+
+ if (extractedAddress.isPresent() == false) {
+ logger.debug("Netconf {} address not found, falling back to default {}", infix, defaultAddress);
+
+ if (defaultAddress == null) {
+ logger.warn("Netconf {} address not found, default address not provided", infix);
+ throw new IllegalStateException("Netconf " + infix + " address not found, default address not provided");
+ }
+ inetSocketAddress = defaultAddress;
+ } else {
+ inetSocketAddress = extractedAddress.get();