Top Description Inners Fields Constructors Methods
io.netty.handler.codec.http

public Class HttpClientUpgradeHandler

extends HttpObjectAggregator
implements ChannelOutboundHandler
Class Inheritance
All Implemented Interfaces
io.netty.channel.ChannelOutboundHandler, io.netty.channel.ChannelHandler
Imports
io.netty.channel.ChannelHandlerContext, .ChannelOutboundHandler, .ChannelPromise, io.netty.util.AsciiString, io.netty.util.internal.ObjectUtil, java.net.SocketAddress, java.util.Collection, .LinkedHashSet, .List, .Set

Client-side handler for handling an HTTP upgrade handshake to another protocol. When the first HTTP request is sent, this handler will add all appropriate headers to perform an upgrade to the new protocol. If the upgrade fails (i.e. response is not 101 Switching Protocols), this handler simply removes itself from the pipeline. If the upgrade is successful, upgrades the pipeline to the new protocol.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
HttpClientUpgradeHandler.SourceCodec

The source codec that is used in the pipeline initially.

public static interface
HttpClientUpgradeHandler.UpgradeCodec

A codec that the source can be upgraded to.

public static enum
HttpClientUpgradeHandler.UpgradeEvent

User events that are fired to notify about upgrade status.

Field Summary

Modifier and TypeField and Description
private final HttpClientUpgradeHandler.SourceCodec
private final HttpClientUpgradeHandler.UpgradeCodec
private boolean

Constructor Summary

AccessConstructor and Description
public
HttpClientUpgradeHandler(HttpClientUpgradeHandler.SourceCodec
the codec that is being used initially.
sourceCodec
,
HttpClientUpgradeHandler.UpgradeCodec
the codec that the client would like to upgrade to.
upgradeCodec
,
int
the maximum length of the aggregated content.
maxContentLength
)

Constructs the client upgrade handler.

Method Summary

