io.undertow.server

## Class ServerConnection

- java.lang.Object
- - io.undertow.util.AbstractAttachable
  - - io.undertow.server.ServerConnection

All Implemented Interfaces:
  Attachable, Closeable, AutoCloseable, Channel, InterruptibleChannel, org.xnio.channels.BoundChannel, org.xnio.channels.CloseableChannel, org.xnio.channels.Configurable, org.xnio.channels.ConnectedChannel

Direct Known Subclasses:
  AbstractServerConnection, Http2ServerConnection

    public abstract class ServerConnection
    extends AbstractAttachable
    implements org.xnio.channels.ConnectedChannel

A server connection.

Author:
  Stuart Douglas

### Nested Class Summary

Nested Classes
`static interface` `ServerConnection.CloseListener`

### Field Summary

### Fields inherited from interface org.xnio.channels.Configurable

`EMPTY`

### Constructor Summary

Constructors
Constructor and Description
`ServerConnection()`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods
`abstract void` `addCloseListener(ServerConnection.CloseListener listener)` Adds a close listener, than will be invoked with the connection is closed
`abstract void` `close()`
`protected abstract void` `exchangeComplete(HttpServerExchange exchange)` Invoked when the exchange is complete.
`abstract org.xnio.Pool<ByteBuffer>` `getBufferPool()` Deprecated.
`abstract int` `getBufferSize()`
`abstract ByteBufferPool` `getByteBufferPool()`
`abstract org.xnio.XnioIoThread` `getIoThread()`
`abstract SocketAddress` `getLocalAddress()`
`abstract <A extends SocketAddress> A` `getLocalAddress(Class<A> type)`
`abstract <T> T` `getOption(org.xnio.Option<T> option)`
`abstract SocketAddress` `getPeerAddress()` Returns the actual address of the remote connection.
`abstract <A extends SocketAddress> A` `getPeerAddress(Class<A> type)` Returns the actual address of the remote connection.
`protected abstract org.xnio.conduits.ConduitStreamSinkChannel` `getSinkChannel()`
`protected abstract org.xnio.conduits.StreamSinkConduit` `getSinkConduit(HttpServerExchange exchange, org.xnio.conduits.StreamSinkConduit conduit)` Gets the sink conduit that should be used for this request.
`protected abstract org.xnio.conduits.ConduitStreamSourceChannel` `getSourceChannel()`
`SSLSession` `getSslSession()` Gets the SSLSession of the underlying connection, or null if SSL is not in use.
`abstract SSLSessionInfo` `getSslSessionInfo()` Gets SSL information about the connection.
`abstract String` `getTransportProtocol()` Returns a string representation describing the protocol used to transmit messages on this connection.
`abstract org.xnio.OptionMap` `getUndertowOptions()`
`abstract org.xnio.XnioWorker` `getWorker()`
`protected abstract boolean` `isConnectSupported()`
`abstract boolean` `isContinueResponseSupported()`
`abstract boolean` `isOpen()`
`boolean` `isPushSupported()`
`abstract boolean` `isRequestTrailerFieldsSupported()`
`protected abstract boolean` `isUpgradeSupported()`
`protected abstract void` `maxEntitySizeUpdated(HttpServerExchange exchange)` Callback that is invoked if the max entity size is updated.
`boolean` `pushResource(String path, HttpString method, HeaderMap requestHeaders)` Attempts to push a resource if this connection supports server push.
`boolean` `pushResource(String path, HttpString method, HeaderMap requestHeaders, HttpHandler handler)` Attempts to push a resource if this connection supports server push.
`abstract HttpServerExchange` `sendOutOfBandResponse(HttpServerExchange exchange)` Sends an out of band response, such as a HTTP 100-continue response.
`protected abstract void` `setConnectListener(HttpUpgradeListener connectListener)`
`abstract <T> T` `setOption(org.xnio.Option<T> option, T value)`
`abstract void` `setSslSessionInfo(SSLSessionInfo sessionInfo)` Sets the current SSL information.
`protected abstract void` `setUpgradeListener(HttpUpgradeListener upgradeListener)`
`abstract boolean` `supportsOption(org.xnio.Option<?> option)`
`abstract void` `terminateRequestChannel(HttpServerExchange exchange)` Invoked when the exchange is complete, and there is still data in the request channel.
`protected abstract org.xnio.StreamConnection` `upgradeChannel()` Upgrade the connection, if allowed

