Top Description Inners Fields Constructors Methods
io.undertow.server

public final Class HttpServerExchange

extends AbstractAttachable
Class Inheritance
Imports
io.undertow.UndertowLogger, .UndertowMessages, .UndertowOptions, io.undertow.channels.DetachableStreamSinkChannel, .DetachableStreamSourceChannel, io.undertow.conduits.EmptyStreamSourceConduit, io.undertow.connector.PooledByteBuffer, io.undertow.io.AsyncReceiverImpl, .AsyncSenderImpl, .BlockingReceiverImpl, .BlockingSenderImpl, .Receiver, .Sender, .UndertowInputStream, .UndertowOutputStream, io.undertow.security.api.SecurityContext, io.undertow.server.handlers.Cookie, io.undertow.util.AbstractAttachable, .AttachmentKey, .ConduitFactory, .Cookies, .HeaderMap, .Headers, .HttpString, .Methods, .NetworkUtils, .Protocols, .Rfc6265CookieSupport, .StatusCodes, org.jboss.logging.Logger, org.xnio.Buffers, .ChannelExceptionHandler, .ChannelListener, .ChannelListeners, .IoUtils, .XnioIoThread, org.xnio.channels.Channels, .Configurable, .StreamSinkChannel, .StreamSourceChannel, org.xnio.conduits.Conduit, .ConduitStreamSinkChannel, .ConduitStreamSourceChannel, .StreamSinkConduit, .StreamSourceConduit, java.io.IOException, .InputStream, .OutputStream, java.net.InetSocketAddress, java.nio.ByteBuffer, java.nio.channels.Channel, .FileChannel, java.util.ArrayDeque, .Deque, .Map, .Set, .TreeMap, java.util.concurrent.atomic.AtomicLong, java.util.concurrent.Executor, .TimeUnit

An HTTP server request/response exchange. An instance of this class is constructed as soon as the request headers are fully parsed.
Authors
David M. Lloyd, Richard Opalka

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private class
HttpServerExchange.ReadDispatchChannel

Channel implementation that is actually provided to clients of the exchange.

public static class
public static class
private class
HttpServerExchange.WriteDispatchChannel

Channel implementation that is actually provided to clients of the exchange.

Field Summary

Modifier and TypeField and Description
private BlockingHttpExchange
pack-priv static final AttachmentKey<PooledByteBuffer[]>
BUFFERED_REQUEST_DATA

The attachment key that buffered request data is attached under.

private final ServerConnection
private DefaultResponseListener[]
private Map<String, Cookie>
private Map<String, Cookie>
private InetSocketAddress
destinationAddress

The destination address for the request.

private Executor
dispatchExecutor

The executor that is to be used to dispatch the dispatchTask.

private Runnable
dispatchTask

When the call stack return this task will be executed by the executor specified in dispatchExecutor.

private ExchangeCompletionListener[]
private int
private static final int
FLAG_DISPATCHED

If this flag is set it means that the request has been dispatched, and will not be ending when the call stack returns.

private static final int
FLAG_IN_CALL

If this flag is set then the request is current running through a handler chain.

private static final int
FLAG_PERSISTENT

Flag that is set if this is a persistent connection, and the connection should be re-used.

private static final int
FLAG_REQUEST_RESET

Flag that indicates that the request channel has been reset, and getRequestChannel() can be called again

private static final int
FLAG_REQUEST_TERMINATED

Flag that is set once the request has been fully read.

private static final int
FLAG_RESPONSE_SENT

Flag that is set when the response sending begins

private static final int
FLAG_RESPONSE_TERMINATED

Flag that is sent when the response has been fully written and flushed.

private static final int
FLAG_SHOULD_RESUME_READS

Flag that indicates that reads should be resumed when the call stack returns.

private static final int
FLAG_SHOULD_RESUME_WRITES

Flag that indicates that writes should be resumed when the call stack returns

private static final int
FLAG_URI_CONTAINS_HOST

Flag that is set if the requestURI field contains the hostname.

private static final String
private static final String
private static final Logger
private static final int
private long
maxEntitySize

The maximum entity size.

private Map<String, Deque<String>>
private HttpString
private Map<String, Deque<String>>
private String
queryString

the query string

private static final AttachmentKey<String>
REASON_PHRASE

The HTTP reason phrase to send.

