Top Description Fields Constructors Methods
io.undertow.server.handlers

public Class PathHandler

extends Object
implements HttpHandler
Class Inheritance
All Implemented Interfaces
io.undertow.server.HttpHandler
Imports
io.undertow.Handlers, io.undertow.server.HttpHandler, .HttpServerExchange, io.undertow.server.handlers.cache.LRUCache, io.undertow.util.PathMatcher, java.util.Map.Entry, .Set, java.util.stream.Collectors

Handler that dispatches to a given handler based of a prefix match of the path.

This only matches a single level of a request, e.g if you have a request that takes the form:

/foo/bar

Author
Stuart Douglas

Field Summary

Modifier and TypeField and Description
private final LRUCache<String, PathMatcher.PathMatch<HttpHandler>>
private final PathMatcher<HttpHandler>

Constructor Summary

AccessConstructor and Description
public
PathHandler(final HttpHandler defaultHandler)

public
PathHandler(final HttpHandler defaultHandler, int cacheSize)

public
public
PathHandler(int cacheSize)

Method Summary

Modifier and TypeMethod and Description
public synchronized PathHandler

Returns:

The resulting PathHandler after this path has been added to it.
addExactPath
(final String
If the request path is exactly this, run handler.
path
,
final HttpHandler
Handler run upon exact path match.
handler
)

If the request path is exactly equal to the given path, run the handler.

public synchronized PathHandler
addPath(final String
The path
path
,
final HttpHandler
The handler
handler
)
Deprecated for removal since 1.0.0. Superseded by addPrefixPath(String, io.undertow.server.HttpHandler).

Adds a path prefix and a handler for that path.

public synchronized PathHandler

Returns:

The resulting PathHandler after this path has been added to it.
addPrefixPath
(final String
If the request contains this prefix, run handler.
path
,
final HttpHandler
The handler which is activated upon match.
handler
)

Adds a path prefix and a handler for that path.

public synchronized PathHandler
public void
handleRequest(HttpServerExchange
the HTTP request/response exchange
exchange
)

Implements io.undertow.server.HttpHandler.handleRequest.

Handle the request.

public synchronized PathHandler
removeExactPath(final String path)

public synchronized PathHandler
removePath(final String path)
Deprecated

public synchronized PathHandler
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

cacheback to summary
private final LRUCache<String, PathMatcher.PathMatch<HttpHandler>> cache
pathMatcherback to summary
private final PathMatcher<HttpHandler> pathMatcher

Constructor Detail

PathHandlerback to summary
public PathHandler(final HttpHandler defaultHandler)
PathHandlerback to summary
public PathHandler(final HttpHandler defaultHandler, int cacheSize)
PathHandlerback to summary
public PathHandler()
PathHandlerback to summary
public PathHandler(int cacheSize)

Method Detail

addExactPathback to summary
public synchronized PathHandler addExactPath(final String path, final HttpHandler handler)

If the request path is exactly equal to the given path, run the handler.

Exact paths are prioritized higher than prefix paths.

Parameters
path:String

If the request path is exactly this, run handler.

handler:HttpHandler

Handler run upon exact path match.

Returns:PathHandler

The resulting PathHandler after this path has been added to it.

addPathback to summary
public synchronized PathHandler addPath(final String path, final HttpHandler handler)

Deprecated

for removal since 1.0.0.

Superseded by addPrefixPath(String, io.undertow.server.HttpHandler).

Adds a path prefix and a handler for that path. If the path does not start with a / then one will be prepended.

The match is done on a prefix bases, so registering /foo will also match /foo/bar. Exact path matches are taken into account first.

If / is specified as the path then it will replace the default handler.

Parameters
path:String

The path

handler:HttpHandler

The handler

Annotations
@Deprecated
since:1.0.0
forRemoval:true
See Also
addPrefixPath(String, io.undertow.server.HttpHandler)
addPrefixPathback to summary
public synchronized PathHandler addPrefixPath(final String path, final HttpHandler handler)

Adds a path prefix and a handler for that path. If the path does not start with a / then one will be prepended.

The match is done on a prefix bases, so registering /foo will also match /foo/bar. Though exact path matches are taken into account before prefix path matches. So if an exact path match exists its handler will be triggered.

If / is specified as the path then it will replace the default handler.

Parameters
path:String

If the request contains this prefix, run handler.

handler:HttpHandler

The handler which is activated upon match.

Returns:PathHandler

The resulting PathHandler after this path has been added to it.

clearPathsback to summary
public synchronized PathHandler clearPaths()
handleRequestback to summary
public void handleRequest(HttpServerExchange exchange) throws Exception

Implements io.undertow.server.HttpHandler.handleRequest.

Doc from io.undertow.server.HttpHandler.handleRequest.

Handle the request.

Parameters
exchange:HttpServerExchange

the HTTP request/response exchange

Annotations
@Override
removeExactPathback to summary
public synchronized PathHandler removeExactPath(final String path)
removePathback to summary
public synchronized PathHandler removePath(final String path)

Deprecated

Annotations
@Deprecated
removePrefixPathback to summary
public synchronized PathHandler removePrefixPath(final String path)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override