io.netty.handler.proxy

## Class ProxyHandler

- java.lang.Object
- - io.netty.channel.ChannelHandlerAdapter
  - - io.netty.channel.ChannelInboundHandlerAdapter
    - - io.netty.channel.ChannelDuplexHandler
      - - io.netty.handler.proxy.ProxyHandler

All Implemented Interfaces:
  io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, io.netty.channel.ChannelOutboundHandler

Direct Known Subclasses:
  HttpProxyHandler, Socks4ProxyHandler, Socks5ProxyHandler

    public abstract class ProxyHandler
    extends io.netty.channel.ChannelDuplexHandler

### Nested Class Summary

### Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

`io.netty.channel.ChannelHandler.Sharable`

### Constructor Summary

Constructors
`protected` `ProxyHandler(SocketAddress proxyAddress)`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`protected abstract void` `addCodec(io.netty.channel.ChannelHandlerContext ctx)` Adds the codec handlers required to communicate with the proxy server.
`abstract String` `authScheme()` Returns the name of the authentication scheme in use.
`void` `channelActive(io.netty.channel.ChannelHandlerContext ctx)`
`void` `channelInactive(io.netty.channel.ChannelHandlerContext ctx)`
`void` `channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)`
`void` `channelReadComplete(io.netty.channel.ChannelHandlerContext ctx)`
`void` `connect(io.netty.channel.ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, io.netty.channel.ChannelPromise promise)`
`io.netty.util.concurrent.Future<io.netty.channel.Channel>` `connectFuture()` Returns a `Future` that is notified when the connection to the destination has been established or the connection attempt has failed.
`long` `connectTimeoutMillis()` Returns the connect timeout in millis.
`<T extends SocketAddress> T` `destinationAddress()` Returns the address of the destination to connect to via the proxy server.
`void` `exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)`
`protected String` `exceptionMessage(String msg)` Decorates the specified exception message with the common information such as the current protocol, authentication scheme, proxy address, and destination address.
`void` `flush(io.netty.channel.ChannelHandlerContext ctx)`
`void` `handlerAdded(io.netty.channel.ChannelHandlerContext ctx)`
`protected abstract boolean` `handleResponse(io.netty.channel.ChannelHandlerContext ctx, Object response)` Handles the message received from the proxy server.
`boolean` `isConnected()` Returns `true` if and only if the connection to the destination has been established successfully.
`protected abstract Object` `newInitialMessage(io.netty.channel.ChannelHandlerContext ctx)` Returns a new message that is sent at first time when the connection to the proxy server has been established.
`abstract String` `protocol()` Returns the name of the proxy protocol in use.
`<T extends SocketAddress> T` `proxyAddress()` Returns the address of the proxy server.
`protected abstract void` `removeDecoder(io.netty.channel.ChannelHandlerContext ctx)` Removes the decoders added in `addCodec(ChannelHandlerContext)`.
`protected abstract void` `removeEncoder(io.netty.channel.ChannelHandlerContext ctx)` Removes the encoders added in `addCodec(ChannelHandlerContext)`.
`protected void` `sendToProxyServer(Object msg)` Sends the specified message to the proxy server.
`void` `setConnectTimeoutMillis(long connectTimeoutMillis)` Sets the connect timeout in millis.
`void` `write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise)`

### Methods inherited from class io.netty.channel.ChannelDuplexHandler

`bind, close, deregister, disconnect, read`

### Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

`channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered`

### Methods inherited from class io.netty.channel.ChannelHandlerAdapter

`ensureNotSharable, handlerRemoved, isSharable`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface io.netty.channel.ChannelHandler

`handlerRemoved`

### Constructor Detail

#### ProxyHandler

    protected ProxyHandler(SocketAddress proxyAddress)

### Method Detail

#### protocol

    public abstract String protocol()

Returns the name of the proxy protocol in use.

#### authScheme

    public abstract String authScheme()

Returns the name of the authentication scheme in use.

#### proxyAddress

    public final <T extends SocketAddress> T proxyAddress()

Returns the address of the proxy server.

#### destinationAddress

    public final <T extends SocketAddress> T destinationAddress()

Returns the address of the destination to connect to via the proxy server.

#### isConnected

    public final boolean isConnected()

Returns `true` if and only if the connection to the destination has been established successfully.

#### connectFuture

    public final io.netty.util.concurrent.Future<io.netty.channel.Channel> connectFuture()

Returns a `Future` that is notified when the connection to the destination has been established or the connection attempt has failed.

#### connectTimeoutMillis

    public final long connectTimeoutMillis()

Returns the connect timeout in millis. If the connection attempt to the destination does not finish within the timeout, the connection attempt will be failed.

#### setConnectTimeoutMillis

    public final void setConnectTimeoutMillis(long connectTimeoutMillis)

Sets the connect timeout in millis. If the connection attempt to the destination does not finish within the timeout, the connection attempt will be failed.

#### handlerAdded

    public final void handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
                            throws Exception

