public final class HttpServerExchange extends AbstractAttachable
Modifier and Type | Field and Description |
---|---|
static AttachmentKey<Executor> |
DISPATCH_EXECUTOR
The executor that is to be used to dispatch the
DISPATCH_TASK . |
static AttachmentKey<Runnable> |
DISPATCH_TASK
When the call stack return this task will be executed by the executor specified in
DISPATCH_EXECUTOR . |
Constructor and Description |
---|
HttpServerExchange(ServerConnection connection) |
HttpServerExchange(ServerConnection connection,
long maxEntitySize) |
Modifier and Type | Method and Description |
---|---|
void |
addDefaultResponseListener(DefaultResponseListener listener) |
void |
addExchangeCompleteListener(ExchangeCompletionListener listener) |
void |
addPathParam(String name,
String param) |
void |
addQueryParam(String name,
String param) |
void |
addRequestWrapper(ConduitWrapper<org.xnio.conduits.StreamSourceConduit> wrapper)
Adds a
ConduitWrapper to the request wrapper chain. |
void |
addResponseWrapper(ConduitWrapper<org.xnio.conduits.StreamSinkConduit> wrapper)
Adds a
ConduitWrapper to the response wrapper chain. |
void |
dispatch() |
void |
dispatch(Executor executor,
HttpHandler handler) |
void |
dispatch(Executor executor,
Runnable runnable)
Dispatches this request to the given executor.
|
void |
dispatch(HttpHandler handler) |
void |
dispatch(Runnable runnable)
Dispatches this request to the XNIO worker thread pool.
|
void |
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.
|
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.
|
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.
|
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.
|
int |
getResponseCode()
Get the response code.
|
long |
getResponseContentLength() |
Map<String,Cookie> |
getResponseCookies() |
HeaderMap |
getResponseHeaders()
Get the response headers.
|
Sender |
getResponseSender()
Get the response sender.
|
InetSocketAddress |
getSourceAddress()
Get the source address of the HTTP request.
|
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 |
isResponseChannelAvailable() |
boolean |
isResponseStarted() |
boolean |
isUpgrade() |
void |
setDispatchExecutor(Executor executor)
Sets the executor that is used for dispatch operations where no executor is specified.
|
void |
setMaxEntitySize(long maxEntitySize)
Sets the max entity size for this exchange.
|
void |
setPersistent(boolean persistent) |
void |
setProtocol(HttpString protocol)
Sets the http protocol
|
void |
setQueryString(String queryString) |
void |
setRelativePath(String relativePath)
Set the request relative path.
|
void |
setRequestMethod(HttpString requestMethod)
Set the HTTP request method.
|
void |
setRequestPath(String requestPath)
Set the request URI path.
|
void |
setRequestScheme(String requestScheme)
Set the request URI scheme.
|
void |
setRequestURI(String requestURI)
Sets the request URI
|
void |
setRequestURI(String requestURI,
boolean containsHost)
Sets the request URI
|
void |
setResolvedPath(String resolvedPath)
Set the resolved path.
|
void |
setResponseCode(int responseCode)
Change the response code for this response.
|
void |
setResponseContentLength(long length)
Sets the response content length
|
void |
setResponseCookie(Cookie cookie)
Sets a response cookie
|
void |
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.
|
void |
terminateRequest()
Force the codec to treat the request as fully read.
|
void |
terminateResponse()
Force the codec to treat the response as fully written.
|
String |
toString() |
void |
unDispatch() |
void |
upgradeChannel(ExchangeCompletionListener upgradeCompleteListener)
Upgrade the channel to a raw socket.
|
void |
upgradeChannel(String productName,
ExchangeCompletionListener upgradeCompleteListener)
Upgrade the channel to a raw socket.
|
addToAttachmentList, getAttachment, getAttachmentList, putAttachment, removeAttachment
public static final AttachmentKey<Executor> DISPATCH_EXECUTOR
DISPATCH_TASK
. Note that this is not cleared
between dispatches, so once a request has been dispatched once then all subsequent dispatches will use
the same executor.public static final AttachmentKey<Runnable> DISPATCH_TASK
DISPATCH_EXECUTOR
.
If the executor is null then it will be executed by the XNIO worker.public HttpServerExchange(ServerConnection connection, long maxEntitySize)
public HttpServerExchange(ServerConnection connection)
public HttpString getProtocol()
Protocols
.public void 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 void setRequestMethod(HttpString requestMethod)
requestMethod
- the HTTP request methodpublic String getRequestScheme()
http
or https
.public void setRequestScheme(String requestScheme)
requestScheme
- the request URI schemepublic String getRequestURI()
public void setRequestURI(String requestURI)
requestURI
- The new request URIpublic void setRequestURI(String requestURI, boolean containsHost)
requestURI
- The new request URIcontainsHost
- If this is true the request URI containst the host partpublic boolean isHostIncludedInRequestURI()
true
If the request URI contains the host part of the URIpublic String getRequestPath()
public void setRequestPath(String requestPath)
requestPath
- the request URI pathpublic String getRelativePath()
CanonicalPathHandler
is installed in the current chain
then this path with be canonicalizedpublic void setRelativePath(String relativePath)
relativePath
- the request relative pathpublic String getResolvedPath()
public void setResolvedPath(String resolvedPath)
resolvedPath
- the resolved pathpublic String getQueryString()
public void setQueryString(String queryString)
public String getRequestURL()
public String getHostName()
public String getHostAndPort()
public ServerConnection getConnection()
public boolean isPersistent()
public boolean isInIoThread()
public boolean isUpgrade()
public void setPersistent(boolean persistent)
public boolean isDispatched()
public void unDispatch()
public void dispatch()
public void 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 void 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 void dispatch(HttpHandler handler)
public void dispatch(Executor executor, HttpHandler handler)
public void setDispatchExecutor(Executor executor)
executor
- The executor to usepublic Executor getDispatchExecutor()
public void upgradeChannel(ExchangeCompletionListener upgradeCompleteListener)
AbstractServerConnection.getChannel()
IllegalStateException
- if a response or upgrade was already sent, or if the request body is already being
readpublic void upgradeChannel(String productName, ExchangeCompletionListener upgradeCompleteListener)
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 void addExchangeCompleteListener(ExchangeCompletionListener listener)
public void addDefaultResponseListener(DefaultResponseListener listener)
public InetSocketAddress getSourceAddress()
public void setSourceAddress(InetSocketAddress sourceAddress)
sourceAddress
- The addresspublic InetSocketAddress getDestinationAddress()
public HeaderMap getRequestHeaders()
public long getRequestContentLength()
-1
if it has not been setpublic HeaderMap getResponseHeaders()
public long getResponseContentLength()
-1
if it has not been setpublic void setResponseContentLength(long length)
length
- The content lengthpublic Map<String,Deque<String>> getQueryParameters()
public Map<String,Deque<String>> getPathParameters()
public Map<String,Cookie> getRequestCookies()
public void 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 void terminateRequest()
public org.xnio.channels.StreamSinkChannel getResponseChannel()
SuspendableWriteChannel.shutdownWrites()
,
and then call SuspendableWriteChannel.flush()
until it returns true. Alternativly 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 void 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 void addRequestWrapper(ConduitWrapper<org.xnio.conduits.StreamSourceConduit> wrapper)
ConduitWrapper
to the request wrapper chain.wrapper
- the wrapperpublic void 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 InputStream getInputStream()
IllegalStateException
- if startBlocking()
has not been calledpublic OutputStream getOutputStream()
IllegalStateException
- if startBlocking()
has not been calledpublic int getResponseCode()
public void terminateResponse()
public void endExchange()
public org.xnio.XnioIoThread getIoThread()
public long getMaxEntitySize()
public void setMaxEntitySize(long maxEntitySize)
maxEntitySize
- The max entity sizeCopyright © 2013 JBoss by Red Hat. All rights reserved.