Remove netconf-impl's getConfig_candidate.xml
[netconf.git] / netconf / netconf-ssh / src / test / java / org / opendaylight / netconf / netty / ProxyClientHandler.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.netty;
9
10 import io.netty.buffer.ByteBuf;
11 import io.netty.channel.ChannelHandlerContext;
12 import io.netty.channel.ChannelInboundHandlerAdapter;
13 import java.nio.charset.StandardCharsets;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 class ProxyClientHandler extends ChannelInboundHandlerAdapter {
18     private static final Logger LOG = LoggerFactory.getLogger(ProxyClientHandler.class);
19
20     private final ChannelHandlerContext remoteCtx;
21
22
23     ProxyClientHandler(ChannelHandlerContext remoteCtx) {
24         this.remoteCtx = remoteCtx;
25     }
26
27     @Override
28     public void channelActive(ChannelHandlerContext ctx) {
29         LOG.info("client active");
30     }
31
32     @Override
33     public void channelRead(ChannelHandlerContext ctx, Object msg) {
34         ByteBuf bb = (ByteBuf) msg;
35         LOG.info(">{}", bb.toString(StandardCharsets.UTF_8));
36         remoteCtx.write(msg);
37     }
38
39     @Override
40     public void channelReadComplete(ChannelHandlerContext ctx) {
41         LOG.debug("Flushing server ctx");
42         remoteCtx.flush();
43     }
44
45     @Override
46     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
47         // Close the connection when an exception is raised.
48         LOG.warn("Unexpected exception from downstream", cause);
49         ctx.close();
50     }
51
52     // called both when local or remote connection dies
53     @Override
54     public void channelInactive(ChannelHandlerContext ctx) {
55         LOG.debug("channelInactive() called, closing remote client ctx");
56         remoteCtx.close();
57     }
58 }