Top Description Inners Fields Constructors Methods
io.netty.handler.proxy

public abstract Class ProxyHandler

extends ChannelDuplexHandler
Class Inheritance
Known Direct Subclasses
io.netty.handler.proxy.Socks4ProxyHandler, io.netty.handler.proxy.Socks5ProxyHandler, io.netty.handler.proxy.HttpProxyHandler
Imports
io.netty.channel.Channel, .ChannelDuplexHandler, .ChannelFuture, .ChannelFutureListener, .ChannelHandlerContext, .ChannelPromise, .PendingWriteQueue, io.netty.util.ReferenceCountUtil, io.netty.util.concurrent.DefaultPromise, .EventExecutor, .Future, io.netty.util.internal.ObjectUtil, io.netty.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.net.SocketAddress, java.nio.channels.ConnectionPendingException, java.util.concurrent.TimeUnit

A common abstraction for protocols that establish blind forwarding proxy tunnels.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
pack-priv static final String
AUTH_NONE

A string that signifies 'no authentication' or 'anonymous'.

private final ProxyHandler.LazyChannelPromise
private Future<?>
private volatile long
private volatile ChannelHandlerContext
private static final long
DEFAULT_CONNECT_TIMEOUT_MILLIS

The default connect timeout: 10 seconds.

private volatile SocketAddress
private boolean
private boolean
private static final InternalLogger
private PendingWriteQueue
private final SocketAddress
private boolean
private final ChannelFutureListener

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected abstract void
addCodec(ChannelHandlerContext ctx)

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

private void
public abstract String
authScheme()

Returns the name of the authentication scheme in use.

