*/
@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));
}