Sonar fixes in "appc-netconf-adapter-bundle"
[appc.git] / appc-adapters / appc-netconf-adapter / appc-netconf-adapter-bundle / src / main / java / org / onap / appc / adapter / netconf / jsch / NetconfClientJsch.java
index 7b9d7a4..c60fbbd 100644 (file)
@@ -75,17 +75,9 @@ public class NetconfClientJsch implements NetconfClient {
 
             session.connect(SESSION_CONNECT_TIMEOUT);
             session.setTimeout(10000);
-            try {
-//                session.setServerAliveCountMax(0); // If this is not set to '0', then socket timeout on all reads will not work!!!!
-                channel = session.openChannel("subsystem");
-                ((ChannelSubsystem)channel).setSubsystem("netconf");
-                netconfAdapter = new NetconfAdapter(channel.getInputStream(), channel.getOutputStream());
-                channel.connect(CHANNEL_CONNECT_TIMEOUT);
-                hello(connectionDetails.getCapabilities());
-            } catch(Exception e) {
-                disconnect();
-                throw e;
-            }
+
+            createConnection(connectionDetails);
+
         } catch(Exception e) {
             String message = EELFResourceManager.format(Msg.CANNOT_ESTABLISH_CONNECTION, host, String.valueOf(port), username);
             throw new APPCException(message, e);
@@ -138,6 +130,20 @@ public class NetconfClientJsch implements NetconfClient {
         }
     }
 
+    private void createConnection(NetconfConnectionDetails connectionDetails) throws APPCException {
+        try {
+//          session.setServerAliveCountMax(0); // If this is not set to '0', then socket timeout on all reads will not work!!!!
+            channel = session.openChannel("subsystem");
+            ((ChannelSubsystem)channel).setSubsystem("netconf");
+            netconfAdapter = new NetconfAdapter(channel.getInputStream(), channel.getOutputStream());
+            channel.connect(CHANNEL_CONNECT_TIMEOUT);
+            hello(connectionDetails.getCapabilities());
+        } catch(Exception e) {
+            disconnect();
+            throw new APPCException(e);
+        }
+    }
+
     private void hello(List<String> capabilities) throws IOException {
         String helloIn = netconfAdapter.receiveMessage();
         if(helloIn == null) {