Modifier and TypeMethod and Description
public void
bind(ChannelHandlerContext
the ChannelHandlerContext for which the bind operation is made
ctx
,
SocketAddress
the SocketAddress to which it should bound
localAddress
,
ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Implements io.netty.channel.ChannelOutboundHandler.bind.

Called once a bind operation is made.
public void
close(ChannelHandlerContext
the ChannelHandlerContext for which the close operation is made
ctx
,
ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Implements io.netty.channel.ChannelOutboundHandler.close.

Called once a close operation is made.
public 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
)

Implements io.netty.channel.ChannelOutboundHandler.connect.

Called once a connect operation is made.
protected void
decode(ChannelHandlerContext ctx, HttpObject
the message to decode to an other one
msg
,
List<Object>
the List to which decoded messages should be added
out
)

Overrides io.netty.handler.codec.MessageAggregator.decode.

Decode from one message to an other.
public void
deregister(ChannelHandlerContext
the ChannelHandlerContext for which the close operation is made
ctx
,
ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Implements io.netty.channel.ChannelOutboundHandler.deregister.

Called once a deregister operation is made from the current registered EventLoop.
public void
disconnect(ChannelHandlerContext
the ChannelHandlerContext for which the disconnect operation is made
ctx
,
ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Implements io.netty.channel.ChannelOutboundHandler.disconnect.

Called once a disconnect operation is made.
public void
flush(ChannelHandlerContext
the ChannelHandlerContext for which the flush operation is made
ctx
)

Implements io.netty.channel.ChannelOutboundHandler.flush.

Called once a flush operation is made.
public void
private static void
private void
setUpgradeRequestHeaders(ChannelHandlerContext ctx, HttpRequest request)

Adds all upgrade request headers necessary for an upgrade to the supported protocols.

public 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
)

Implements io.netty.channel.ChannelOutboundHandler.write.

Called once a write operation is made.
Inherited from io.netty.handler.codec.http.HttpObjectAggregator:
aggregatebeginAggregationcloseAfterContinueResponsefinishAggregationhandleOversizedMessageignoreContentAfterContinueResponseisAggregatedisContentLengthInvalidisContentMessageisLastContentMessageisStartMessagenewContinueResponse

Field Detail

sourceCodecback to summary
private final HttpClientUpgradeHandler.SourceCodec sourceCodec
upgradeCodecback to summary
private final HttpClientUpgradeHandler.UpgradeCodec upgradeCodec
upgradeRequestedback to summary
private boolean upgradeRequested

Constructor Detail

HttpClientUpgradeHandlerback to summary
public HttpClientUpgradeHandler(HttpClientUpgradeHandler.SourceCodec sourceCodec, HttpClientUpgradeHandler.UpgradeCodec upgradeCodec, int maxContentLength)

Constructs the client upgrade handler.

Parameters
sourceCodec:HttpClientUpgradeHandler.SourceCodec

the codec that is being used initially.

upgradeCodec:HttpClientUpgradeHandler.UpgradeCodec

the codec that the client would like to upgrade to.

maxContentLength:int

the maximum length of the aggregated content.

Method Detail

bindback to summary
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception

Implements io.netty.channel.ChannelOutboundHandler.bind.

Doc from io.netty.channel.ChannelOutboundHandler.bind.

Called once a bind operation is made.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the bind operation is made

localAddress:SocketAddress

the SocketAddress to which it should bound

promise:ChannelPromise

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:
thrown if an error occurs
closeback to summary
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception

Implements io.netty.channel.ChannelOutboundHandler.close.

Doc from io.netty.channel.ChannelOutboundHandler.close.

Called once a close operation is made.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the close operation is made

promise:ChannelPromise

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:
thrown if an error occurs
connectback to summary
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception

Implements io.netty.channel.ChannelOutboundHandler.connect.

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

Called once a connect operation is made.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the connect operation is made

remoteAddress:SocketAddress

the SocketAddress to which it should connect

localAddress:SocketAddress

the SocketAddress which is used as source on connect

promise:ChannelPromise

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:
thrown if an error occurs
decodeback to summary
protected void decode(ChannelHandlerContext ctx, HttpObject msg, List<Object> out) throws Exception

Overrides io.netty.handler.codec.MessageAggregator.decode.

Doc from io.netty.handler.codec.MessageToMessageDecoder.decode.

Decode from one message to an other. This method will be called for each written message that can be handled by this decoder.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this MessageToMessageDecoder belongs to

msg:HttpObject

the message to decode to an other one

out:List<Object>

the List to which decoded messages should be added

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs
deregisterback to summary
public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception

Implements io.netty.channel.ChannelOutboundHandler.deregister.

Doc from io.netty.channel.ChannelOutboundHandler.deregister.

Called once a deregister operation is made from the current registered EventLoop.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the close operation is made

promise:ChannelPromise

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:
thrown if an error occurs
disconnectback to summary
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception

Implements io.netty.channel.ChannelOutboundHandler.disconnect.

Doc from io.netty.channel.ChannelOutboundHandler.disconnect.

Called once a disconnect operation is made.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the disconnect operation is made

promise:ChannelPromise

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:
thrown if an error occurs
flushback to summary
public void flush(ChannelHandlerContext ctx) throws Exception

Implements io.netty.channel.ChannelOutboundHandler.flush.

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

Called once a flush operation is made. The flush operation will try to flush out all previous written messages that are pending.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the flush operation is made

Annotations
@Override
Exceptions
Exception:
thrown if an error occurs
readback to summary
public void read(ChannelHandlerContext ctx) throws Exception

Implements io.netty.channel.ChannelOutboundHandler.read.

Doc from io.netty.channel.ChannelOutboundHandler.read.

Intercepts ChannelHandlerContext#read().

Annotations
@Override
removeThisHandlerback to summary
private static void removeThisHandler(ChannelHandlerContext ctx)
setUpgradeRequestHeadersback to summary
private void setUpgradeRequestHeaders(ChannelHandlerContext ctx, HttpRequest request)

Adds all upgrade request headers necessary for an upgrade to the supported protocols.

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

Implements io.netty.channel.ChannelOutboundHandler.write.

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

Called once a write operation is made. The write operation will write the messages through the ChannelPipeline. Those are then ready to be flushed to the actual Channel once Channel#flush() is called

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the write operation is made

msg:Object

the message to write

promise:ChannelPromise

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:
thrown if an error occurs
io.netty.handler.codec.http back to summary

public Interface HttpClientUpgradeHandler.SourceCodec

Known Direct Implementers
io.netty.handler.codec.http.HttpClientCodec

The source codec that is used in the pipeline initially.

Method Summary

Modifier and TypeMethod and Description
public void
prepareUpgradeFrom(ChannelHandlerContext ctx)

Removes or disables the encoder of this codec so that the UpgradeCodec can send an initial greeting (if any).

public void
upgradeFrom(ChannelHandlerContext ctx)

Removes this codec (i.e. all associated handlers) from the pipeline.

Method Detail

prepareUpgradeFromback to summary
public void prepareUpgradeFrom(ChannelHandlerContext ctx)

Removes or disables the encoder of this codec so that the UpgradeCodec can send an initial greeting (if any).

upgradeFromback to summary
public void upgradeFrom(ChannelHandlerContext ctx)

Removes this codec (i.e. all associated handlers) from the pipeline.

io.netty.handler.codec.http back to summary

public Interface HttpClientUpgradeHandler.UpgradeCodec


A codec that the source can be upgraded to.

Method Summary

Modifier and TypeMethod and Description
public CharSequence
protocol()

Returns the name of the protocol supported by this codec, as indicated by the 'UPGRADE' header.

public Collection<CharSequence>
setUpgradeHeaders(ChannelHandlerContext ctx, HttpRequest upgradeRequest)

Sets any protocol-specific headers required to the upgrade request.

public void
upgradeTo(ChannelHandlerContext
the context for the current handler.
ctx
,
FullHttpResponse
the 101 Switching Protocols response that indicates that the server has switched to this protocol.
upgradeResponse
)

Performs an HTTP protocol upgrade from the source codec.

Method Detail

protocolback to summary
public CharSequence protocol()

Returns the name of the protocol supported by this codec, as indicated by the 'UPGRADE' header.

setUpgradeHeadersback to summary
public Collection<CharSequence> setUpgradeHeaders(ChannelHandlerContext ctx, HttpRequest upgradeRequest)

Sets any protocol-specific headers required to the upgrade request. Returns the names of all headers that were added. These headers will be used to populate the CONNECTION header.

upgradeToback to summary
public void upgradeTo(ChannelHandlerContext ctx, FullHttpResponse upgradeResponse) throws Exception

Performs an HTTP protocol upgrade from the source codec. This method is responsible for adding all handlers required for the new protocol.

Parameters
ctx:ChannelHandlerContext

the context for the current handler.

upgradeResponse:FullHttpResponse

the 101 Switching Protocols response that indicates that the server has switched to this protocol.

io.netty.handler.codec.http back to summary

public final Enum HttpClientUpgradeHandler.UpgradeEvent

extends Enum<HttpClientUpgradeHandler.UpgradeEvent>
Class Inheritance

User events that are fired to notify about upgrade status.

Field Summary

Modifier and TypeField and Description
public static final HttpClientUpgradeHandler.UpgradeEvent
UPGRADE_ISSUED

The Upgrade request was sent to the server.

public static final HttpClientUpgradeHandler.UpgradeEvent
UPGRADE_REJECTED

The Upgrade was unsuccessful due to the server not issuing with a 101 Switching Protocols response.

public static final HttpClientUpgradeHandler.UpgradeEvent
UPGRADE_SUCCESSFUL

The Upgrade to the new protocol was successful.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static HttpClientUpgradeHandler.UpgradeEvent
public static HttpClientUpgradeHandler.UpgradeEvent[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

UPGRADE_ISSUEDback to summary
public static final HttpClientUpgradeHandler.UpgradeEvent UPGRADE_ISSUED

The Upgrade request was sent to the server.

UPGRADE_REJECTEDback to summary
public static final HttpClientUpgradeHandler.UpgradeEvent UPGRADE_REJECTED

The Upgrade was unsuccessful due to the server not issuing with a 101 Switching Protocols response.

UPGRADE_SUCCESSFULback to summary
public static final HttpClientUpgradeHandler.UpgradeEvent UPGRADE_SUCCESSFUL

The Upgrade to the new protocol was successful.

Constructor Detail

UpgradeEventback to summary
private UpgradeEvent()

Method Detail

valueOfback to summary
public static HttpClientUpgradeHandler.UpgradeEvent valueOf(String name)
valuesback to summary
public static HttpClientUpgradeHandler.UpgradeEvent[] values()