public final class HttpServerExchange extends AbstractAttachable
Modifier and Type | Class and Description |
---|---|
static class |
HttpServerExchange.WrapperConduitFactory<T extends org.xnio.conduits.Conduit> |
static class |
HttpServerExchange.WrapperStreamSinkConduitFactory |
Modifier and Type | Field and Description |
---|---|
protected io.undertow.server.HttpServerExchange.ReadDispatchChannel |
requestChannel
The actual request channel.
|
Constructor and Description |
---|
HttpServerExchange(ServerConnection connection) |
HttpServerExchange(ServerConnection connection,
long maxEntitySize) |
Modifier and Type | Method and Description |
---|---|
HttpServerExchange |
addDefaultResponseListener(DefaultResponseListener listener) |
HttpServerExchange |
addExchangeCompleteListener(ExchangeCompletionListener listener) |
HttpServerExchange |
addPathParam(String name,
String param) |
HttpServerExchange |
addQueryParam(String name,
String param) |
HttpServerExchange |
addRequestWrapper(ConduitWrapper<org.xnio.conduits.StreamSourceConduit> wrapper)
Adds a
ConduitWrapper to the request wrapper chain. |
HttpServerExchange |
addResponseWrapper(ConduitWrapper<org.xnio.conduits.StreamSinkConduit> wrapper)
Adds a
ConduitWrapper to the response wrapper chain. |
HttpServerExchange |
dispatch() |
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 source 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() |
org.xnio.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 |
getRelativePath()
Get the request relative path.
|
org.xnio.channels.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.
|
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.
|
org.xnio.channels.StreamSinkChannel |
getResponseChannel()
Get the response channel.
|
String |
getResponseCharset()
Returns the response charset.
|
int |
getResponseCode()
Get the response code.
|
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.
|
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 |
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 responseCode)
Change the response code for this response.
|
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.
|
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, getAttachment, getAttachmentList, putAttachment, removeAttachment
protected io.undertow.server.HttpServerExchange.ReadDispatchChannel requestChannel
public HttpServerExchange(ServerConnection connection, long maxEntitySize)
public HttpServerExchange(ServerConnection connection)
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()
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()
true
If the request URI contains the host part of the URIpublic String getRequestPath()
public HttpServerExchange setRequestPath(String requestPath)
requestPath
- the request URI pathpublic String getRelativePath()
CanonicalPathHandler
is installed in the current chain
then this path with be canonicalizedpublic 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()
public String getRequestCharset()
public String getResponseCharset()
public String getHostName()
public String getHostAndPort()
public int getHostPort()
public ServerConnection getConnection()
public boolean isPersistent()
public boolean isInIoThread()
public boolean isUpgrade()
public HttpServerExchange setPersistent(boolean persistent)
public boolean isDispatched()
public HttpServerExchange unDispatch()
public HttpServerExchange dispatch()
public HttpServerExchange dispatch(Runnable runnable)
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)
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 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 org.xnio.channels.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 org.xnio.channels.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()
null
if another party already acquired the channel or the sendergetResponseChannel()
public boolean isResponseChannelAvailable()
true
if getResponseChannel()
has not been calledpublic HttpServerExchange setResponseCode(int responseCode)
200
. Setting
the response code after the response headers have been transmitted has no effect.responseCode
- the new codeIllegalStateException
- if a response or upgrade was already sentpublic HttpServerExchange addRequestWrapper(ConduitWrapper<org.xnio.conduits.StreamSourceConduit> wrapper)
ConduitWrapper
to the request wrapper chain.wrapper
- the wrapperpublic HttpServerExchange addResponseWrapper(ConduitWrapper<org.xnio.conduits.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)
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 int getResponseCode()
public long getRequestStartTime()
public HttpServerExchange endExchange()
public org.xnio.XnioIoThread getIoThread()
public long getMaxEntitySize()
public HttpServerExchange setMaxEntitySize(long maxEntitySize)
maxEntitySize
- The max entity sizepublic SecurityContext getSecurityContext()
public void setSecurityContext(SecurityContext securityContext)
Copyright © 2014 JBoss by Red Hat. All rights reserved.