Specified by:
  `handlerAdded` in interface `io.netty.channel.ChannelHandler`
Overrides:
  `handlerAdded` in class `io.netty.channel.ChannelHandlerAdapter`
Throws:
  `Exception`

#### addCodec

    protected abstract void addCodec(io.netty.channel.ChannelHandlerContext ctx)
                              throws Exception

Adds the codec handlers required to communicate with the proxy server.

Throws:
  `Exception`

#### removeEncoder

    protected abstract void removeEncoder(io.netty.channel.ChannelHandlerContext ctx)
                                   throws Exception

Removes the encoders added in `addCodec(ChannelHandlerContext)`.

Throws:
  `Exception`

#### removeDecoder

    protected abstract void removeDecoder(io.netty.channel.ChannelHandlerContext ctx)
                                   throws Exception

Removes the decoders added in `addCodec(ChannelHandlerContext)`.

Throws:
  `Exception`

#### connect

    public final void connect(io.netty.channel.ChannelHandlerContext ctx,
                              SocketAddress remoteAddress,
                              SocketAddress localAddress,
                              io.netty.channel.ChannelPromise promise)
                       throws Exception

Specified by:
  `connect` in interface `io.netty.channel.ChannelOutboundHandler`
Overrides:
  `connect` in class `io.netty.channel.ChannelDuplexHandler`
Throws:
  `Exception`

#### channelActive

    public final void channelActive(io.netty.channel.ChannelHandlerContext ctx)
                             throws Exception

Specified by:
  `channelActive` in interface `io.netty.channel.ChannelInboundHandler`
Overrides:
  `channelActive` in class `io.netty.channel.ChannelInboundHandlerAdapter`
Throws:
  `Exception`

#### newInitialMessage

    protected abstract Object newInitialMessage(io.netty.channel.ChannelHandlerContext ctx)
                                         throws Exception

Returns a new message that is sent at first time when the connection to the proxy server has been established.

Returns:
  the initial message, or `null` if the proxy server is expected to send the first message instead
Throws:
  `Exception`

#### sendToProxyServer

    protected final void sendToProxyServer(Object msg)

Sends the specified message to the proxy server. Use this method to send a response to the proxy server in `handleResponse(ChannelHandlerContext, Object)`.

#### channelInactive

    public final void channelInactive(io.netty.channel.ChannelHandlerContext ctx)
                               throws Exception

Specified by:
  `channelInactive` in interface `io.netty.channel.ChannelInboundHandler`
Overrides:
  `channelInactive` in class `io.netty.channel.ChannelInboundHandlerAdapter`
Throws:
  `Exception`

#### exceptionCaught

    public final void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx,
                                      Throwable cause)
                               throws Exception

Specified by:
  `exceptionCaught` in interface `io.netty.channel.ChannelHandler`
Specified by:
  `exceptionCaught` in interface `io.netty.channel.ChannelInboundHandler`
Overrides:
  `exceptionCaught` in class `io.netty.channel.ChannelInboundHandlerAdapter`
Throws:
  `Exception`

#### channelRead

    public final void channelRead(io.netty.channel.ChannelHandlerContext ctx,
                                  Object msg)
                           throws Exception

Specified by:
  `channelRead` in interface `io.netty.channel.ChannelInboundHandler`
Overrides:
  `channelRead` in class `io.netty.channel.ChannelInboundHandlerAdapter`
Throws:
  `Exception`

#### handleResponse

    protected abstract boolean handleResponse(io.netty.channel.ChannelHandlerContext ctx,
                                              Object response)
                                       throws Exception

Handles the message received from the proxy server.

Returns:
  `true` if the connection to the destination has been established, `false` if the connection to the destination has not been established and more messages are expected from the proxy server
Throws:
  `Exception`

#### exceptionMessage

    protected final String exceptionMessage(String msg)

Decorates the specified exception message with the common information such as the current protocol, authentication scheme, proxy address, and destination address.

#### channelReadComplete

    public final void channelReadComplete(io.netty.channel.ChannelHandlerContext ctx)
                                   throws Exception

Specified by:
  `channelReadComplete` in interface `io.netty.channel.ChannelInboundHandler`
Overrides:
  `channelReadComplete` in class `io.netty.channel.ChannelInboundHandlerAdapter`
Throws:
  `Exception`

#### write

    public final void write(io.netty.channel.ChannelHandlerContext ctx,
                            Object msg,
                            io.netty.channel.ChannelPromise promise)
                     throws Exception

Specified by:
  `write` in interface `io.netty.channel.ChannelOutboundHandler`
Overrides:
  `write` in class `io.netty.channel.ChannelDuplexHandler`
Throws:
  `Exception`

#### flush

    public final void flush(io.netty.channel.ChannelHandlerContext ctx)
                     throws Exception

Specified by:
  `flush` in interface `io.netty.channel.ChannelOutboundHandler`
Overrides:
  `flush` in class `io.netty.channel.ChannelDuplexHandler`
Throws:
  `Exception`