Source:
public void sessionCreated(IoSession session) throws Exception { boolean isClient = session.getRemoteAddress().equals(forward); if (log.isDebugEnabled()) { log.debug("Is downstream: " + isClient); session.getFilterChain().addFirst("protocol", new ProtocolCodecFilter(codecFactory)); } session.getFilterChain().addFirst("proxy", new ProxyFilter(isClient ? "client" : "server")); String fileName = System.currentTimeMillis() + '_' + forward.getHostName() + '_' + forward.getPort() + '_' + (isClient ? "DOWNSTREAM" : "UPSTREAM"); File headersFile = loader.getResource(dumpTo + fileName + ".cap").getFile(); headersFile.createNewFile(); File rawFile = loader.getResource(dumpTo + fileName + ".raw").getFile(); rawFile.createNewFile(); FileOutputStream headersFos = new FileOutputStream(headersFile); FileOutputStream rawFos = new FileOutputStream(rawFile); try { WritableByteChannel headers = headersFos.getChannel(); WritableByteChannel raw = rawFos.getChannel(); IoBuffer header = IoBuffer.allocate(1); header.put((byte) (isClient ? 0x00 : 0x01)); header.flip(); headers.write(header.buf()); session.getFilterChain().addFirst("dump", new NetworkDumpFilter(headers, raw)); } finally { headersFos.close(); rawFos.close(); } if (!isClient) { log.debug("Connecting.."); IoConnector connector = new NioSocketConnector(); connector.setHandler(this); ConnectFuture future = connector.connect(forward); future.awaitUninterruptibly(); if (future.isConnected()) { if (log.isDebugEnabled()) { log.debug("Connected: {}", forward); } IoSession client = future.getSession(); client.setAttribute(ProxyFilter.FORWARD_KEY, session); session.setAttribute(ProxyFilter.FORWARD_KEY, client); } } super.sessionCreated(session); }

Target:
public void sessionCreated(IoSession session) throws Exception { boolean isClient = session.getRemoteAddress().equals(forward); if (log.isDebugEnabled()) { log.debug("Is downstream: " + isClient); session.getFilterChain().addFirst("protocol", new ProtocolCodecFilter(codecFactory)); } session.getFilterChain().addFirst("proxy", new ProxyFilter(isClient ? "client" : "server")); String fileName = System.currentTimeMillis() + '_' + forward.getHostName() + '_' + forward.getPort() + '_' + (isClient ? "DOWNSTREAM" : "UPSTREAM"); File headersFile = loader.getResource(dumpTo + fileName + ".cap").getFile(); headersFile.createNewFile(); File rawFile = loader.getResource(dumpTo + fileName + ".raw").getFile(); rawFile.createNewFile(); try (FileOutputStream headersFos = new FileOutputStream(headersFile); FileOutputStream rawFos = new FileOutputStream(rawFile)) { WritableByteChannel headers = headersFos.getChannel(); WritableByteChannel raw = rawFos.getChannel(); IoBuffer header = IoBuffer.allocate(1); header.put((byte) (isClient ? 0x00 : 0x01)); header.flip(); headers.write(header.buf()); session.getFilterChain().addFirst("dump", new NetworkDumpFilter(headers, raw)); } finally { headersFos.close(); rawFos.close(); } if (!isClient) { log.debug("Connecting.."); IoConnector connector = new NioSocketConnector(); connector.setHandler(this); ConnectFuture future = connector.connect(forward); future.awaitUninterruptibly(); if (future.isConnected()) { if (log.isDebugEnabled()) { log.debug("Connected: {}", forward); } IoSession client = future.getSession(); client.setAttribute(ProxyFilter.FORWARD_KEY, session); session.setAttribute(ProxyFilter.FORWARD_KEY, client); } } super.sessionCreated(session); }