private Receiver
private String
relativePath

The remaining unresolved portion of request path.

public static final AttachmentKey<String>
REMOTE_USER

Attachment key that can be used to hold a remotely authenticated user

public static final AttachmentKey<Map<String, String>>
REQUEST_ATTRIBUTES

Attachment key that can be used to hold additional request attributes

private static final AtomicLong
protected HttpServerExchange.ReadDispatchChannel
requestChannel

The actual request channel.

private DelegatingIterable<Cookie>
private final HeaderMap
private final String
private HttpString
private String
requestPath

The request path.

private String
private long
private String
requestURI

The original request URI.

private int
private ConduitWrapper<StreamSourceConduit>[]
private String
resolvedPath

The resolved part of the canonical path.

private long
responseBytesSent

The number of bytes that have been sent to the remote client.

private HttpServerExchange.WriteDispatchChannel
responseChannel

The actual response channel.

private DelegatingIterable<Cookie>
private final HeaderMap
private int
private ConduitWrapper<StreamSinkConduit>[]
public static final AttachmentKey<Boolean>
SECURE_REQUEST

Attachment key that can be used as a flag of secure attribute

private SecurityContext
securityContext

The security context

private Sender
private static final RuntimePermission
private InetSocketAddress
sourceAddress

The source address for the request.

private int

Constructor Summary

AccessConstructor and Description
public
HttpServerExchange(final ServerConnection connection, long maxEntitySize)

public
public
HttpServerExchange(final ServerConnection connection, final HeaderMap requestHeaders, final HeaderMap responseHeaders, long maxEntitySize)

Method Summary

Modifier and TypeMethod and Description
public HttpServerExchange
public HttpServerExchange
public HttpServerExchange
public HttpServerExchange
addPathParam(final String name, final String param)

public HttpServerExchange
addQueryParam(final String name, final String param)

public HttpServerExchange
addRequestWrapper(final ConduitWrapper<StreamSourceConduit>
the wrapper
wrapper
)

Adds a ConduitWrapper to the request wrapper chain.

public void
addResponseCommitListener(final ResponseCommitListener
The response listener
listener
)

Adds a listener that will be invoked on response commit

public HttpServerExchange
addResponseWrapper(final ConduitWrapper<StreamSinkConduit>
the wrapper
wrapper
)

Adds a ConduitWrapper to the response wrapper chain.

private void
public HttpServerExchange

Returns:

this exchange
dispatch
()
Deprecated

dispatch(Executor, Runnable) should be used instead of this method, as it is hard to use safely.

public HttpServerExchange
dispatch(final Runnable
The task to run
runnable
)

Dispatches this request to the XNIO worker thread pool.

public HttpServerExchange
dispatch(final Executor executor, final Runnable
The task to run
runnable
)

Dispatches this request to the given executor.

public HttpServerExchange
dispatch(final HttpHandler handler)

public HttpServerExchange
dispatch(final Executor executor, final HttpHandler handler)

public HttpServerExchange
endExchange()

Ends the exchange by fully draining the request channel, and flushing the response channel.

private String
public ServerConnection

Returns:

the underlying HTTP connection
getConnection
()

Get the underlying HTTP connection.

public InetSocketAddress

Returns:

the destination address of the HTTP request
getDestinationAddress
()

Get the destination address of the HTTP request.

public Executor

Returns:

The current dispatch executor
getDispatchExecutor
()

Gets the current executor that is used for dispatch operations.

pack-priv Runnable

Returns:

The current dispatch task
getDispatchTask
()

public String

Returns:

The host and port part of the destination address
getHostAndPort
()

Return the host, and also the port if this request was sent to a non-standard port.

public String

Returns:

The host part of the destination address
getHostName
()

Return the host that this request was sent to, in general this will be the value of the Host header, minus the port specifier.

public int

Returns:

The port part of the destination address
getHostPort
()

Return the port that this request was sent to.

public InputStream

Returns:

The input stream
getInputStream
()

public XnioIoThread
public long

Returns:

The maximum entity size for this exchange
getMaxEntitySize
()

public OutputStream

Returns:

The output stream
getOutputStream
()

public Map<String, Deque<String>>

Returns:

The path parameters
getPathParameters
()

Returns a mutable map of path parameters

public HttpString

Returns:

the request protocol string
getProtocol
()

