code: @Override
      public void sessionCreated(NextFilter nextFilter, IoSession session)
              throws Exception {
          LOGGER.debug("Session created: " + session);
          ProxyIoSession proxyIoSession = (ProxyIoSession) session
                  .getAttribute(ProxyIoSession.PROXY_SESSION);
          LOGGER.debug("  get proxyIoSession: " + proxyIoSession);
          proxyIoSession.setProxyFilter(this);
  
          // Create a HTTP proxy handler and start handshake.
          ProxyLogicHandler handler = proxyIoSession.getHandler();
  
          // This test prevents from loosing handler conversationnal state when
          // reconnection occurs during an http handshake.
          if (handler == null) {
              ProxyRequest request = proxyIoSession.getRequest();
  
              if (request instanceof SocksProxyRequest) {
                  SocksProxyRequest req = (SocksProxyRequest) request;
                  if (req.getProtocolVersion() == SocksProxyConstants.SOCKS_VERSION_4) {
                      handler = new Socks4LogicHandler(proxyIoSession);
                  } else {
                      handler = new Socks5LogicHandler(proxyIoSession);
                  }
              } else {
                  handler = new HttpSmartProxyHandler(proxyIoSession);
              }
  
              proxyIoSession.setHandler(handler);
              handler.doHandshake(nextFilter);
          }
  
          proxyIoSession.getEventQueue().enqueueEventIfNecessary(
                  new IoSessionEvent(nextFilter, session,
                          IoSessionEventType.CREATED));
      }
docs: Called when the session is created. Will create the handler able to handle
  the {@link ProxyIoSession#getRequest()} request stored in the session. Event
  is stored in an {@link IoSessionEventQueue} for later delivery to the next filter
  in the chain when the handshake would have succeed. This will prevent the rest of
  the filter chain from being affected by this filter internals.
  
  Please note that this event can occur multiple times because of some http
  proxies not handling keep-alive connections thus needing multiple sessions
  during the handshake.
  
  @param nextFilter the next filter in filter chain
  @param session the session object