public final class HttpServerExchange extends AbstractAttachable implements BufferAllocator, OutputChannel, InputChannel, CompletedListener, PreCommitListener
| Modifier and Type | Field and Description |
|---|---|
static AttachmentKey<Map<String,String>> |
REQUEST_ATTRIBUTES
Attachment key that can be used to hold additional request attributes
|
static AttachmentKey<Boolean> |
SECURE_REQUEST
Attachment key that can be used as a flag of secure attribute
|
| Constructor and Description |
|---|
HttpServerExchange(HttpExchange delegate,
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) |
void |
addRequestHeader(String name,
String value) |
void |
addResponseCommitListener(ResponseCommitListener listener)
Adds a listener that will be invoked on response commit
|
void |
addResponseHeader(String name,
String value) |
void |
addWriteFunction(WriteFunction function) |
io.netty.buffer.ByteBuf |
allocateBuffer() |
io.netty.buffer.ByteBuf |
allocateBuffer(boolean direct) |
io.netty.buffer.ByteBuf |
allocateBuffer(boolean direct,
int bufferSize) |
io.netty.buffer.ByteBuf |
allocateBuffer(int bufferSize) |
void |
beginExecutingHandlerChain() |
void |
clearRequestHeaders() |
void |
clearResponseHeaders() |
void |
close() |
void |
completed(HttpExchange exchange) |
boolean |
containsRequestHeader(String name) |
boolean |
containsResponseHeader(String name) |
void |
discardRequest()
Used to terminate the request in an async manner, the actual mechanism will depend on the underlying getProtocol,
for example HTTP/2 may send a RST_STREAM stream if there is more data coming.
|
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.
|
void |
endExecutingHandlerChain() |
int |
getBufferSize() |
HttpExchange |
getDelegate() |
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.
|
InputChannel |
getInputChannel() |
InputStream |
getInputStream() |
io.netty.util.concurrent.EventExecutor |
getIoThread() |
long |
getMaxEntitySize() |
OutputChannel |
getOutputChannel() |
OutputStream |
getOutputStream() |
Map<String,Deque<String>> |
getPathParameters()
Returns a mutable map of path parameters
|
String |
getProtocol()
Get the request getProtocol string.
|
Map<String,Deque<String>> |
getQueryParameters()
Returns a mutable map of query parameters.
|
String |
getQueryString() |
String |
getRelativePath()
Get the request relative path.
|
long |
getRequestContentLength() |
Map<String,Cookie> |
getRequestCookies() |
String |
getRequestHeader(String name) |
Collection<String> |
getRequestHeaderNames() |
List<String> |
getRequestHeaders(String name) |
String |
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.
|
long |
getResponseBytesSent() |
long |
getResponseContentLength() |
Map<String,Cookie> |
getResponseCookies() |
String |
getResponseHeader(String name) |
Collection<String> |
getResponseHeaderNames() |
List<String> |
getResponseHeaders(String name) |
SecurityContext |
getSecurityContext() |
InetSocketAddress |
getSourceAddress()
Get the source address of the HTTP request.
|
SSLSessionInfo |
getSslSessionInfo() |
int |
getStatusCode()
Get the status code.
|
UndertowOptionMap |
getUndertowOptions() |
Executor |
getWorker() |
boolean |
isComplete() |
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 |
isInIoThread() |
boolean |
isPersistent() |
boolean |
isPushSupported() |
boolean |
isReadable() |
boolean |
isRequestComplete() |
boolean |
isRequestTrailerFieldsSupported() |
boolean |
isResponseComplete() |
boolean |
isResponseStarted() |
boolean |
isSecure() |
void |
preCommit(HttpExchange exchange) |
HttpServerExchange |
protocol(String protocol)
Sets the http getProtocol
|
void |
pushResource(String path,
String method,
Map<String,List<String>> requestHeaders) |
io.netty.buffer.ByteBuf |
readAsync() |
io.netty.buffer.ByteBuf |
readBlocking()
Reads some data.
|
int |
readBytesAvailable() |
void |
removeRequestHeader(String name) |
void |
removeResponseHeader(String name) |
HttpServerExchange |
requestMethod(String requestMethod)
Set the HTTP request method.
|
void |
resetRequestChannel() |
void |
runResumeReadWrite() |
void |
send1ContinueIfRequired() |
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 |
setQueryString(String queryString) |
<T> void |
setReadHandler(BiConsumer<InputChannel,T> handler,
T context) |
HttpServerExchange |
setRelativePath(String relativePath)
Set the request relative path.
|
void |
setRequestHeader(String name,
String value) |
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 |
setResponseContentLength(long length)
Sets the response content length
|
HttpServerExchange |
setResponseCookie(Cookie cookie)
Sets a response cookie
|
void |
setResponseHeader(String name,
String value) |
void |
setSecurityContext(SecurityContext securityContext) |
HttpServerExchange |
setSourceAddress(InetSocketAddress sourceAddress)
Sets the source address of the HTTP request.
|
void |
setSslSessionInfo(SSLSessionInfo info) |
HttpServerExchange |
setStatusCode(int statusCode)
Change the status code for this response.
|
void |
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(Consumer<Object> listener)
Upgrade the channel to a raw socket.
|
HttpServerExchange |
upgradeChannel(String productName,
Consumer<Object> listener)
Upgrade the channel to a raw socket.
|
<T> void |
writeAsync(io.netty.buffer.ByteBuf data,
boolean last,
IoCallback<T> callback,
T context) |
void |
writeAsync(String data)
Writes the given UTF-8 data and ends the exchange
|
void |
writeAsync(String data,
Charset charset)
Writes the given data in the provided charset and ends the exchange
|
<T> void |
writeAsync(String data,
Charset charset,
boolean last,
IoCallback<T> callback,
T context)
Writes the given data in the provided charset and invokes the provided callback on completion
|
void |
writeBlocking(io.netty.buffer.ByteBuf data,
boolean last) |
addToAttachmentList, createAttachmentMap, getAttachment, getAttachmentList, putAttachment, removeAttachmentpublic static final AttachmentKey<Map<String,String>> REQUEST_ATTRIBUTES
public static final AttachmentKey<Boolean> SECURE_REQUEST
public HttpServerExchange(HttpExchange delegate, long maxEntitySize)
public String getProtocol()
HttpProtocolNames.public HttpServerExchange protocol(String protocol)
protocol - public boolean isSecure()
public String getRequestMethod()
HttpMethodNames.public HttpServerExchange requestMethod(String 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 long getRequestContentLength()
public long getResponseContentLength()
-1 if it has not been setpublic 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 HttpExchange getDelegate()
public int getHostPort()
public boolean isPersistent()
public boolean isInIoThread()
true If the current thread in the IO thread for the exchangepublic long getResponseBytesSent()
public HttpServerExchange setPersistent(boolean persistent)
public boolean isDispatched()
public HttpServerExchange unDispatch()
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 addExchangeCompleteListener(ExchangeCompletionListener listener)
public HttpServerExchange addDefaultResponseListener(DefaultResponseListener listener)
public InetSocketAddress getSourceAddress()
public boolean isComplete()
public boolean isRequestComplete()
public boolean isResponseComplete()
public HttpServerExchange setSourceAddress(InetSocketAddress sourceAddress)
sourceAddress - The addresspublic InetSocketAddress getDestinationAddress()
public HttpServerExchange setDestinationAddress(InetSocketAddress destinationAddress)
destinationAddress - The addresspublic 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 io.netty.buffer.ByteBuf readBlocking()
throws IOException
readBlocking in interface InputChannelIOException - on failurepublic void send1ContinueIfRequired()
public void writeAsync(String data)
writeAsync in interface OutputChanneldata - The data to writepublic void writeAsync(String data, Charset charset)
writeAsync in interface OutputChanneldata - The data to writepublic <T> void writeAsync(String data, Charset charset, boolean last, IoCallback<T> callback, T context)
writeAsync in interface OutputChanneldata - The data to writepublic <T> void writeAsync(io.netty.buffer.ByteBuf data,
boolean last,
IoCallback<T> callback,
T context)
writeAsync in interface OutputChannelpublic void writeBlocking(io.netty.buffer.ByteBuf data,
boolean last)
throws IOException
writeBlocking in interface OutputChannelIOExceptionpublic int getStatusCode()
public boolean containsRequestHeader(String name)
public void removeRequestHeader(String name)
public Collection<String> getRequestHeaderNames()
public void clearRequestHeaders()
public void clearResponseHeaders()
public boolean containsResponseHeader(String name)
public void removeResponseHeader(String name)
public Collection<String> getResponseHeaderNames()
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 void 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 InputStream getInputStream()
public OutputStream getOutputStream()
public 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 io.netty.util.concurrent.EventExecutor 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 listenerpublic io.netty.buffer.ByteBuf readAsync()
throws IOException
readAsync in interface InputChannelIOExceptionpublic boolean isReadable()
isReadable in interface InputChannelpublic <T> void setReadHandler(BiConsumer<InputChannel,T> handler, T context)
setReadHandler in interface InputChannelpublic int readBytesAvailable()
readBytesAvailable in interface InputChannelpublic io.netty.buffer.ByteBuf allocateBuffer()
allocateBuffer in interface BufferAllocatorpublic io.netty.buffer.ByteBuf allocateBuffer(boolean direct)
allocateBuffer in interface BufferAllocatorpublic io.netty.buffer.ByteBuf allocateBuffer(int bufferSize)
allocateBuffer in interface BufferAllocatorpublic io.netty.buffer.ByteBuf allocateBuffer(boolean direct,
int bufferSize)
allocateBuffer in interface BufferAllocatorpublic int getBufferSize()
getBufferSize in interface BufferAllocatorpublic void discardRequest()
This may result in an unclean close if it is called on a non multiplexed getProtocol
public HttpServerExchange upgradeChannel(Consumer<Object> listener)
IllegalStateException - if a response or upgrade was already sent, or if the request body is already being
readpublic HttpServerExchange upgradeChannel(String productName, Consumer<Object> listener)
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 resetRequestChannel()
public void setSslSessionInfo(SSLSessionInfo info)
public SSLSessionInfo getSslSessionInfo()
public void close()
close in interface AutoCloseablepublic Executor getWorker()
public UndertowOptionMap getUndertowOptions()
public boolean isPushSupported()
public void pushResource(String path, String method, Map<String,List<String>> requestHeaders)
public boolean isRequestTrailerFieldsSupported()
public void completed(HttpExchange exchange)
completed in interface CompletedListenerpublic void beginExecutingHandlerChain()
public void endExecutingHandlerChain()
public void runResumeReadWrite()
public OutputChannel getOutputChannel()
public InputChannel getInputChannel()
public void preCommit(HttpExchange exchange)
preCommit in interface PreCommitListenerpublic void addWriteFunction(WriteFunction function)
Copyright © 2020 JBoss by Red Hat. All rights reserved.