fix failure during connecting device when channelActive happens later than handleMessage
[netconf.git] / netconf / netconf-client / src / main / java / org / opendaylight / netconf / client / NetconfClientSessionNegotiator.java
index 608450225f52d84d71cff3d1443b739905edaa5d..0b456f447f8ce33be11239ec8901dcffe0a041aa 100644 (file)
@@ -63,8 +63,19 @@ public class NetconfClientSessionNegotiator extends
         super(sessionPreferences, promise, channel, timer, sessionListener, connectionTimeoutMillis);
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
     protected void handleMessage(final NetconfHelloMessage netconfMessage) throws NetconfDocumentedException {
+        if (!ifNegotiatedAlready()) {
+            LOG.debug("Server hello message received, starting negotiation on channel {}", channel);
+            try {
+                startNegotiation();
+            } catch (final Exception e) {
+                LOG.warn("Unexpected negotiation failure", e);
+                negotiationFailed(e);
+                return;
+            }
+        }
         final NetconfClientSession session = getSessionForHelloMessage(netconfMessage);
         replaceHelloMessageInboundHandler(session);