### Methods inherited from class io.undertow.util.AbstractAttachable

`addToAttachmentList, createAttachmentMap, getAttachment, getAttachmentList, putAttachment, removeAttachment`

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

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

### Methods inherited from interface org.xnio.channels.ConnectedChannel

`getCloseSetter`

### Constructor Detail

#### ServerConnection

    public ServerConnection()

### Method Detail

#### getBufferPool

    @Deprecated
    public abstract org.xnio.Pool<ByteBuffer> getBufferPool()

Deprecated.

Returns:
  The connections buffer pool

#### getByteBufferPool

    public abstract ByteBufferPool getByteBufferPool()

Returns:
  The connections buffer pool

#### getWorker

    public abstract org.xnio.XnioWorker getWorker()

Specified by:
  `getWorker` in interface `org.xnio.channels.CloseableChannel`
Returns:
  The connections worker

#### getIoThread

    public abstract org.xnio.XnioIoThread getIoThread()

Specified by:
  `getIoThread` in interface `org.xnio.channels.CloseableChannel`
Returns:
  The IO thread associated with the connection

#### sendOutOfBandResponse

    public abstract HttpServerExchange sendOutOfBandResponse(HttpServerExchange exchange)

Sends an out of band response, such as a HTTP 100-continue response. WARNING: do not attempt to write to the current exchange until the out of band exchange has been fully written. Doing so may have unexpected results. TODO: this needs more thought.

Parameters:
  `exchange` - The current exchange
Returns:
  The out of band exchange.

#### isContinueResponseSupported

    public abstract boolean isContinueResponseSupported()

Returns:
  `true` if this connection supports sending a 100-continue response

#### terminateRequestChannel

    public abstract void terminateRequestChannel(HttpServerExchange exchange)

Invoked when the exchange is complete, and there is still data in the request channel. Some implementations (such as SPDY and HTTP2) have more efficient ways to drain the request than simply reading all data (e.g. RST_STREAM). After this method is invoked the stream will be drained normally.

Parameters:
  `exchange` - The current exchange.

#### isOpen

    public abstract boolean isOpen()

Specified by:
  `isOpen` in interface `Channel`
Returns:
  true if the connection is open

#### supportsOption

    public abstract boolean supportsOption(org.xnio.Option<?> option)

Specified by:
  `supportsOption` in interface `org.xnio.channels.Configurable`

#### getOption

    public abstract <T> T getOption(org.xnio.Option<T> option)
                             throws IOException

Specified by:
  `getOption` in interface `org.xnio.channels.Configurable`
Throws:
  `IOException`

#### setOption

    public abstract <T> T setOption(org.xnio.Option<T> option,
                                    T value)
                             throws IllegalArgumentException,
                                    IOException

Specified by:
  `setOption` in interface `org.xnio.channels.Configurable`
Throws:
  `IllegalArgumentException`
  `IOException`

