Package io.undertow
Class Handlers
java.lang.Object
io.undertow.Handlers
Utility class with convenience methods for dealing with handlers
- Author:
- Stuart Douglas
-
Method Summary
Modifier and TypeMethodDescriptionstatic AccessControlListHandleracl(HttpHandler next, boolean defaultAllow, ExchangeAttribute attribute) Returns a new handler that can allow or deny access to a resource based an at attribute of the exchangestatic DateHandlerdate(HttpHandler next) Deprecated.static HttpHandlerdisableCache(HttpHandler next) Handler that sets the headers that disable caching of the responsestatic ExceptionHandlerexceptionHandler(HttpHandler next) Returns a handler that maps exceptions to additional handlersstatic GracefulShutdownHandlergracefulShutdown(HttpHandler next) Returns a new handler that can be used to wait for all requests to finish before shutting down the server gracefully.static voidhandlerNotNull(HttpHandler handler) static SetHeaderHandlerheader(HttpHandler next, String headerName, ExchangeAttribute headerValue) Returns a handler that sets a response headerstatic SetHeaderHandlerheader(HttpHandler next, String headerName, String headerValue) Returns a handler that sets a response headerstatic HttpContinueReadHandlerhttpContinueRead(HttpHandler next) Deprecated.ipAccessControl(HttpHandler next, boolean defaultAllow) Returns a new handler that can allow or deny access to a resource based on IP addressstatic JvmRouteHandlerjvmRoute(String sessionCookieName, String jvmRoute, HttpHandler next) Handler that appends the JVM route to the session cookiestatic PathHandlerpath()Creates a new path handlerstatic PathHandlerpath(HttpHandler defaultHandler) Creates a new path handler, with the default handler specifiedstatic PathTemplateHandlerstatic PathTemplateHandlerpathTemplate(boolean rewriteQueryParams) static PredicateHandlerpredicate(Predicate predicate, HttpHandler trueHandler, HttpHandler falseHandler) Returns a new predicate handler, that will delegate to one of the two provided handlers based on the value of the provided predicate.static HttpHandlerpredicateContext(HttpHandler next) static PredicatesHandlerpredicates(List<PredicatedHandler> handlers, HttpHandler next) static ProxyPeerAddressHandlerproxyPeerAddress(HttpHandler next) Returns a new handler that sets the peer address based on the X-Forwarded-For and X-Forwarded-Proto headerstatic RedirectHandlerReturns a new redirect handlerstatic HttpHandlerrequestDump(HttpHandler next) Returns a handler that dumps requests to the log for debugging purposes.static RequestLimitingHandlerrequestLimitingHandler(int maxRequest, int queueSize, HttpHandler next) Returns a handler that limits the maximum number of requests that can run at a time.static RequestLimitingHandlerrequestLimitingHandler(RequestLimit requestLimit, HttpHandler next) Returns a handler that limits the maximum number of requests that can run at a time.static ResourceHandlerresource(ResourceManager resourceManager) Return a new resource handlerstatic ResponseRateLimitingHandlerresponseRateLimitingHandler(HttpHandler next, int bytes, long time, TimeUnit timeUnit) A handler that limits the download speed to a set number of bytes/periodstatic HttpHandlerrewrite(String condition, String target, ClassLoader classLoader, HttpHandler next) Creates the set of handlers that are required to perform a simple rewrite.static RoutingHandlerrouting()static RoutingHandlerrouting(boolean rewriteQueryParams) static SetAttributeHandlersetAttribute(HttpHandler next, String attribute, String value, ClassLoader classLoader) Returns an attribute setting handler that can be used to set an arbitrary attribute on the exchange.static HttpTraceHandlertrace(HttpHandler next) Returns a new HTTP trace handler.static URLDecodingHandlerurlDecoding(HttpHandler next, String charset) A handler that will decode the URL, query parameters and to the specified charset.static HttpHandlerurlDecodingHandler(String charset, HttpHandler next) Returns a new handler that decodes the URL and query parameters into the specified charset, assuming it has not already been done by the connector.static NameVirtualHostHandlerCreates a new virtual host handlerstatic NameVirtualHostHandlervirtualHost(HttpHandler defaultHandler) Creates a new virtual host handler using the provided default handlerstatic NameVirtualHostHandlervirtualHost(HttpHandler defaultHandler, HttpHandler hostHandler, String... hostnames) Creates a new virtual host handler that uses the provided handler as the root handler for the given hostnames.static NameVirtualHostHandlervirtualHost(HttpHandler hostHandler, String... hostnames) Creates a new virtual host handler that uses the provided handler as the root handler for the given hostnames.
-
Method Details
-
path
Creates a new path handler, with the default handler specified- Parameters:
defaultHandler- The default handler- Returns:
- A new path handler
-
path
Creates a new path handler- Returns:
- A new path handler
-
pathTemplate
- Returns:
- a new path template handler
-
routing
- Parameters:
rewriteQueryParams- If the query params should be rewritten- Returns:
- The routing handler
-
routing
- Returns:
- a new routing handler
-
pathTemplate
- Parameters:
rewriteQueryParams- If the query params should be rewritten- Returns:
- The path template handler
-
virtualHost
Creates a new virtual host handler- Returns:
- A new virtual host handler
-
virtualHost
Creates a new virtual host handler using the provided default handler- Returns:
- A new virtual host handler
-
virtualHost
Creates a new virtual host handler that uses the provided handler as the root handler for the given hostnames.- Parameters:
hostHandler- The host handlerhostnames- The host names- Returns:
- A new virtual host handler
-
virtualHost
public static NameVirtualHostHandler virtualHost(HttpHandler defaultHandler, HttpHandler hostHandler, String... hostnames) Creates a new virtual host handler that uses the provided handler as the root handler for the given hostnames.- Parameters:
defaultHandler- The default handlerhostHandler- The host handlerhostnames- The host names- Returns:
- A new virtual host handler
-
resource
Return a new resource handler- Parameters:
resourceManager- The resource manager to use- Returns:
- A new resource handler
-
redirect
Returns a new redirect handler- Parameters:
location- The redirect location- Returns:
- A new redirect handler
-
trace
Returns a new HTTP trace handler. This handler will handle HTTP TRACE requests as per the RFC.WARNING: enabling trace requests may leak information, in general it is recommended that these be disabled for security reasons.
- Parameters:
next- The next handler in the chain- Returns:
- A HTTP trace handler
-
date
Deprecated.Returns a new HTTP handler that sets the Date: header.This is no longer necessary, as it is handled by the connectors directly.
- Parameters:
next- The next handler in the chain- Returns:
- A new date handler
-
predicate
public static PredicateHandler predicate(Predicate predicate, HttpHandler trueHandler, HttpHandler falseHandler) Returns a new predicate handler, that will delegate to one of the two provided handlers based on the value of the provided predicate.- Parameters:
predicate- The predicatetrueHandler- The handler that will be executed if the predicate is truefalseHandler- The handler that will be exected if the predicate is false- Returns:
- A new predicate handler
- See Also:
-
predicateContext
- Parameters:
next- The next handler- Returns:
- a handler that sets up a new predicate context
-
predicates
-
header
Returns a handler that sets a response header- Parameters:
next- The next handler in the chainheaderName- The name of the headerheaderValue- The header value- Returns:
- A new set header handler
-
header
public static SetHeaderHandler header(HttpHandler next, String headerName, ExchangeAttribute headerValue) Returns a handler that sets a response header- Parameters:
next- The next handler in the chainheaderName- The name of the headerheaderValue- The header value- Returns:
- A new set header handler
-
ipAccessControl
Returns a new handler that can allow or deny access to a resource based on IP address- Parameters:
next- The next handler in the chaindefaultAllow- Determine if a non-matching address will be allowed by default- Returns:
- A new IP access control handler
-
acl
public static AccessControlListHandler acl(HttpHandler next, boolean defaultAllow, ExchangeAttribute attribute) Returns a new handler that can allow or deny access to a resource based an at attribute of the exchange- Parameters:
next- The next handler in the chaindefaultAllow- Determine if a non-matching user agent will be allowed by default- Returns:
- A new user agent access control handler
-
httpContinueRead
Deprecated.A handler that automatically handles HTTP 100-continue responses, by sending a continue response when the first attempt is made to read from the request channel. This handler is no longer required- Parameters:
next- The next handler in the chain- Returns:
- A new continue handler
-
urlDecoding
A handler that will decode the URL, query parameters and to the specified charset.If you are using this handler you must set the
UndertowOptions.DECODE_URLparameter to false.This is not as efficient as using the parsers built in UTF-8 decoder. Unless you need to decode to something other than UTF-8 you should rely on the parsers decoding instead.
- Parameters:
next- The next handler in the chaincharset- The charset to decode to- Returns:
- a new url decoding handler
-
setAttribute
public static SetAttributeHandler setAttribute(HttpHandler next, String attribute, String value, ClassLoader classLoader) Returns an attribute setting handler that can be used to set an arbitrary attribute on the exchange. This includes functions such as adding and removing headers etc.- Parameters:
next- The next handlerattribute- The attribute to set, specified as a string presentation of anExchangeAttributevalue- The value to set, specified an a string representation of anExchangeAttributeclassLoader- The class loader to use to parser the exchange attributes- Returns:
- The handler
-
rewrite
public static HttpHandler rewrite(String condition, String target, ClassLoader classLoader, HttpHandler next) Creates the set of handlers that are required to perform a simple rewrite.- Parameters:
condition- The rewrite conditiontarget- The rewrite target if the condition matchesnext- The next handler- Returns:
-
urlDecodingHandler
Returns a new handler that decodes the URL and query parameters into the specified charset, assuming it has not already been done by the connector. For this handler to take effect the parameterUndertowOptions.DECODE_URLmust have been set to false.- Parameters:
charset- The charset to decodenext- The next handler- Returns:
- A handler that decodes the URL
-
gracefulShutdown
Returns a new handler that can be used to wait for all requests to finish before shutting down the server gracefully.- Parameters:
next- The next http handler- Returns:
- The graceful shutdown handler
-
proxyPeerAddress
Returns a new handler that sets the peer address based on the X-Forwarded-For and X-Forwarded-Proto header- Parameters:
next- The next http handler- Returns:
- The handler
-
jvmRoute
Handler that appends the JVM route to the session cookie- Parameters:
sessionCookieName- The session cookie namejvmRoute- The JVM route to appendnext- The next handler- Returns:
- The handler
-
requestLimitingHandler
public static RequestLimitingHandler requestLimitingHandler(int maxRequest, int queueSize, HttpHandler next) Returns a handler that limits the maximum number of requests that can run at a time.- Parameters:
maxRequest- The maximum number of requestsqueueSize- The maximum number of queued requestsnext- The next handler- Returns:
- The handler
-
requestLimitingHandler
public static RequestLimitingHandler requestLimitingHandler(RequestLimit requestLimit, HttpHandler next) Returns a handler that limits the maximum number of requests that can run at a time.- Parameters:
requestLimit- The request limit object that can be shared between handlers, to apply the same limits across multiple handlersnext- The next handler- Returns:
- The handler
-
disableCache
Handler that sets the headers that disable caching of the response- Parameters:
next- The next handler- Returns:
- The handler
-
requestDump
Returns a handler that dumps requests to the log for debugging purposes.- Parameters:
next- The next handler- Returns:
- The request dumping handler
-
exceptionHandler
Returns a handler that maps exceptions to additional handlers- Parameters:
next- The next handler- Returns:
- The exception handler
-
responseRateLimitingHandler
public static ResponseRateLimitingHandler responseRateLimitingHandler(HttpHandler next, int bytes, long time, TimeUnit timeUnit) A handler that limits the download speed to a set number of bytes/period- Parameters:
next- The next handlerbytes- The number of bytes per time periodtime- The time periodtimeUnit- The units of the time period
-
handlerNotNull
-