private void
public final void
public final void
public final void
public final void
public final void
connect(ChannelHandlerContext
the ChannelHandlerContext for which the connect operation is made
ctx
,
SocketAddress
the SocketAddress to which it should connect
remoteAddress
,
SocketAddress
the SocketAddress which is used as source on connect
localAddress
,
ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Overrides io.netty.channel.ChannelDuplexHandler.connect.

Implements io.netty.channel.ChannelOutboundHandler.connect.

Calls ChannelHandlerContext#connect(SocketAddress, SocketAddress, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
public final Future<Channel>
connectFuture()

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

public final long
connectTimeoutMillis()

Returns the connect timeout in millis.

public final <T extends SocketAddress> T
destinationAddress()

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

public final void
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.

private void
private void
public final void
public final void
handlerAdded(ChannelHandlerContext ctx)

Overrides io.netty.channel.ChannelHandlerAdapter.handlerAdded.

Implements io.netty.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.
protected abstract boolean

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
handleResponse
(ChannelHandlerContext ctx, Object response)

Handles the message received from the proxy server.

public final boolean
isConnected()

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

protected abstract Object

Returns:

the initial message, or null if the proxy server is expected to send the first message instead
newInitialMessage
(ChannelHandlerContext ctx)

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

public abstract String
protocol()

Returns the name of the proxy protocol in use.

public final <T extends SocketAddress> T
proxyAddress()

Returns the address of the proxy server.

private static void
protected abstract void
protected abstract void
private boolean
private boolean
private void
sendInitialMessage(final ChannelHandlerContext ctx)

Sends the initial message to be sent to the proxy server.

protected final void
sendToProxyServer(Object msg)

Sends the specified message to the proxy server.

private void
private void
public final void
setConnectTimeoutMillis(long connectTimeoutMillis)

Sets the connect timeout in millis.

public final void
write(ChannelHandlerContext
the ChannelHandlerContext for which the write operation is made
ctx
,
Object
the message to write
msg
,
ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Overrides io.netty.channel.ChannelDuplexHandler.write.

Implements io.netty.channel.ChannelOutboundHandler.write.

Calls ChannelHandlerContext#write(Object, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
private void
Inherited from io.netty.channel.ChannelDuplexHandler:
bindclosederegisterdisconnectread

Field Detail

AUTH_NONEback to summary
pack-priv static final String AUTH_NONE

A string that signifies 'no authentication' or 'anonymous'.

connectPromiseback to summary
private final ProxyHandler.LazyChannelPromise connectPromise
connectTimeoutFutureback to summary
private Future<?> connectTimeoutFuture
connectTimeoutMillisback to summary
private volatile long connectTimeoutMillis
ctxback to summary
private volatile ChannelHandlerContext ctx
DEFAULT_CONNECT_TIMEOUT_MILLISback to summary
private static final long DEFAULT_CONNECT_TIMEOUT_MILLIS

The default connect timeout: 10 seconds.

destinationAddressback to summary
private volatile SocketAddress destinationAddress
finishedback to summary
private boolean finished
flushedPrematurelyback to summary
private boolean flushedPrematurely
loggerback to summary
private static final InternalLogger logger
pendingWritesback to summary
private PendingWriteQueue pendingWrites
proxyAddressback to summary
private final SocketAddress proxyAddress
suppressChannelReadCompleteback to summary
private boolean suppressChannelReadComplete
writeListenerback to summary
private final ChannelFutureListener writeListener

Constructor Detail

ProxyHandlerback to summary
protected ProxyHandler(SocketAddress proxyAddress)

Method Detail

addCodecback to summary
protected abstract void addCodec(ChannelHandlerContext ctx) throws Exception

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

addPendingWriteback to summary
private void addPendingWrite(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
authSchemeback to summary
public abstract String authScheme()

Returns the name of the authentication scheme in use.

cancelConnectTimeoutFutureback to summary
private void cancelConnectTimeoutFuture()
channelActiveback to summary
public final void channelActive(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelActive.

Implements io.netty.channel.ChannelInboundHandler.channelActive.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelActive.

Calls ChannelHandlerContext#fireChannelActive() to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Annotations
@Override
channelInactiveback to summary
public final void channelInactive(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelInactive.

Implements io.netty.channel.ChannelInboundHandler.channelInactive.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelInactive.

Calls ChannelHandlerContext#fireChannelInactive() to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Annotations
@Override
channelReadback to summary
public final void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelRead.

Implements io.netty.channel.ChannelInboundHandler.channelRead.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelRead.

Calls ChannelHandlerContext#fireChannelRead(Object) to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Annotations
@Override
channelReadCompleteback to summary
public final void channelReadComplete(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelReadComplete.

Implements io.netty.channel.ChannelInboundHandler.channelReadComplete.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelReadComplete.

Calls ChannelHandlerContext#fireChannelReadComplete() to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Annotations
@Override
connectback to summary
public final void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception

Overrides io.netty.channel.ChannelDuplexHandler.connect.

Implements io.netty.channel.ChannelOutboundHandler.connect.

Doc from io.netty.channel.ChannelDuplexHandler.connect.

Calls ChannelHandlerContext#connect(SocketAddress, SocketAddress, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.channel.ChannelOutboundHandler.connect.

the ChannelHandlerContext for which the connect operation is made

remoteAddress:SocketAddress

Doc from io.netty.channel.ChannelOutboundHandler.connect.

the SocketAddress to which it should connect

localAddress:SocketAddress

Doc from io.netty.channel.ChannelOutboundHandler.connect.

the SocketAddress which is used as source on connect

promise:ChannelPromise

Doc from io.netty.channel.ChannelOutboundHandler.connect.

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:

Doc from io.netty.channel.ChannelOutboundHandler.connect.

thrown if an error occurs

connectFutureback to summary
public final Future<Channel> connectFuture()

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

connectTimeoutMillisback to summary
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.

destinationAddressback to summary
public final <T extends SocketAddress> T destinationAddress()

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

Annotations
@SuppressWarnings:unchecked
exceptionCaughtback to summary
public final void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception

Overrides io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught.

Implements io.netty.channel.ChannelHandler.exceptionCaught, io.netty.channel.ChannelInboundHandler.exceptionCaught.

Doc from io.netty.channel.ChannelHandler.exceptionCaught.

Gets called if a Throwable was thrown.

Annotations
@Override
exceptionMessageback to summary
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.

failPendingWritesback to summary
private void failPendingWrites(Throwable cause)
failPendingWritesAndCloseback to summary
private void failPendingWritesAndClose(Throwable cause)
flushback to summary
public final void flush(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelDuplexHandler.flush.

Implements io.netty.channel.ChannelOutboundHandler.flush.

Doc from io.netty.channel.ChannelDuplexHandler.flush.

Calls ChannelHandlerContext#flush() to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.channel.ChannelOutboundHandler.flush.

the ChannelHandlerContext for which the flush operation is made

Annotations
@Override
Exceptions
Exception:

Doc from io.netty.channel.ChannelOutboundHandler.flush.

thrown if an error occurs

handlerAddedback to summary
public final void handlerAdded(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelHandlerAdapter.handlerAdded.

Implements io.netty.channel.ChannelHandler.handlerAdded.

Doc from io.netty.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.

Annotations
@Override
handleResponseback to summary
protected abstract boolean handleResponse(ChannelHandlerContext ctx, Object response) throws Exception

Handles the message received from the proxy server.

Returns:boolean

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

isConnectedback to summary
public final boolean isConnected()

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

newInitialMessageback to summary
protected abstract Object newInitialMessage(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:Object

the initial message, or null if the proxy server is expected to send the first message instead

protocolback to summary
public abstract String protocol()

Returns the name of the proxy protocol in use.

proxyAddressback to summary
public final <T extends SocketAddress> T proxyAddress()

Returns the address of the proxy server.

Annotations
@SuppressWarnings:unchecked
readIfNeededback to summary
private static void readIfNeeded(ChannelHandlerContext ctx)
removeDecoderback to summary
protected abstract void removeDecoder(ChannelHandlerContext ctx) throws Exception

Removes the decoders added in addCodec(ChannelHandlerContext).

removeEncoderback to summary
protected abstract void removeEncoder(ChannelHandlerContext ctx) throws Exception

Removes the encoders added in addCodec(ChannelHandlerContext).

safeRemoveDecoderback to summary
private boolean safeRemoveDecoder()
safeRemoveEncoderback to summary
private boolean safeRemoveEncoder()
sendInitialMessageback to summary
private void sendInitialMessage(final ChannelHandlerContext ctx) throws Exception

Sends the initial message to be sent to the proxy server. This method also starts a timeout task which marks the connectPromise as failure if the connection attempt does not success within the timeout.

sendToProxyServerback to summary
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).

setConnectFailureback to summary
private void setConnectFailure(Throwable cause)
setConnectSuccessback to summary
private void setConnectSuccess()
setConnectTimeoutMillisback to summary
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.

writeback to summary
public final void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception

Overrides io.netty.channel.ChannelDuplexHandler.write.

Implements io.netty.channel.ChannelOutboundHandler.write.

Doc from io.netty.channel.ChannelDuplexHandler.write.

Calls ChannelHandlerContext#write(Object, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.channel.ChannelOutboundHandler.write.

the ChannelHandlerContext for which the write operation is made

msg:Object

Doc from io.netty.channel.ChannelOutboundHandler.write.

the message to write

promise:ChannelPromise

Doc from io.netty.channel.ChannelOutboundHandler.write.

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:

Doc from io.netty.channel.ChannelOutboundHandler.write.

thrown if an error occurs

writePendingWritesback to summary
private void writePendingWrites()
io.netty.handler.proxy back to summary

private final Class ProxyHandler.LazyChannelPromise

extends DefaultPromise<Channel>
Class Inheritance

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected EventExecutor
executor()

Overrides io.netty.util.concurrent.DefaultPromise.executor.

Get the executor used to notify listeners when this promise is complete.
Inherited from io.netty.util.concurrent.DefaultPromise:
addListeneraddListenersawaitawaitawaitawaitUninterruptiblyawaitUninterruptiblyawaitUninterruptiblycancelcausecheckDeadLockgetgetgetNowisCancellableisCancelledisDoneisSuccessnotifyListenerremoveListenerremoveListenerssetFailuresetSuccesssetUncancellablesyncsyncUninterruptiblytoStringtoStringBuildertryFailuretrySuccess

Constructor Detail

LazyChannelPromiseback to summary
private LazyChannelPromise()

Method Detail

executorback to summary
protected EventExecutor executor()

Overrides io.netty.util.concurrent.DefaultPromise.executor.

Doc from io.netty.util.concurrent.DefaultPromise.executor.

Get the executor used to notify listeners when this promise is complete.

It is assumed this executor will protect against StackOverflowError exceptions. The executor may be used to avoid StackOverflowError by executing a Runnable if the stack depth exceeds a threshold.

Returns:EventExecutor

The executor used to notify listeners when this promise is complete.

Annotations
@Override