Get the request protocol string.

public Map<String, Deque<String>>

Returns:

The query parameters
getQueryParameters
()

Returns a mutable map of query parameters.

public String

Returns:

The query string, without the leading ?
getQueryString
()

public String

Returns:

The current reason phrase
getReasonPhrase
()

public String

Returns:

the request relative path
getRelativePath
()

Get the request relative path.

public StreamSourceChannel

Returns:

the channel for the inbound request, or null if another party already acquired the channel
getRequestChannel
()

Get the inbound request.

public String

Returns:

The character encoding
getRequestCharset
()

Returns the request charset.

public long

Returns:

The content length of the request, or -1 if it has not been set
getRequestContentLength
()

public Cookie
public Map<String, Cookie>

Returns:

A mutable map of request cookies
getRequestCookies
()
Deprecated for removal since 2.2.0. use either requestCookies() or getRequestCookie(String) or setRequestCookie(Cookie) methods instead

public HeaderMap

Returns:

the request headers
getRequestHeaders
()

Get the request headers.

public String
public HttpString

Returns:

the HTTP request method
getRequestMethod
()

Get the HTTP request method.

public String
getRequestPath()

The request path.

public Receiver
public String

Returns:

the request URI scheme
getRequestScheme
()

Get the request URI scheme.

public long

Returns:

The request start time using the JVM's high-resolution time source, in nanoseconds, or -1 if this was not recorded
getRequestStartTime
()

public String
getRequestURI()

The original request URI.

public String
getRequestURL()

Reconstructs the complete URL as seen by the user.

public String

Returns:

the resolved path
getResolvedPath
()

Get the resolved path.

public long

Returns:

The number of bytes sent in the entity body
getResponseBytesSent
()

public StreamSinkChannel

Returns:

the response channel, or null if another party already acquired the channel
getResponseChannel
()

Get the response channel.

public String

Returns:

The character encoding
getResponseCharset
()

Returns the response charset.

public int

Returns:

the status code
getResponseCode
()
Deprecated

Get the status code.

public long

Returns:

The content length of the response, or -1 if it has not been set
getResponseContentLength
()

public Map<String, Cookie>

Returns:

A mutable map of response cookies
getResponseCookies
()
Deprecated for removal since 2.2.0. use either responseCookies() or setResponseCookie(Cookie) methods instead

public HeaderMap

Returns:

the response headers
getResponseHeaders
()

Get the response headers.

public Sender

Returns:

the response sender, or null if another party already acquired the channel or the sender
getResponseSender
()

Get the response sender.

public SecurityContext
public InetSocketAddress

Returns:

the source address of the HTTP request
getSourceAddress
()

Get the source address of the HTTP request.

public int

Returns:

the status code
getStatusCode
()

Get the status code.

private void
public boolean

Returns:

true If this is a blocking HTTP server exchange
isBlocking
()

Returns true if startBlocking() or startBlocking(BlockingHttpExchange) has been called.

public boolean
isComplete()

Returns true if the completion handler for this exchange has been invoked, and the request is considered finished.

public boolean
public boolean

Returns:

true If the request URI contains the host part of the URI
isHostIncludedInRequestURI
()

If a request was submitted to the server with a full URI instead of just a path this will return true.

public boolean

Returns:

true if the request protocol is equal to Protocols#HTTP_0_9, false otherwise
isHttp09
()

Determine whether this request conforms to HTTP 0.9.

public boolean

Returns:

true if the request protocol is equal to Protocols#HTTP_1_0, false otherwise
isHttp10
()

Determine whether this request conforms to HTTP 1.0.

public boolean

Returns:

true if the request protocol is equal to Protocols#HTTP_1_1, false otherwise
isHttp11
()

Determine whether this request conforms to HTTP 1.1.

pack-priv boolean
public boolean

Returns:

true If the current thread in the IO thread for the exchange
isInIoThread
()

public boolean
public boolean
public boolean

Returns:

true if the request is complete
isRequestComplete
()

Returns true if all data has been read from the request, or if there was not data.

public boolean

Returns:

true if getResponseChannel() has not been called
isResponseChannelAvailable
()

public boolean

Returns:

true if the responses is complete
isResponseComplete
()

public boolean

Returns:

true If the response has already been started
isResponseStarted
()

pack-priv boolean
public boolean
public boolean