#### close

    public abstract void close()
                        throws IOException

Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Channel`
Specified by:
  `close` in interface `InterruptibleChannel`
Specified by:
  `close` in interface `org.xnio.channels.CloseableChannel`
Throws:
  `IOException`

#### getSslSession

    public SSLSession getSslSession()

Gets the SSLSession of the underlying connection, or null if SSL is not in use. Note that for client cert auth `getSslSessionInfo()` should be used instead, as it takes into account other information potentially provided by load balancers that terminate SSL

Returns:
  The SSLSession of the connection

#### getPeerAddress

    public abstract SocketAddress getPeerAddress()

Returns the actual address of the remote connection. This will not take things like X-Forwarded-for into account.

Specified by:
  `getPeerAddress` in interface `org.xnio.channels.ConnectedChannel`
Returns:
  The address of the remote peer

#### getPeerAddress

    public abstract <A extends SocketAddress> A getPeerAddress(Class<A> type)

Returns the actual address of the remote connection. This will not take things like X-Forwarded-for into account.

Specified by:
  `getPeerAddress` in interface `org.xnio.channels.ConnectedChannel`
Type Parameters:
  `A` - The address type
Parameters:
  `type` - The type of address to return
Returns:
  The remote endpoint address

#### getLocalAddress

    public abstract SocketAddress getLocalAddress()

Specified by:
  `getLocalAddress` in interface `org.xnio.channels.BoundChannel`

#### getLocalAddress

    public abstract <A extends SocketAddress> A getLocalAddress(Class<A> type)

Specified by:
  `getLocalAddress` in interface `org.xnio.channels.BoundChannel`

#### getUndertowOptions

    public abstract org.xnio.OptionMap getUndertowOptions()

#### getBufferSize

    public abstract int getBufferSize()

#### getSslSessionInfo

    public abstract SSLSessionInfo getSslSessionInfo()

Gets SSL information about the connection. This could represent the actual client connection, or could be providing SSL information that was provided by a front end proxy.

Returns:
  SSL information about the connection

#### setSslSessionInfo

    public abstract void setSslSessionInfo(SSLSessionInfo sessionInfo)

Sets the current SSL information. This can be used by handlers to setup SSL information that was provided by a front end proxy. If this is being set of a per request basis then you must ensure that it is either cleared by an exchange completion listener at the end of the request, or is always set for every request. Otherwise it is possible to SSL information to 'leak' between requests.

Parameters:
  `sessionInfo` - The ssl session information

#### addCloseListener

    public abstract void addCloseListener(ServerConnection.CloseListener listener)

Adds a close listener, than will be invoked with the connection is closed

Parameters:
  `listener` - The close listener

#### upgradeChannel

    protected abstract org.xnio.StreamConnection upgradeChannel()

Upgrade the connection, if allowed

Returns:
  The StreamConnection that should be passed to the upgrade handler

#### getSinkChannel

    protected abstract org.xnio.conduits.ConduitStreamSinkChannel getSinkChannel()

#### getSourceChannel

    protected abstract org.xnio.conduits.ConduitStreamSourceChannel getSourceChannel()

#### getSinkConduit

    protected abstract org.xnio.conduits.StreamSinkConduit getSinkConduit(HttpServerExchange exchange,
                                                                          org.xnio.conduits.StreamSinkConduit conduit)

Gets the sink conduit that should be used for this request. This allows the connection to apply any per-request conduit wrapping that is required, without adding to the response wrappers array. There is no corresponding method for source conduits, as in general conduits can be directly inserted into the connection after the request has been read.

Returns:
  The source conduit

#### isUpgradeSupported

    protected abstract boolean isUpgradeSupported()

Returns:
  true if this connection supports HTTP upgrade

#### isConnectSupported

    protected abstract boolean isConnectSupported()

Returns:
  `true` if this connection supports the HTTP CONNECT verb

#### exchangeComplete

    protected abstract void exchangeComplete(HttpServerExchange exchange)

Invoked when the exchange is complete.

#### setUpgradeListener

    protected abstract void setUpgradeListener(HttpUpgradeListener upgradeListener)

#### setConnectListener

    protected abstract void setConnectListener(HttpUpgradeListener connectListener)

#### maxEntitySizeUpdated

    protected abstract void maxEntitySizeUpdated(HttpServerExchange exchange)

Callback that is invoked if the max entity size is updated.

Parameters:
  `exchange` - The current exchange

#### getTransportProtocol

    public abstract String getTransportProtocol()

Returns a string representation describing the protocol used to transmit messages on this connection.

Returns:
  the transport protocol

#### pushResource

    public boolean pushResource(String path,
                                HttpString method,
                                HeaderMap requestHeaders)

Attempts to push a resource if this connection supports server push. Otherwise the request is ignored. Note that push is always done on a best effort basis, even if this method returns true it is possible that the remote endpoint will reset the stream

Parameters:
  `path` - The path of the resource
  `method` - The request method
  `requestHeaders` - The request headers
Returns:
  `true` if the server attempted the push, false otherwise

#### pushResource

    public boolean pushResource(String path,
                                HttpString method,
                                HeaderMap requestHeaders,
                                HttpHandler handler)

Attempts to push a resource if this connection supports server push. Otherwise the request is ignored. Note that push is always done on a best effort basis, even if this method returns true it is possible that the remote endpoint will reset the stream. The `HttpHandler` passed in will be used to generate the pushed response

Parameters:
  `path` - The path of the resource
  `method` - The request method
  `requestHeaders` - The request headers
Returns:
  `true` if the server attempted the push, false otherwise

#### isPushSupported

    public boolean isPushSupported()

#### isRequestTrailerFieldsSupported

    public abstract boolean isRequestTrailerFieldsSupported()