Bug 8153: Enforce check-style rules for netconf - netconf-ssh 72/55972/2
authormatus.kubica <matus.kubica@pantheon.tech>
Tue, 25 Apr 2017 10:40:50 +0000 (12:40 +0200)
committermatus.kubica <matus.kubica@pantheon.tech>
Thu, 27 Apr 2017 09:01:08 +0000 (11:01 +0200)
    Organize Imports for Checkstyle compliance.
    Checkstyle compliance: line length.
    Checkstyle compliance: various types of small changes.
    Checkstyle compliant Exception handling.
    Checkstyle final clean up & enforcement.
    Add the fail on violation flag into the pom.xml .

Change-Id: Ie0c29a5ba6b165716e1eb4ccd79200f01237bf88
Signed-off-by: matus.kubica <matus.kubica@pantheon.tech>
18 files changed:
netconf/netconf-ssh/pom.xml
netconf/netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/NetconfNorthboundSshServer.java
netconf/netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/RemoteNetconfCommand.java
netconf/netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/SshProxyClientHandler.java
netconf/netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/SshProxyServer.java
netconf/netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/SshProxyServerConfiguration.java
netconf/netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/SshProxyServerConfigurationBuilder.java
netconf/netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/osgi/AuthProviderTracker.java
netconf/netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/osgi/NetconfSSHActivator.java
netconf/netconf-ssh/src/test/java/org/opendaylight/netconf/netty/EchoClient.java
netconf/netconf-ssh/src/test/java/org/opendaylight/netconf/netty/EchoClientHandler.java
netconf/netconf-ssh/src/test/java/org/opendaylight/netconf/netty/EchoServer.java
netconf/netconf-ssh/src/test/java/org/opendaylight/netconf/netty/EchoServerHandler.java
netconf/netconf-ssh/src/test/java/org/opendaylight/netconf/netty/ProxyClientHandler.java [new file with mode: 0644]
netconf/netconf-ssh/src/test/java/org/opendaylight/netconf/netty/ProxyServer.java
netconf/netconf-ssh/src/test/java/org/opendaylight/netconf/netty/ProxyServerHandler.java
netconf/netconf-ssh/src/test/java/org/opendaylight/netconf/netty/SSHTest.java
netconf/netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/authentication/SSHServerTest.java

index 64caf33c6959481253324fa1e2b7b17761ae99b5..66f87fb69936f7d661035649f73e38275e02a168 100644 (file)
           <groupId>org.opendaylight.yangtools</groupId>
           <artifactId>yang-maven-plugin</artifactId>
       </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-checkstyle-plugin</artifactId>
+        <configuration>
+          <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
 