Returns:

True if this exchange represents an upgrade response
isUpgrade
()

public Iterable<Cookie>

Returns:

A read-only enumeration of request cookies
requestCookies
()

Returns unmodifiable enumeration of request cookies.

pack-priv void
public Iterable<Cookie>

Returns:

A read-only enumeration of response cookies
responseCookies
()

Returns unmodifiable enumeration of response cookies.

pack-priv boolean

Returns:

true if reads or writes were resumed
runResumeReadWrite
()

Actually resumes reads or writes, if the relevant method has been called.

public HttpServerExchange
setDestinationAddress(InetSocketAddress
The address
destinationAddress
)

Sets the destination address of the HTTP request.

public HttpServerExchange
setDispatchExecutor(final Executor
The executor to use
executor
)

Sets the executor that is used for dispatch operations where no executor is specified.

pack-priv HttpServerExchange
setInCall(boolean value)

public HttpServerExchange
setMaxEntitySize(final long
The max entity size
maxEntitySize
)

Sets the max entity size for this exchange.

public HttpServerExchange
setPersistent(final boolean persistent)

public HttpServerExchange
setProtocol(final HttpString protocol)

Sets the http protocol

public HttpServerExchange
setQueryString(final String queryString)

Set query string.

public HttpServerExchange

Returns:

this exchange
setReasonPhrase
(String
The status message
message
)

Sets the HTTP reason phrase.

public HttpServerExchange
setRelativePath(final String
the request relative path
relativePath
)

Set the request relative path.

public HttpServerExchange
setRequestCookie(final Cookie
The cookie
cookie
)

Sets a request cookie

public HttpServerExchange
setRequestMethod(final HttpString
the HTTP request method
requestMethod
)

Set the HTTP request method.

public HttpServerExchange
setRequestPath(final String
the request URI path
requestPath
)

Set the request URI path.

public HttpServerExchange
setRequestScheme(final String
the request URI scheme
requestScheme
)

Set the request URI scheme.

pack-priv HttpServerExchange
setRequestStartTime(long requestStartTime)

public HttpServerExchange
setRequestURI(final String
The new request URI
requestURI
)

Sets the request URI

public HttpServerExchange
setRequestURI(final String
The new request URI
requestURI
,
boolean
If this is true the request URI contains the host part
containsHost
)

Sets the request URI

public HttpServerExchange
setResolvedPath(final String
the resolved path
resolvedPath
)

Set the resolved path.

public HttpServerExchange
setResponseCode(final int
the new code
statusCode
)
Deprecated

Change the status code for this response.

public HttpServerExchange
setResponseContentLength(long
The content length
length
)

Sets the response content length

public HttpServerExchange
setResponseCookie(final Cookie
The cookie
cookie
)

Sets a response cookie

public void
public HttpServerExchange
setSourceAddress(InetSocketAddress
The address
sourceAddress
)

Sets the source address of the HTTP request.

public HttpServerExchange
setStatusCode(final int
the new code
statusCode
)

Change the status code for this response.

public BlockingHttpExchange

Returns:

The existing blocking exchange, if any
startBlocking
()

Calling this method puts the exchange in blocking mode, and creates a BlockingHttpExchange object to store the streams.

public BlockingHttpExchange

Returns:

The existing blocking exchange, if any
startBlocking
(final BlockingHttpExchange httpExchange)

Calling this method puts the exchange in blocking mode, using the given blocking exchange as the source of the streams.

pack-priv HttpServerExchange
startResponse()

Transmit the response headers.

pack-priv void
terminateRequest()

Force the codec to treat the request as fully read.

pack-priv HttpServerExchange
terminateResponse()

Force the codec to treat the response as fully written.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public HttpServerExchange
pack-priv void
updateBytesSent(long
The number of bytes to increase the response size by. May be negative
bytes
)

Updates the number of response bytes sent.

public HttpServerExchange
upgradeChannel(final HttpUpgradeListener listener)

Upgrade the channel to a raw socket.

public HttpServerExchange
upgradeChannel(String
the product name to report to the client
productName
,
final HttpUpgradeListener listener)

Upgrade the channel to a raw socket.

Inherited from io.undertow.util.AbstractAttachable:
addToAttachmentListcreateAttachmentMapgetAttachmentgetAttachmentListputAttachmentremoveAttachment