public final class HttpServerExchange extends AbstractAttachable
Modifier and Type | Class and Description |
---|---|
static class |
HttpServerExchange.WrapperConduitFactory<T extends Conduit> |
static class |
HttpServerExchange.WrapperStreamSinkConduitFactory |
Modifier and Type | Field and Description |
---|---|
static AttachmentKey<Map<String,String>> |
REQUEST_ATTRIBUTES
Attachment key that can be used to hold additional request attributes
|
protected io.undertow.server.HttpServerExchange.ReadDispatchChannel |
requestChannel
The actual request channel.
|
Constructor and Description |
---|
HttpServerExchange(ServerConnection connection) |
HttpServerExchange(ServerConnection connection,
HeaderMap requestHeaders,
HeaderMap responseHeaders,
long maxEntitySize) |
HttpServerExchange(ServerConnection connection,
long maxEntitySize) |
Modifier and Type | Method and Description |
---|---|
HttpServerExchange |
acceptConnectRequest(HttpUpgradeListener connectListener) |
HttpServerExchange |
addDefaultResponseListener(DefaultResponseListener listener) |
HttpServerExchange |
addExchangeCompleteListener(ExchangeCompletionListener listener) |
HttpServerExchange |
addPathParam(String name,
String param) |
HttpServerExchange |
addQueryParam(String name,
String param) |
HttpServerExchange |
addRequestWrapper(ConduitWrapper<StreamSourceConduit> wrapper)
Adds a
ConduitWrapper to the request wrapper chain. |
void |
addResponseCommitListener(ResponseCommitListener listener)
Adds a listener that will be invoked on response commit
|
HttpServerExchange |
addResponseWrapper(ConduitWrapper<StreamSinkConduit> wrapper)
Adds a
ConduitWrapper to the response wrapper chain. |
HttpServerExchange |
dispatch()
Deprecated.
|
HttpServerExchange |
dispatch(Executor executor,
HttpHandler handler) |
HttpServerExchange |
dispatch(Executor executor,
Runnable runnable)
Dispatches this request to the given executor.
|
HttpServerExchange |
dispatch(HttpHandler handler) |
HttpServerExchange |
dispatch(Runnable runnable)
Dispatches this request to the XNIO worker thread pool.
|
HttpServerExchange |
endExchange()
Ends the exchange by fully draining the request channel, and flushing the response channel.
|
ServerConnection |
getConnection()
Get the underlying HTTP connection.
|
InetSocketAddress |
getDestinationAddress()
Get the destination address of the HTTP request.
|
Executor |
getDispatchExecutor()
Gets the current executor that is used for dispatch operations.
|
String |
getHostAndPort()
Return the host, and also the port if this request was sent to a non-standard port.
|
String |
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.
|
int |
getHostPort()
Return the port that this request was sent to.
|
InputStream |
getInputStream() |
XnioIoThread |
getIoThread() |
long |
getMaxEntitySize() |
OutputStream |
getOutputStream() |
Map<String,Deque<String>> |
getPathParameters()
Returns a mutable map of path parameters
|
HttpString |
getProtocol()
Get the request protocol string.
|
Map<String,Deque<String>> |
getQueryParameters()
Returns a mutable map of query parameters.
|
String |
getQueryString() |
String |
getReasonPhrase() |
String |
getRelativePath()
Get the request relative path.
|
StreamSourceChannel |
getRequestChannel()
Get the inbound request.
|
String |
getRequestCharset()
Returns the request charset.
|
long |
getRequestContentLength() |
Map<String,Cookie> |
getRequestCookies() |
HeaderMap |
getRequestHeaders()
Get the request headers.
|
HttpString |
getRequestMethod()
Get the HTTP request method.
|
String |
getRequestPath()
The request path.
|
Receiver |
getRequestReceiver() |
String |
getRequestScheme()
Get the request URI scheme.
|
long |
getRequestStartTime() |
String |
getRequestURI()
The original request URI.
|
String |
getRequestURL()
Reconstructs the complete URL as seen by the user.
|
String |
getResolvedPath()
Get the resolved path.
|
long |
getResponseBytesSent() |
StreamSinkChannel |
getResponseChannel()
Get the response channel.
|
String |
getResponseCharset()
Returns the response charset.
|
int |
getResponseCode()
Deprecated.
|
long |
getResponseContentLength() |
Map<String,Cookie> |
getResponseCookies() |
HeaderMap |
getResponseHeaders()
Get the response headers.
|
Sender |
getResponseSender()
Get the response sender.
|
SecurityContext |
getSecurityContext() |
InetSocketAddress |
getSourceAddress()
Get the source address of the HTTP request.
|
int |
getStatusCode()
Get the status code.
|
boolean |
isBlocking()
Returns true if
startBlocking() or startBlocking(BlockingHttpExchange) has been called. |
boolean |
isComplete()
Returns true if the completion handler for this exchange has been invoked, and the request is considered
finished.
|
boolean |
isDispatched() |
boolean |
isHostIncludedInRequestURI()
If a request was submitted to the server with a full URI instead of just a path this
will return true.
|
boolean |
isHttp09()
Determine whether this request conforms to HTTP 0.9.
|
boolean |
isHttp10()
Determine whether this request conforms to HTTP 1.0.
|
boolean |
isHttp11()
Determine whether this request conforms to HTTP 1.1.
|
boolean |
isInIoThread() |
boolean |
isPersistent() |
boolean |
isRequestChannelAvailable() |
boolean |
isRequestComplete()
Returns true if all data has been read from the request, or if there
was not data.
|
boolean |
isResponseChannelAvailable() |
boolean |
isResponseComplete() |
boolean |
isResponseStarted() |
boolean |
isUpgrade() |
HttpServerExchange |
setDestinationAddress(InetSocketAddress destinationAddress)
Sets the destination address of the HTTP request.
|
HttpServerExchange |
setDispatchExecutor(Executor executor)
Sets the executor that is used for dispatch operations where no executor is specified.
|
HttpServerExchange |
setMaxEntitySize(long maxEntitySize)
Sets the max entity size for this exchange.
|
HttpServerExchange |
setPersistent(boolean persistent) |
HttpServerExchange |
setProtocol(HttpString protocol)
Sets the http protocol
|
HttpServerExchange |
setQueryString(String queryString) |
HttpServerExchange |
setReasonPhrase(String message)
Sets the HTTP reason phrase.
|
HttpServerExchange |
setRelativePath(String relativePath)
Set the request relative path.
|
HttpServerExchange |
setRequestMethod(HttpString requestMethod)
Set the HTTP request method.
|
HttpServerExchange |
setRequestPath(String requestPath)
Set the request URI path.
|
HttpServerExchange |
setRequestScheme(String requestScheme)
Set the request URI scheme.
|
HttpServerExchange |
setRequestURI(String requestURI)
Sets the request URI
|
HttpServerExchange |
setRequestURI(String requestURI,
boolean containsHost)
Sets the request URI
|
HttpServerExchange |
setResolvedPath(String resolvedPath)
Set the resolved path.
|
HttpServerExchange |
setResponseCode(int statusCode)
Deprecated.
|
HttpServerExchange |
setResponseContentLength(long length)
Sets the response content length
|
HttpServerExchange |
setResponseCookie(Cookie cookie)
Sets a response cookie
|
void |
setSecurityContext(SecurityContext securityContext) |
HttpServerExchange |
setSourceAddress(InetSocketAddress sourceAddress)
Sets the source address of the HTTP request.
|
HttpServerExchange |
setStatusCode(int statusCode)
Change the status code for this response.
|
BlockingHttpExchange |
startBlocking()
Calling this method puts the exchange in blocking mode, and creates a
BlockingHttpExchange object to store the streams. |
BlockingHttpExchange |
startBlocking(BlockingHttpExchange httpExchange)
Calling this method puts the exchange in blocking mode, using the given
blocking exchange as the source of the streams.
|
String |
toString() |
HttpServerExchange |
unDispatch() |
HttpServerExchange |
upgradeChannel(HttpUpgradeListener listener)
Upgrade the channel to a raw socket.
|
HttpServerExchange |
upgradeChannel(String productName,
HttpUpgradeListener listener)
Upgrade the channel to a raw socket.
|
addToAttachmentList, createAttachmentMap, getAttachment, getAttachmentList, putAttachment, removeAttachment
public static final AttachmentKey<Map<String,String>> REQUEST_ATTRIBUTES
protected io.undertow.server.HttpServerExchange.ReadDispatchChannel requestChannel
public HttpServerExchange(ServerConnection connection, long maxEntitySize)
public HttpServerExchange(ServerConnection connection)
public HttpServerExchange(ServerConnection connection, HeaderMap requestHeaders, HeaderMap responseHeaders, long maxEntitySize)
public HttpString getProtocol()
Protocols
.public HttpServerExchange setProtocol(HttpString protocol)
protocol
- public boolean isHttp09()
true
if the request protocol is equal to Protocols.HTTP_0_9
, false
otherwisepublic boolean isHttp10()
true
if the request protocol is equal to Protocols.HTTP_1_0
, false
otherwisepublic boolean isHttp11()
true
if the request protocol is equal to Protocols.HTTP_1_1
, false
otherwisepublic HttpString getRequestMethod()
Methods
.public HttpServerExchange setRequestMethod(HttpString requestMethod)
requestMethod
- the HTTP request methodpublic String getRequestScheme()
http
or https
.public HttpServerExchange setRequestScheme(String requestScheme)
requestScheme
- the request URI schemepublic String getRequestURI()
This is not decoded in any way, and does not include the query string.
Examples: GET http://localhost:8080/myFile.jsf?foo=bar HTTP/1.1 -> 'http://localhost:8080/myFile.jsf' POST /my+File.jsf?foo=bar HTTP/1.1 -> '/my+File.jsf'
public HttpServerExchange setRequestURI(String requestURI)
requestURI
- The new request URIpublic HttpServerExchange setRequestURI(String requestURI, boolean containsHost)
requestURI
- The new request URIcontainsHost
- If this is true the request URI contains the host partpublic boolean isHostIncludedInRequestURI()
GET http://localhost:8080/b/../my+File.jsf?foo=bar HTTP/1.1 -> true POST /my+File.jsf?foo=bar HTTP/1.1 -> false
true
If the request URI contains the host part of the URIpublic String getRequestPath()
This path is not canonicalised, so care must be taken to ensure that escape attacks are not possible.
Examples: GET http://localhost:8080/b/../my+File.jsf?foo=bar HTTP/1.1 -> '/b/../my+File.jsf' POST /my+File.jsf?foo=bar HTTP/1.1 -> '/my File.jsf'
public HttpServerExchange setRequestPath(String requestPath)
requestPath
- the request URI pathpublic String getRelativePath()
If the CanonicalPathHandler
is installed in the current chain
then this path with be canonicalized
public HttpServerExchange setRelativePath(String relativePath)
relativePath
- the request relative pathpublic String getResolvedPath()
public HttpServerExchange setResolvedPath(String resolvedPath)
resolvedPath
- the resolved pathpublic String getQueryString()
public HttpServerExchange setQueryString(String queryString)
public String getRequestURL()
This is not decoded.
public String getRequestCharset()
public String getResponseCharset()
public String getHostName()
If this resolves to an IPv6 address it will not be enclosed by square brackets. Care must be taken when constructing URLs based on this method to ensure IPv6 URLs are handled correctly.
public String getHostAndPort()
If this resolves to an IPv6 address it *will* be enclosed by square brackets. The return value of this method is suitable for inclusion in a URL.
public int getHostPort()
public ServerConnection getConnection()
public boolean isPersistent()
public boolean isInIoThread()
true
If the current thread in the IO thread for the exchangepublic boolean isUpgrade()
public long getResponseBytesSent()
public HttpServerExchange setPersistent(boolean persistent)
public boolean isDispatched()
public HttpServerExchange unDispatch()
@Deprecated public HttpServerExchange dispatch()
dispatch(Executor, Runnable)
should be used instead of this method, as it is hard to use safely.
Use SameThreadExecutor.INSTANCE
if you do not want to dispatch to another thread.public HttpServerExchange dispatch(Runnable runnable)
In general handlers should first check the value of isInIoThread()
before
calling this method, and only dispatch if the request is actually running in the IO
thread.
runnable
- The task to runIllegalStateException
- If this exchange has already been dispatchedpublic HttpServerExchange dispatch(Executor executor, Runnable runnable)
In general handlers should first check the value of isInIoThread()
before
calling this method, and only dispatch if the request is actually running in the IO
thread.
runnable
- The task to runIllegalStateException
- If this exchange has already been dispatchedpublic HttpServerExchange dispatch(HttpHandler handler)
public HttpServerExchange dispatch(Executor executor, HttpHandler handler)
public HttpServerExchange setDispatchExecutor(Executor executor)
executor
- The executor to usepublic Executor getDispatchExecutor()
public HttpServerExchange upgradeChannel(HttpUpgradeListener listener)
AbstractServerConnection.getChannel()
IllegalStateException
- if a response or upgrade was already sent, or if the request body is already being
readpublic HttpServerExchange upgradeChannel(String productName, HttpUpgradeListener listener)
AbstractServerConnection.getChannel()
productName
- the product name to report to the clientIllegalStateException
- if a response or upgrade was already sent, or if the request body is already being
readpublic HttpServerExchange acceptConnectRequest(HttpUpgradeListener connectListener)
connectListener
- public HttpServerExchange addExchangeCompleteListener(ExchangeCompletionListener listener)
public HttpServerExchange addDefaultResponseListener(DefaultResponseListener listener)
public InetSocketAddress getSourceAddress()
public HttpServerExchange setSourceAddress(InetSocketAddress sourceAddress)
sourceAddress
- The addresspublic InetSocketAddress getDestinationAddress()
public HttpServerExchange setDestinationAddress(InetSocketAddress destinationAddress)
destinationAddress
- The addresspublic HeaderMap getRequestHeaders()
public long getRequestContentLength()
-1
if it has not been setpublic HeaderMap getResponseHeaders()
public long getResponseContentLength()
-1
if it has not been setpublic HttpServerExchange setResponseContentLength(long length)
length
- The content lengthpublic Map<String,Deque<String>> getQueryParameters()
public HttpServerExchange addQueryParam(String name, String param)
public Map<String,Deque<String>> getPathParameters()
public HttpServerExchange addPathParam(String name, String param)
public Map<String,Cookie> getRequestCookies()
public HttpServerExchange setResponseCookie(Cookie cookie)
cookie
- The cookiepublic Map<String,Cookie> getResponseCookies()
public boolean isResponseStarted()
true
If the response has already been startedpublic StreamSourceChannel getRequestChannel()
Channel.close()
or SuspendableReadChannel.shutdownReads()
method must be called at some point after the request is processed to prevent resource leakage and to allow
the next request to proceed. Any unread content will be discarded.null
if another party already acquired the channelpublic boolean isRequestChannelAvailable()
public boolean isComplete()
public boolean isRequestComplete()
public boolean isResponseComplete()
public StreamSinkChannel getResponseChannel()
SuspendableWriteChannel.shutdownWrites()
,
and then call SuspendableWriteChannel.flush()
until it returns true. Alternatively you can
call endExchange()
, which will close the channel as part of its cleanup.
Closing a fixed-length response before the corresponding number of bytes has been written will cause the connection to be reset and subsequent requests to fail; thus it is important to ensure that the proper content length is delivered when one is specified. The response channel may not be writable until after the response headers have been sent.
If this method is not called then an empty or default response body will be used, depending on the response code set.
The returned channel will begin to write out headers when the first write request is initiated, or when
SuspendableWriteChannel.shutdownWrites()
is called on the channel with no content being written.
Once the channel is acquired, however, the response code and headers may not be modified.
null
if another party already acquired the channelpublic Sender getResponseSender()
For blocking exchanges this will return a sender that uses the underlying output stream.
null
if another party already acquired the channel or the sendergetResponseChannel()
public Receiver getRequestReceiver()
public boolean isResponseChannelAvailable()
true
if getResponseChannel()
has not been called@Deprecated public int getResponseCode()
getStatusCode()
@Deprecated public HttpServerExchange setResponseCode(int statusCode)
200
. Setting
the status code after the response headers have been transmitted has no effect.statusCode
- the new codeIllegalStateException
- if a response or upgrade was already sentsetStatusCode(int)
public int getStatusCode()
public HttpServerExchange setStatusCode(int statusCode)
200
. Setting
the status code after the response headers have been transmitted has no effect.statusCode
- the new codeIllegalStateException
- if a response or upgrade was already sentpublic HttpServerExchange setReasonPhrase(String message)
message
- The status messagepublic String getReasonPhrase()
public HttpServerExchange addRequestWrapper(ConduitWrapper<StreamSourceConduit> wrapper)
ConduitWrapper
to the request wrapper chain.wrapper
- the wrapperpublic HttpServerExchange addResponseWrapper(ConduitWrapper<StreamSinkConduit> wrapper)
ConduitWrapper
to the response wrapper chain.wrapper
- the wrapperpublic BlockingHttpExchange startBlocking()
BlockingHttpExchange
object to store the streams.
When an exchange is in blocking mode the input stream methods become available, other than that there is presently no major difference between blocking an non-blocking modes.
public BlockingHttpExchange startBlocking(BlockingHttpExchange httpExchange)
When an exchange is in blocking mode the input stream methods become available, other than that there is presently no major difference between blocking an non-blocking modes.
Note that this method may be called multiple times with different exchange objects, to allow handlers to modify the streams that are being used.
public boolean isBlocking()
startBlocking()
or startBlocking(BlockingHttpExchange)
has been called.true
If this is a blocking HTTP server exchangepublic InputStream getInputStream()
IllegalStateException
- if startBlocking()
has not been calledpublic OutputStream getOutputStream()
IllegalStateException
- if startBlocking()
has not been calledpublic long getRequestStartTime()
public HttpServerExchange endExchange()
This can result in handoff to an XNIO worker, so after this method is called the exchange should not be modified by the caller.
If the exchange is already complete this method is a noop
public XnioIoThread getIoThread()
public long getMaxEntitySize()
public HttpServerExchange setMaxEntitySize(long maxEntitySize)
maxEntitySize
- The max entity sizepublic SecurityContext getSecurityContext()
public void setSecurityContext(SecurityContext securityContext)
public void addResponseCommitListener(ResponseCommitListener listener)
listener
- The response listenerCopyright © 2017 JBoss by Red Hat. All rights reserved.