* 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;
+package org.opendaylight.netconf.ssh;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
public EchoClient(final ChannelHandler clientHandler) {
channelInitializer = new ChannelInitializer<>() {
@Override
- public void initChannel(final LocalChannel ch) throws Exception {
+ public void initChannel(final LocalChannel ch) {
ch.pipeline().addLast(clientHandler);
}
};
* 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;
+package org.opendaylight.netconf.ssh;
import static com.google.common.base.Preconditions.checkState;
import static java.nio.charset.StandardCharsets.UTF_8;
* the server.
*/
public class EchoClientHandler extends ChannelInboundHandlerAdapter implements ChannelFutureListener {
- private static final Logger LOG = LoggerFactory.getLogger(EchoClientHandler.class);
-
- private ChannelHandlerContext context;
- private final StringBuilder fromServer = new StringBuilder();
-
public enum State {
CONNECTING, CONNECTED, FAILED_TO_CONNECT, CONNECTION_CLOSED
}
+ private static final Logger LOG = LoggerFactory.getLogger(EchoClientHandler.class);
+ private final StringBuilder fromServer = new StringBuilder();
+ private ChannelHandlerContext context;
private State state = State.CONNECTING;
@Override
- public synchronized void channelActive(ChannelHandlerContext ctx) {
+ public synchronized void channelActive(final ChannelHandlerContext ctx) {
checkState(context == null);
LOG.info("channelActive");
context = ctx;
}
@Override
- public synchronized void channelInactive(ChannelHandlerContext ctx) throws Exception {
+ public synchronized void channelInactive(final ChannelHandlerContext ctx) throws Exception {
state = State.CONNECTION_CLOSED;
}
@Override
- public synchronized void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
+ public synchronized void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception {
ByteBuf bb = (ByteBuf) msg;
String string = bb.toString(UTF_8);
fromServer.append(string);
}
@Override
- public synchronized void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
+ public synchronized void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
// Close the connection when an exception is raised.
LOG.warn("Unexpected exception from downstream.", cause);
checkState(context.equals(ctx));
context = null;
}
- public synchronized void write(String message) {
+ public synchronized void write(final String message) {
ByteBuf byteBuf = Unpooled.copiedBuffer(message.getBytes());
context.writeAndFlush(byteBuf);
}
}
@Override
- public synchronized void operationComplete(ChannelFuture future) throws Exception {
+ public synchronized void operationComplete(final ChannelFuture future) throws Exception {
checkState(state == State.CONNECTING);
if (future.isSuccess()) {
LOG.trace("Successfully connected, state will be switched in channelActive");
* 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;
+package org.opendaylight.netconf.ssh;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ChannelInitializer<LocalChannel>() {
@Override
- public void initChannel(final LocalChannel ch) throws Exception {
+ public void initChannel(final LocalChannel ch) {
ch.pipeline().addLast(new EchoServerHandler());
}
});
* 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;
+package org.opendaylight.netconf.ssh;
import com.google.common.base.Splitter;
import io.netty.buffer.ByteBuf;
private final Splitter splitter = Splitter.onPattern("\r?\n");
@Override
- public void channelActive(ChannelHandlerContext ctx) throws Exception {
+ public void channelActive(final ChannelHandlerContext ctx) throws Exception {
LOG.debug("sleep start");
Thread.sleep(1000);
LOG.debug("sleep done");
}
@Override
- public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
+ public void channelRead(final ChannelHandlerContext ctx, final Object msg) {
ByteBuf byteBuf = (ByteBuf) msg;
String message = byteBuf.toString(StandardCharsets.UTF_8);
LOG.info("writing back '{}'", message);
}
@Override
- public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
+ public void channelReadComplete(final ChannelHandlerContext ctx) {
LOG.debug("flushing");
ctx.flush();
}
* 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;
+package org.opendaylight.netconf.ssh;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
* 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;
+package org.opendaylight.netconf.ssh;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
* 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;
+package org.opendaylight.netconf.ssh;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.Unpooled;
private Channel clientChannel;
- public ProxyServerHandler(EventLoopGroup bossGroup, LocalAddress localAddress) {
+ public ProxyServerHandler(final EventLoopGroup bossGroup, final LocalAddress localAddress) {
clientBootstrap = new Bootstrap();
clientBootstrap.group(bossGroup).channel(LocalChannel.class);
this.localAddress = localAddress;
}
@Override
- public void channelActive(ChannelHandlerContext remoteCtx) {
+ public void channelActive(final ChannelHandlerContext remoteCtx) {
final ProxyClientHandler clientHandler = new ProxyClientHandler(remoteCtx);
clientBootstrap.handler(new ChannelInitializer<LocalChannel>() {
@Override
- public void initChannel(LocalChannel ch) throws Exception {
+ public void initChannel(final LocalChannel ch) {
ch.pipeline().addLast(clientHandler);
}
});
}
@Override
- public void channelInactive(ChannelHandlerContext ctx) {
+ public void channelInactive(final ChannelHandlerContext ctx) {
LOG.info("channelInactive - closing client connection");
clientChannel.close();
}
@Override
- public void channelRead(ChannelHandlerContext ctx, final Object msg) {
+ public void channelRead(final ChannelHandlerContext ctx, final Object msg) {
LOG.debug("Writing to client {}", msg);
clientChannel.write(msg);
}
@Override
- public void channelReadComplete(ChannelHandlerContext ctx) {
+ public void channelReadComplete(final ChannelHandlerContext ctx) {
LOG.debug("flushing");
clientChannel.flush();
}
@Override
- public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
+ public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
// Close the connection when an exception is raised.
LOG.warn("Unexpected exception from downstream.", cause);
ctx.close();
* 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.ssh.authentication;
+package org.opendaylight.netconf.ssh;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import org.opendaylight.netconf.shaded.sshd.client.future.ConnectFuture;
import org.opendaylight.netconf.shaded.sshd.client.session.ClientSession;
import org.opendaylight.netconf.shaded.sshd.common.util.security.SecurityUtils;
-import org.opendaylight.netconf.ssh.SshProxyServer;
-import org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder;
import org.opendaylight.netconf.util.NetconfConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* 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;
+package org.opendaylight.netconf.ssh;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.opendaylight.netconf.netty.EchoClientHandler.State;
import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPasswordHandler;
import org.opendaylight.netconf.nettyutil.handler.ssh.client.AsyncSshHandler;
import org.opendaylight.netconf.shaded.sshd.common.util.security.SecurityUtils;
-import org.opendaylight.netconf.ssh.SshProxyServer;
-import org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder;
+import org.opendaylight.netconf.ssh.EchoClientHandler.State;
import org.opendaylight.netconf.util.NetconfConfiguration;
public class SSHTest {