- String portKey = PREFIX_PROP + infixProp + PORT_SUFFIX_PROP;
- String portString = context.getProperty(portKey);
- checkNotNull(portString, "Netconf port must be specified in properties file with " + portKey);
- try {
- int port = Integer.valueOf(portString);
- return Optional.of(new InetSocketAddress(address, port));
- } catch (RuntimeException e) {
- throw new IllegalStateException("Cannot create " + infixProp + " netconf address from address:" + address
- + " and port:" + portString, e);
+ return Optional.absent();
+ }
+
+ private static InetSocketAddress parseAddress(final Optional<String> address, final Optional<String> port) {
+ final int portNumber = Integer.valueOf(port.get());
+ return new InetSocketAddress(address.get(), portNumber);
+ }
+
+ private static Optional<InetSocketAddress> extractNetconfClientAddress(final BundleContext context,
+ final InfixProp infixProp) {
+ final Optional<String> address = getProperty(context,
+ PREFIX_PROP + infixProp + CLIENT_PROP + ADDRESS_SUFFIX_PROP);
+ final Optional<String> port = getProperty(context,
+ PREFIX_PROP + infixProp + CLIENT_PROP + PORT_SUFFIX_PROP);
+
+ if (address.isPresent() && port.isPresent()) {
+ try {
+ return Optional.of(parseAddress(address, port));
+ } catch (final RuntimeException e) {
+ logger.warn("Unable to parse client {} netconf address from {}:{}, fallback to server address",
+ infixProp, address, port, e);
+ }
+ }
+ return extractNetconfServerAddress(context, infixProp);
+ }
+
+ private static Optional<String> getProperty(final BundleContext context, final String propKey) {
+ String value = context.getProperty(propKey);
+ if (value != null && value.isEmpty()) {
+ value = null;