- private static Optional<InetSocketAddress> extractSomeNetconfAddress(BundleContext context,
- InfixProp infixProp,
- String exceptionMessage,
- boolean client) {
- String address = "";
- if (client) {
- address = context.getProperty(PREFIX_PROP + infixProp + CLIENT_PROP + ADDRESS_SUFFIX_PROP);
- }
- if (address == null || address.equals("")){
- address = context.getProperty(PREFIX_PROP + infixProp + ADDRESS_SUFFIX_PROP);
- }
- if (address == null || address.equals("")) {
- throw new IllegalStateException("Cannot find initial netconf configuration for parameter "
- +PREFIX_PROP + infixProp + ADDRESS_SUFFIX_PROP
- +" in config.ini. "+exceptionMessage);
- }
- String portKey = "";
- if (client) {
- portKey = PREFIX_PROP + infixProp + CLIENT_PROP + PORT_SUFFIX_PROP;
+ public static Optional<InetSocketAddress> extractNetconfServerAddress(final BundleContext context,
+ final InfixProp infixProp) {
+
+ final Optional<String> address = getProperty(context, getNetconfServerAddressKey(infixProp));
+ final Optional<String> port = getProperty(context, PREFIX_PROP + infixProp + PORT_SUFFIX_PROP);
+
+ if (address.isPresent() && port.isPresent()) {
+ try {
+ return Optional.of(parseAddress(address, port));
+ } catch (final RuntimeException e) {
+ LOG.warn("Unable to parse {} netconf address from {}:{}, fallback to default",
+ infixProp, address, port, e);
+ }