index fca99e0b3c0e1f906abe237ecd1b87080d6c6e13..300e19f594368cd7d224fe7da4aa23dde88a81e0 100644 (file)
@@ -44,7 +44,8 @@ public class NetconfNorthboundSshServer {
         sshProxyServer = new SshProxyServer(Executors.newScheduledThreadPool(1), workerGroup, eventExecutor);
 
         final InetSocketAddress inetAddress = getInetAddress(bindingAddress, portNumber);
-        final SshProxyServerConfigurationBuilder sshProxyServerConfigurationBuilder = new SshProxyServerConfigurationBuilder();
+        final SshProxyServerConfigurationBuilder sshProxyServerConfigurationBuilder =
+                new SshProxyServerConfigurationBuilder();
         sshProxyServerConfigurationBuilder.setBindingAddress(inetAddress);
         sshProxyServerConfigurationBuilder.setLocalAddress(localAddress);
         sshProxyServerConfigurationBuilder.setAuthenticator(authProvider);
@@ -68,8 +69,9 @@ public class NetconfNorthboundSshServer {
 
     private InetSocketAddress getInetAddress(final String bindingAddress, final String portNumber) {
         try {
-            IpAddress ipAddress= IpAddressBuilder.getDefaultInstance(bindingAddress);
-            final InetAddress inetAd = InetAddress.getByName(ipAddress.getIpv4Address() == null ? ipAddress.getIpv6Address().getValue() : ipAddress.getIpv4Address().getValue());
+            IpAddress ipAddress = IpAddressBuilder.getDefaultInstance(bindingAddress);
+            final InetAddress inetAd = InetAddress.getByName(ipAddress.getIpv4Address() == null
+                    ? ipAddress.getIpv6Address().getValue() : ipAddress.getIpv4Address().getValue());
             return new InetSocketAddress(inetAd, Integer.valueOf(portNumber));
         } catch (final UnknownHostException e) {
             throw new IllegalArgumentException("Unable to bind netconf endpoint to address " + bindingAddress, e);
index 69dd6bc6f946a88b7a1203602dec8465e20739ae..b5a6355d2990c6c26926b6a3fae1280af89dce85 100644 (file)
@@ -39,6 +39,7 @@ import org.slf4j.LoggerFactory;
  * This command handles all netconf related rpc and forwards to delegate server.
  * Uses netty to make a local connection to delegate server.
  *
+ * <p>
  * Command is Apache Mina SSH terminology for objects handling ssh data.
  */
 public class RemoteNetconfCommand implements AsyncCommand, SessionAware {
@@ -105,24 +106,26 @@ public class RemoteNetconfCommand implements AsyncCommand, SessionAware {
         final Bootstrap clientBootstrap = new Bootstrap();
         clientBootstrap.group(clientEventGroup).channel(LocalChannel.class);
 
-        clientBootstrap
-                .handler(new ChannelInitializer<LocalChannel>() {
-                    @Override
-                    public void initChannel(final LocalChannel ch) throws Exception {
-                        ch.pipeline().addLast(new SshProxyClientHandler(in, out, netconfHelloMessageAdditionalHeader, callback));
-                    }
-                });
+        clientBootstrap.handler(new ChannelInitializer<LocalChannel>() {
+            @Override
+            public void initChannel(final LocalChannel ch) throws Exception {
+                ch.pipeline()
+                        .addLast(new SshProxyClientHandler(in, out, netconfHelloMessageAdditionalHeader, callback));
+            }
+        });
         clientChannelFuture = clientBootstrap.connect(localAddress);
         clientChannelFuture.addListener(new GenericFutureListener<ChannelFuture>() {
 
             @Override
             public void operationComplete(final ChannelFuture future) throws Exception {
-                if(future.isSuccess()) {
+                if (future.isSuccess()) {
                     clientChannel = clientChannelFuture.channel();
                 } else {
-                    LOG.warn("Unable to establish internal connection to netconf server for client: {}", getClientAddress());
+                    LOG.warn("Unable to establish internal connection to netconf server for client: {}",
+                            getClientAddress());
                     Preconditions.checkNotNull(callback, "Exit callback must be set");
-                    callback.onExit(1, "Unable to establish internal connection to netconf server for client: "+ getClientAddress());
+                    callback.onExit(1, "Unable to establish internal connection to netconf server for client: "
+                            + getClientAddress());
                 }
             }
         });
@@ -134,13 +137,14 @@ public class RemoteNetconfCommand implements AsyncCommand, SessionAware {
                 getClientAddress(), clientChannel);
 
         clientChannelFuture.cancel(true);
-        if(clientChannel != null) {
+        if (clientChannel != null) {
             clientChannel.close().addListener(new GenericFutureListener<ChannelFuture>() {
 
                 @Override
                 public void operationComplete(final ChannelFuture future) throws Exception {
                     if (future.isSuccess() == false) {
-                        LOG.warn("Unable to release internal connection to netconf server on channel: {}", clientChannel);
+                        LOG.warn("Unable to release internal connection to netconf server on channel: {}",
+                                clientChannel);
                     }
                 }
             });
@@ -156,7 +160,7 @@ public class RemoteNetconfCommand implements AsyncCommand, SessionAware {
         final SocketAddress remoteAddress = session.getIoSession().getRemoteAddress();
         String hostName = "";
         String port = "";
-        if(remoteAddress instanceof InetSocketAddress) {
+        if (remoteAddress instanceof InetSocketAddress) {
             hostName = ((InetSocketAddress) remoteAddress).getAddress().getHostAddress();
             port = Integer.toString(((InetSocketAddress) remoteAddress).getPort());
         }
index 66a337433878ab6f692c9de5c8a1ba23248bff93..2a198383a693c91b90b6f3faa7462d64772a2ac9 100644 (file)
@@ -22,7 +22,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Netty handler that reads SSH from remote client and writes to delegate server and reads from delegate server and writes to remote client
+ * Netty handler that reads SSH from remote client and writes to delegate server
+ * and reads from delegate server and writes to remote client.
  */
 final class SshProxyClientHandler extends ChannelInboundHandlerAdapter {
 
@@ -37,9 +38,9 @@ final class SshProxyClientHandler extends ChannelInboundHandlerAdapter {
     private final NetconfHelloMessageAdditionalHeader netconfHelloMessageAdditionalHeader;
     private final ExitCallback callback;
 
-    public SshProxyClientHandler(final IoInputStream in, final IoOutputStream out,
-                                 final NetconfHelloMessageAdditionalHeader netconfHelloMessageAdditionalHeader,
-                                 final ExitCallback callback) {
+    SshProxyClientHandler(final IoInputStream in, final IoOutputStream out,
+                          final NetconfHelloMessageAdditionalHeader netconfHelloMessageAdditionalHeader,
+                          final ExitCallback callback) {
         this.in = in;
         this.out = out;
         this.netconfHelloMessageAdditionalHeader = netconfHelloMessageAdditionalHeader;
@@ -64,9 +65,10 @@ final class SshProxyClientHandler extends ChannelInboundHandlerAdapter {
         }, new AsyncSshHandlerReader.ReadMsgHandler() {
             @Override
             public void onMessageRead(final ByteBuf msg) {
-                if(LOG.isTraceEnabled()) {
+                if (LOG.isTraceEnabled()) {
                     LOG.trace("Forwarding message for client: {} on channel: {}, message: {}",
-                            netconfHelloMessageAdditionalHeader.getAddress(), ctx.channel(), AsyncSshHandlerWriter.byteBufToString(msg));
+                            netconfHelloMessageAdditionalHeader.getAddress(), ctx.channel(),
+                            AsyncSshHandlerWriter.byteBufToString(msg));
                 }
                 // Just forward to delegate
                 ctx.writeAndFlush(msg);
@@ -90,8 +92,8 @@ final class SshProxyClientHandler extends ChannelInboundHandlerAdapter {
     public void channelInactive(final ChannelHandlerContext ctx) throws Exception {
         LOG.debug("Internal connection to netconf server was dropped for client: {} on channel: ",
                 netconfHelloMessageAdditionalHeader.getAddress(), ctx.channel());
-        callback.onExit(1, "Internal connection to netconf server was dropped for client: " +
-                netconfHelloMessageAdditionalHeader.getAddress() + " on channel: " + ctx.channel());
+        callback.onExit(1, "Internal connection to netconf server was dropped for client: "
+                netconfHelloMessageAdditionalHeader.getAddress() + " on channel: " + ctx.channel());
         super.channelInactive(ctx);
     }
 
index 9fa4bb33ab5592691bb2c08c028aaca116fdea53..ab8e22228b63efca2194e2fefdff455b09b98ab1 100644 (file)
@@ -52,10 +52,12 @@ public class SshProxyServer implements AutoCloseable {
     private final EventLoopGroup clientGroup;
     private final IoServiceFactoryFactory nioServiceWithPoolFactoryFactory;
 
-    public SshProxyServer(final ScheduledExecutorService minaTimerExecutor, final EventLoopGroup clientGroup, final ExecutorService nioExecutor) {
+    public SshProxyServer(final ScheduledExecutorService minaTimerExecutor,
+                          final EventLoopGroup clientGroup, final ExecutorService nioExecutor) {
         this.minaTimerExecutor = minaTimerExecutor;
         this.clientGroup = clientGroup;
-        this.nioServiceWithPoolFactoryFactory = new NioServiceWithPoolFactory.NioServiceWithPoolFactoryFactory(nioExecutor);
+        this.nioServiceWithPoolFactoryFactory =
+                new NioServiceWithPoolFactory.NioServiceWithPoolFactoryFactory(nioExecutor);
         this.sshServer = SshServer.setUpDefaultServer();
     }
 
@@ -86,7 +88,8 @@ public class SshProxyServer implements AutoCloseable {
         sshServer.setProperties(getProperties(sshProxyServerConfiguration));
 
         final RemoteNetconfCommand.NetconfCommandFactory netconfCommandFactory =
-                new RemoteNetconfCommand.NetconfCommandFactory(clientGroup, sshProxyServerConfiguration.getLocalAddress());
+                new RemoteNetconfCommand.NetconfCommandFactory(clientGroup,
+                        sshProxyServerConfiguration.getLocalAddress());
         sshServer.setSubsystemFactories(ImmutableList.of(netconfCommandFactory));
         sshServer.start();
     }
@@ -112,14 +115,15 @@ public class SshProxyServer implements AutoCloseable {
     }
 
     /**
-     * Based on Nio2ServiceFactory with one addition: injectable executor
+     * Based on Nio2ServiceFactory with one addition: injectable executor.
      */
-    private static final class NioServiceWithPoolFactory extends CloseableUtils.AbstractCloseable implements IoServiceFactory {
+    private static final class NioServiceWithPoolFactory
+            extends CloseableUtils.AbstractCloseable implements IoServiceFactory {
 
         private final FactoryManager manager;
         private final AsynchronousChannelGroup group;
 
-        public NioServiceWithPoolFactory(final FactoryManager manager, final ExecutorService executor) {
+        NioServiceWithPoolFactory(final FactoryManager manager, final ExecutorService executor) {
             this.manager = manager;
             try {
                 group = AsynchronousChannelGroup.withThreadPool(executor);
@@ -138,6 +142,7 @@ public class SshProxyServer implements AutoCloseable {
             return new Nio2Acceptor(manager, handler, group);
         }
 
+        @SuppressWarnings("checkstyle:IllegalCatch")
         @Override
         protected void doCloseImmediately() {
             try {
index 55b54862d2e2abcea38ba1bc61ba3a00f1e3dfc0..9fe57a40b692105fcaa2568dba7446c160ad5dd6 100644 (file)
@@ -21,7 +21,8 @@ public final class SshProxyServerConfiguration {
     private final KeyPairProvider keyPairProvider;
     private final int idleTimeout;
 
-    SshProxyServerConfiguration(final InetSocketAddress bindingAddress, final LocalAddress localAddress, final AuthProvider authenticator, final KeyPairProvider keyPairProvider, final int idleTimeout) {
+    SshProxyServerConfiguration(final InetSocketAddress bindingAddress, final LocalAddress localAddress,
+                    final AuthProvider authenticator, final KeyPairProvider keyPairProvider, final int idleTimeout) {
         this.bindingAddress = Preconditions.checkNotNull(bindingAddress);
         this.localAddress = Preconditions.checkNotNull(localAddress);
         this.authenticator = Preconditions.checkNotNull(authenticator);
index 14b00b462d93c6942f413fc4551f16e7cf832117..5b7948ed6fde4a803e10e2a96c2cbafd19d9224a 100644 (file)
@@ -46,7 +46,8 @@ public final class SshProxyServerConfigurationBuilder {
     }
 
     public SshProxyServerConfiguration createSshProxyServerConfiguration() {
-        return new SshProxyServerConfiguration(bindingAddress, localAddress, authenticator, keyPairProvider, idleTimeout);
+        return new SshProxyServerConfiguration(bindingAddress, localAddress, authenticator,
+                keyPairProvider, idleTimeout);
     }
 
     public static SshProxyServerConfigurationBuilder create() {
index 51be1bc3eae126e1e1204d2ef626fcb3433366cc..124e7e7ac16948c80331e3cb0fd8e32a309a86d6 100644 (file)
@@ -24,7 +24,7 @@ final class AuthProviderTracker implements ServiceTrackerCustomizer<AuthProvider
     private final ServiceTracker<AuthProvider, AuthProvider> listenerTracker;
     private volatile AuthProvider authProvider;
 
-    public AuthProviderTracker(final BundleContext bundleContext) {
+    AuthProviderTracker(final BundleContext bundleContext) {
         this.bundleContext = bundleContext;
         listenerTracker = new ServiceTracker<>(bundleContext, AuthProvider.class, this);
         listenerTracker.open();
index fddbc7389b3ec85ac70bc6a237fcd777bd80a170..f31f7b95b1ed93cb0d81e202ee5b5ab99f5f54da 100644 (file)
@@ -46,8 +46,8 @@ public class NetconfSSHActivator implements BundleActivator {
     public void start(final BundleContext bundleContext) throws IOException, InvalidSyntaxException {
         minaTimerExecutor = Executors.newScheduledThreadPool(POOL_SIZE, new ThreadFactory() {
             @Override
-            public Thread newThread(final Runnable r) {
-                return new Thread(r, "netconf-ssh-server-mina-timers");
+            public Thread newThread(final Runnable runnable) {
+                return new Thread(runnable, "netconf-ssh-server-mina-timers");
             }
         });
         clientGroup = new NioEventLoopGroup();
@@ -61,19 +61,19 @@ public class NetconfSSHActivator implements BundleActivator {
             server.close();
         }
 
-        if(authProviderTracker != null) {
+        if (authProviderTracker != null) {
             authProviderTracker.stop();
         }
 
-        if(nioExecutor!=null) {
+        if (nioExecutor != null) {
             nioExecutor.shutdownNow();
         }
 
-        if(clientGroup != null) {
+        if (clientGroup != null) {
             clientGroup.shutdownGracefully();
         }
 
-        if(minaTimerExecutor != null) {
+        if (minaTimerExecutor != null) {
             minaTimerExecutor.shutdownNow();
         }
     }
index c8584a7ed8cb608aa34279aba1e866ea37fe34c4..2cdd97c9f90994a47472439a9320ad151a3a92b6 100644 (file)
@@ -45,23 +45,24 @@ public class EchoClient extends Thread {
         this.channelInitializer = channelInitializer;
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
     public void run() {
         // Configure the client.
         EventLoopGroup group = new NioEventLoopGroup();
         try {
-            Bootstrap b = new Bootstrap();
+            Bootstrap bootstrap = new Bootstrap();
 
-            b.group(group)
+            bootstrap.group(group)
                     .channel(LocalChannel.class)
                     .handler(channelInitializer);
 
             // Start the client.
             LocalAddress localAddress = new LocalAddress("foo");
-            ChannelFuture f = b.connect(localAddress).sync();
+            ChannelFuture future = bootstrap.connect(localAddress).sync();
 
             // Wait until the connection is closed.
-            f.channel().closeFuture().sync();
+            future.channel().closeFuture().sync();
         } catch (Exception e) {
             LOG.error("Error in client", e);
             throw new RuntimeException("Error in client", e);
index 5d571a5caad660d9c21db1db0f407c2f76e99ce7..2a94d38161e9763322e5b77b80f0f2174c9cad4f 100644 (file)
@@ -31,7 +31,9 @@ public class EchoClientHandler extends ChannelInboundHandlerAdapter implements C
     private ChannelHandlerContext ctx;
     private final StringBuilder fromServer = new StringBuilder();
 
-    public static enum State {CONNECTING, CONNECTED, FAILED_TO_CONNECT, CONNECTION_CLOSED}
+    public enum State {
+        CONNECTING, CONNECTED, FAILED_TO_CONNECT, CONNECTION_CLOSED
+    }
 
 
     private State state = State.CONNECTING;
index a6f9e6cb66595bd0616c35774684571fe683a11b..c660ffd02b0f0643b4a4e088fdaa07c797f589f5 100644 (file)
@@ -31,13 +31,14 @@ import org.slf4j.LoggerFactory;
 public class EchoServer implements Runnable {
     private static final Logger LOG = LoggerFactory.getLogger(EchoServer.class);
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public void run() {
         // Configure the server.
         EventLoopGroup bossGroup = new NioEventLoopGroup(1);
         EventLoopGroup workerGroup = new NioEventLoopGroup();
         try {
-            ServerBootstrap b = new ServerBootstrap();
-            b.group(bossGroup, workerGroup)
+            ServerBootstrap bootstrap = new ServerBootstrap();
+            bootstrap.group(bossGroup, workerGroup)
                     .channel(LocalServerChannel.class)
                     .option(ChannelOption.SO_BACKLOG, 100)
                     .handler(new LoggingHandler(LogLevel.INFO))
@@ -50,10 +51,10 @@ public class EchoServer implements Runnable {
 
             // Start the server.
             LocalAddress localAddress = NetconfConfiguration.NETCONF_LOCAL_ADDRESS;
-            ChannelFuture f = b.bind(localAddress).sync();
+            ChannelFuture future = bootstrap.bind(localAddress).sync();
 
             // Wait until the server socket is closed.
-            f.channel().closeFuture().sync();
+            future.channel().closeFuture().sync();
         } catch (Exception e) {
             throw new RuntimeException(e);
         } finally {
index 38634280ffd8ca5f506c01c0abffab5c5e84e464..632d207ea7e76a61438027089432be8503a90cb6 100644 (file)
@@ -26,6 +26,7 @@ public class EchoServerHandler extends ChannelInboundHandlerAdapter {
     private static final Logger LOG = LoggerFactory.getLogger(EchoServerHandler.class);
     private String fromLastNewLine = "";
     private final Splitter splitter = Splitter.onPattern("\r?\n");
+
     @Override
     public void channelActive(ChannelHandlerContext ctx) throws Exception {
         LOG.debug("sleep start");
diff --git a/netconf/netconf-ssh/src/test/java/org/opendaylight/netconf/netty/ProxyClientHandler.java b/netconf/netconf-ssh/src/test/java/org/opendaylight/netconf/netty/ProxyClientHandler.java
new file mode 100644 (file)
index 0000000..dd1daed
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.netty;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import java.nio.charset.StandardCharsets;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+class ProxyClientHandler extends ChannelInboundHandlerAdapter {
+    private static final Logger LOG = LoggerFactory.getLogger(ProxyClientHandler.class);
+
+    private final ChannelHandlerContext remoteCtx;
+
+
+    ProxyClientHandler(ChannelHandlerContext remoteCtx) {
+        this.remoteCtx = remoteCtx;
+    }
+
+    @Override
+    public void channelActive(ChannelHandlerContext ctx) {
+        LOG.info("client active");
+    }
+
+    @Override
+    public void channelRead(ChannelHandlerContext ctx, Object msg) {
+        ByteBuf bb = (ByteBuf) msg;
+        LOG.info(">{}", bb.toString(StandardCharsets.UTF_8));
+        remoteCtx.write(msg);
+    }
+
+    @Override
+    public void channelReadComplete(ChannelHandlerContext ctx) {
+        LOG.debug("Flushing server ctx");
+        remoteCtx.flush();
+    }
+
+    @Override
+    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
+        // Close the connection when an exception is raised.
+        LOG.warn("Unexpected exception from downstream", cause);
+        ctx.close();
+    }
+
+    // called both when local or remote connection dies
+    @Override
+    public void channelInactive(ChannelHandlerContext ctx) {
+        LOG.debug("channelInactive() called, closing remote client ctx");
+        remoteCtx.close();
+    }
+}
index ee34f8fd2f1ad2acbf4a746f1794bc140513563d..3b693512ea659ec1ae227f3a8f6cec8b903989fa 100644 (file)
@@ -30,6 +30,7 @@ public class ProxyServer implements Runnable {
         this.proxyHandlerFactory = proxyHandlerFactory;
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public void run() {
         // Configure the server.
         final EventLoopGroup bossGroup = new NioEventLoopGroup();
@@ -50,10 +51,10 @@ public class ProxyServer implements Runnable {
 
             // Start the server.
             InetSocketAddress address = new InetSocketAddress("127.0.0.1", 8080);
-            ChannelFuture f = serverBootstrap.bind(address).sync();
+            ChannelFuture future = serverBootstrap.bind(address).sync();
 
             // Wait until the server socket is closed.
-            f.channel().closeFuture().sync();
+            future.channel().closeFuture().sync();
         } catch (Exception e) {
             throw new RuntimeException(e);
         } finally {
@@ -62,7 +63,8 @@ public class ProxyServer implements Runnable {
             workerGroup.shutdownGracefully();
         }
     }
-    public static interface ProxyHandlerFactory {
+
+    public interface ProxyHandlerFactory {
         ChannelHandler create(EventLoopGroup bossGroup, LocalAddress localAddress);
     }
 
index dc879c233229f0755dd138f12a1eba034f26767b..c70efcdb34eea40e787f9d3e9e5b5c19776aeed2 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.netconf.netty;
 
 import io.netty.bootstrap.Bootstrap;
-import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
@@ -19,7 +18,6 @@ import io.netty.channel.ChannelInitializer;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.local.LocalAddress;
 import io.netty.channel.local.LocalChannel;
-import java.nio.charset.StandardCharsets;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -77,45 +75,3 @@ public class ProxyServerHandler extends ChannelInboundHandlerAdapter {
     }
 }
 
-class ProxyClientHandler extends ChannelInboundHandlerAdapter {
-    private static final Logger LOG = LoggerFactory.getLogger(ProxyClientHandler.class);
-
-    private final ChannelHandlerContext remoteCtx;
-
-
-    public ProxyClientHandler(ChannelHandlerContext remoteCtx) {
-        this.remoteCtx = remoteCtx;
-    }
-
-    @Override
-    public void channelActive(ChannelHandlerContext ctx) {
-        LOG.info("client active");
-    }
-
-    @Override
-    public void channelRead(ChannelHandlerContext ctx, Object msg) {
-        ByteBuf bb = (ByteBuf) msg;
-        LOG.info(">{}", bb.toString(StandardCharsets.UTF_8));
-        remoteCtx.write(msg);
-    }
-
-    @Override
-    public void channelReadComplete(ChannelHandlerContext ctx) {
-        LOG.debug("Flushing server ctx");
-        remoteCtx.flush();
-    }
-
-    @Override
-    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
-        // Close the connection when an exception is raised.
-        LOG.warn("Unexpected exception from downstream", cause);
-        ctx.close();
-    }
-
-    // called both when local or remote connection dies
-    @Override
-    public void channelInactive(ChannelHandlerContext ctx) {
-        LOG.debug("channelInactive() called, closing remote client ctx");
-        remoteCtx.close();
-    }
-}
index 759b96210bdd068c05f1a6309b223c3d026e40ab..3b1a6950280d2722df43f36ff9ca3148b3c3dee9 100644 (file)
@@ -73,18 +73,21 @@ public class SSHTest {
 
         final InetSocketAddress addr = new InetSocketAddress("127.0.0.1", 10831);
         final SshProxyServer sshProxyServer = new SshProxyServer(minaTimerEx, nettyGroup, nioExec);
-        sshProxyServer.bind(
-                new SshProxyServerConfigurationBuilder().setBindingAddress(addr).setLocalAddress(NetconfConfiguration.NETCONF_LOCAL_ADDRESS).setAuthenticator(new AuthProvider() {
-                    @Override
-                    public boolean authenticated(final String username, final String password) {
-                        return true;
-                    }
-                }).setKeyPairProvider(new PEMGeneratorHostKeyProvider(sshKeyPair.toPath().toAbsolutePath().toString())).setIdleTimeout(Integer.MAX_VALUE).createSshProxyServerConfiguration());
+        sshProxyServer.bind(new SshProxyServerConfigurationBuilder()
+                .setBindingAddress(addr).setLocalAddress(NetconfConfiguration.NETCONF_LOCAL_ADDRESS)
+                .setAuthenticator(new AuthProvider() {
+                        @Override
+                        public boolean authenticated(final String username, final String password) {
+                            return true;
+                        }
+                })
+                .setKeyPairProvider(new PEMGeneratorHostKeyProvider(sshKeyPair.toPath().toAbsolutePath().toString()))
+                .setIdleTimeout(Integer.MAX_VALUE).createSshProxyServerConfiguration());
 
         final EchoClientHandler echoClientHandler = connectClient(addr);
 
         Stopwatch stopwatch = Stopwatch.createStarted();
-        while(echoClientHandler.isConnected() == false && stopwatch.elapsed(TimeUnit.SECONDS) < 30) {
+        while (echoClientHandler.isConnected() == false && stopwatch.elapsed(TimeUnit.SECONDS) < 30) {
             Thread.sleep(500);
         }
         assertTrue(echoClientHandler.isConnected());
@@ -131,7 +134,7 @@ public class SSHTest {
         final InetSocketAddress address = new InetSocketAddress(12345);
         final EchoClientHandler echoClientHandler = connectClient(address);
         final Stopwatch stopwatch = Stopwatch.createStarted();
-        while(echoClientHandler.getState() == State.CONNECTING && stopwatch.elapsed(TimeUnit.SECONDS) < 5) {
+        while (echoClientHandler.getState() == State.CONNECTING && stopwatch.elapsed(TimeUnit.SECONDS) < 5) {
             Thread.sleep(100);
         }
         assertFalse(echoClientHandler.isConnected());
index 1257e4b7e923f4bed84ac260b7f3e883c5d7db05..7af4598997cc6254906f387fa7d809f8c0092ee0 100644 (file)
@@ -72,13 +72,16 @@ public class SSHServerTest {
 
         final InetSocketAddress addr = InetSocketAddress.createUnresolved(HOST, PORT);
         server = new SshProxyServer(minaTimerEx, clientGroup, nioExec);
-        server.bind(
-                new SshProxyServerConfigurationBuilder().setBindingAddress(addr).setLocalAddress(NetconfConfiguration.NETCONF_LOCAL_ADDRESS).setAuthenticator(new AuthProvider() {
+        server.bind(new SshProxyServerConfigurationBuilder()
+                .setBindingAddress(addr).setLocalAddress(NetconfConfiguration.NETCONF_LOCAL_ADDRESS)
+                .setAuthenticator(new AuthProvider() {
                     @Override
                     public boolean authenticated(final String username, final String password) {
                         return true;
                     }
-                }).setKeyPairProvider(new PEMGeneratorHostKeyProvider(sshKeyPair.toPath().toAbsolutePath().toString())).setIdleTimeout(Integer.MAX_VALUE).createSshProxyServerConfiguration());
+                })
+                .setKeyPairProvider(new PEMGeneratorHostKeyProvider(sshKeyPair.toPath().toAbsolutePath().toString()))
+                .setIdleTimeout(Integer.MAX_VALUE).createSshProxyServerConfiguration());
         LOG.info("SSH server started on {}", PORT);
     }