+ private static final String CONNECTION_TIMEOUT_MILLIS_PROP = "connectionTimeoutMillis";
+ private static final long DEFAULT_TIMEOUT_MILLIS = 5000;
+
+ public static long extractTimeoutMillis(final BundleContext bundleContext) {
+ final String key = PREFIX_PROP + CONNECTION_TIMEOUT_MILLIS_PROP;
+ final String timeoutString = bundleContext.getProperty(key);
+ if (timeoutString == null || timeoutString.length() == 0) {
+ return DEFAULT_TIMEOUT_MILLIS;
+ }
+ try {
+ return Long.parseLong(timeoutString);
+ } catch (final NumberFormatException e) {
+ logger.warn("Cannot parse {} property: {}, using defaults", key, timeoutString, e);
+ return DEFAULT_TIMEOUT_MILLIS;
+ }
+ }
+
+ public static InetSocketAddress extractTCPNetconfServerAddress(final BundleContext context, final InetSocketAddress defaultAddress) {
+ final Optional<InetSocketAddress> extracted = extractNetconfServerAddress(context, InfixProp.tcp);
+ final InetSocketAddress netconfTcpAddress = getNetconfAddress(defaultAddress, extracted, InfixProp.tcp);
+ logger.debug("Using {} as netconf tcp address", netconfTcpAddress);
+ if (netconfTcpAddress.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);
+ }
+ return netconfTcpAddress;
+ }
+
+ public static InetSocketAddress extractTCPNetconfClientAddress(final BundleContext context, final InetSocketAddress defaultAddress) {
+ final Optional<InetSocketAddress> extracted = extractNetconfClientAddress(context, InfixProp.tcp);
+ return getNetconfAddress(defaultAddress, extracted, InfixProp.tcp);
+ }
+
+ /**
+ * 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;