Class RoutingContext
- java.lang.Object
-
- io.vertx.mutiny.ext.web.RoutingContext
-
public class RoutingContext extends Object
Represents the context for the handling of a request in Vert.x-Web.A new instance is created for each HTTP request that is received in the
Handler
of the router.The same instance is passed to any matching request or failure handlers during the routing of the request or failure.
The context provides access to the and and allows you to maintain arbitrary data that lives for the lifetime of the context. Contexts are discarded once they have been routed to the handler for the request.
The context also provides access to the
Session
, cookies and body for the request, given the correct handlers in the application.If you use the internal error handler
NOTE: This class has been automatically generated from theoriginal
non Mutiny-ified interface using Vert.x codegen.
-
-
Field Summary
Fields Modifier and Type Field Description static TypeArg<RoutingContext>
__TYPE_ARG
-
Constructor Summary
Constructors Constructor Description RoutingContext(io.vertx.ext.web.RoutingContext delegate)
RoutingContext(Object delegate)
-
Method Summary
-
-
-
Field Detail
-
__TYPE_ARG
public static final TypeArg<RoutingContext> __TYPE_ARG
-
-
Constructor Detail
-
RoutingContext
public RoutingContext(io.vertx.ext.web.RoutingContext delegate)
-
RoutingContext
public RoutingContext(Object delegate)
-
-
Method Detail
-
getDelegate
public io.vertx.ext.web.RoutingContext getDelegate()
-
request
public HttpServerRequest request()
- Returns:
- the HTTP request object
-
response
public HttpServerResponse response()
- Returns:
- the HTTP response object
-
next
public void next()
-
fail
public void fail(int statusCode)
- Parameters:
statusCode
- the HTTP status code
-
fail
public void fail(Throwable throwable)
- Parameters:
throwable
- a throwable representing the failure
-
fail
public void fail(int statusCode, Throwable throwable)
- Parameters:
statusCode
- the HTTP status codethrowable
- a throwable representing the failure
-
put
public RoutingContext put(String key, Object obj)
- Parameters:
key
- the key for the dataobj
- the data- Returns:
- a reference to this, so the API can be used fluently
-
get
public <T> T get(String key)
- Parameters:
key
- the key for the data- Returns:
- the data
-
get
public <T> T get(String key, T defaultValue)
- Parameters:
key
- the key for the datadefaultValue
- when the underlying data doesn't contain the key this will be the return value.- Returns:
- the data
-
remove
public <T> T remove(String key)
- Parameters:
key
- the key for the data- Returns:
- the previous data associated with the key
-
vertx
public Vertx vertx()
- Returns:
- the Vert.x instance associated to the initiating
Router
for this context
-
mountPoint
public String mountPoint()
- Returns:
- the mount point for this router. It will be null for a top level router. For a sub-router it will be the path at which the subrouter was mounted.
-
currentRoute
public Route currentRoute()
- Returns:
- the current route this context is being routed through.
-
normalisedPath
@Deprecated public String normalisedPath()
Deprecated.- Returns:
-
normalizedPath
public String normalizedPath()
- Returns:
- the normalized path
-
getCookie
public Cookie getCookie(String name)
- Parameters:
name
- the cookie name- Returns:
- the cookie
-
addCookie
public RoutingContext addCookie(Cookie cookie)
- Parameters:
cookie
- the cookie- Returns:
- a reference to this, so the API can be used fluently
-
removeCookie
public Cookie removeCookie(String name)
- Parameters:
name
- the name of the cookie- Returns:
- the cookie, if it existed, or null
-
removeCookie
public Cookie removeCookie(String name, boolean invalidate)
- Parameters:
name
- the name of the cookieinvalidate
-- Returns:
- the cookie, if it existed, or null
-
cookieCount
public int cookieCount()
- Returns:
- the number of cookies.
-
getBodyAsString
public String getBodyAsString()
- Returns:
- the entire HTTP request body as a string, assuming UTF-8 encoding if the request does not provide the content type charset attribute. If a charset is provided in the request that it shall be respected. The context must have first been routed to a
BodyHandler
for this to be populated.
-
getBodyAsString
public String getBodyAsString(String encoding)
- Parameters:
encoding
- the encoding, e.g. "UTF-16"- Returns:
- the body
-
getBodyAsJson
public io.vertx.core.json.JsonObject getBodyAsJson(int maxAllowedLength)
- Parameters:
maxAllowedLength
- if the current buffer length is greater than the limit anIllegalStateException
is thrown. This can be used to avoid DDoS attacks on very long JSON payloads that could take over the CPU while attempting to parse the data.- Returns:
- Get the entire HTTP request body as a . The context must have first been routed to a
BodyHandler
for this to be populated.
When the body isnull
or the"null"
JSON literal thennull
is returned.
-
getBodyAsJsonArray
public io.vertx.core.json.JsonArray getBodyAsJsonArray(int maxAllowedLength)
- Parameters:
maxAllowedLength
- if the current buffer length is greater than the limit anIllegalStateException
is thrown. This can be used to avoid DDoS attacks on very long JSON payloads that could take over the CPU while attempting to parse the data.- Returns:
- Get the entire HTTP request body as a . The context must have first been routed to a
BodyHandler
for this to be populated.
When the body isnull
or the"null"
JSON literal thennull
is returned.
-
getBodyAsJson
public io.vertx.core.json.JsonObject getBodyAsJson()
- Returns:
- Get the entire HTTP request body as a . The context must have first been routed to a
BodyHandler
for this to be populated.
When the body isnull
or the"null"
JSON literal thennull
is returned.
-
getBodyAsJsonArray
public io.vertx.core.json.JsonArray getBodyAsJsonArray()
- Returns:
- Get the entire HTTP request body as a . The context must have first been routed to a
BodyHandler
for this to be populated.
When the body isnull
or the"null"
JSON literal thennull
is returned.
-
getBody
public Buffer getBody()
- Returns:
- Get the entire HTTP request body as a . The context must have first been routed to a
BodyHandler
for this to be populated.
-
fileUploads
public Set<FileUpload> fileUploads()
- Returns:
- a set of fileuploads (if any) for the request. The context must have first been routed to a
BodyHandler
for this to work.
-
session
public Session session()
- Returns:
- the session.
-
isSessionAccessed
public boolean isSessionAccessed()
- Returns:
- true if the session has been accessed.
-
user
public User user()
- Returns:
- the user, or null if the current user is not authenticated.
-
failure
public Throwable failure()
- Returns:
- the throwable used when signalling failure
-
statusCode
public int statusCode()
- Returns:
- the status code used when signalling failure
-
getAcceptableContentType
public String getAcceptableContentType()
- Returns:
- the most acceptable content type.
-
parsedHeaders
public ParsedHeaderValues parsedHeaders()
- Returns:
- A container with the parsed headers.
-
addHeadersEndHandler
public int addHeadersEndHandler(Runnable handler)
- Parameters:
handler
- the handler- Returns:
-
removeHeadersEndHandler
public boolean removeHeadersEndHandler(int handlerID)
- Parameters:
handlerID
- the id as returned fromaddHeadersEndHandler(java.lang.Runnable)
.- Returns:
- true if the handler existed and was removed, false otherwise
-
addBodyEndHandler
public int addBodyEndHandler(Runnable handler)
- Parameters:
handler
- the handler- Returns:
-
removeBodyEndHandler
public boolean removeBodyEndHandler(int handlerID)
- Parameters:
handlerID
- the id as returned fromaddBodyEndHandler(java.lang.Runnable)
.- Returns:
- true if the handler existed and was removed, false otherwise
-
addEndHandler
public io.smallrye.mutiny.Uni<Void> addEndHandler()
Add an end handler for the request/response context. This will be called when the response is disposed or an exception has been encountered to allow consistent cleanup. The handler is called asynchronously of when the response has been received by the client.Unlike the bare Vert.x variant, this method returns a
Uni
. Don't forget to subscribe on it to trigger the operation.- Returns:
- the
uni
firing the result of the operation when completed, or a failure if the operation failed.
-
addEndHandlerAndAwait
public Void addEndHandlerAndAwait()
Blocking variant ofaddEndHandler()
.This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
- Returns:
- the Void instance produced by the operation.
-
addEndHandlerAndForget
public void addEndHandlerAndForget()
Variant ofaddEndHandler()
that ignores the result of the operation.This method subscribes on the result of
addEndHandler()
, but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation fromaddEndHandler()
but you don't need to compose it with other operations.
-
removeEndHandler
public boolean removeEndHandler(int handlerID)
- Parameters:
handlerID
- the id as returned fromaddEndHandler()
.- Returns:
- true if the handler existed and was removed, false otherwise
-
failed
public boolean failed()
- Returns:
- true if the context is being routed to failure handlers.
-
setBody
public void setBody(Buffer body)
- Parameters:
body
- the body
-
setSession
public void setSession(Session session)
- Parameters:
session
- the session
-
setUser
public void setUser(User user)
- Parameters:
user
- the user
-
clearUser
public void clearUser()
-
setAcceptableContentType
public void setAcceptableContentType(String contentType)
- Parameters:
contentType
- the content type
-
reroute
public void reroute(String path)
- Parameters:
path
- the new http path.
-
reroute
public void reroute(io.vertx.core.http.HttpMethod method, String path)
- Parameters:
method
- the new http requestpath
- the new http path.
-
acceptableLanguages
public List<LanguageHeader> acceptableLanguages()
- Returns:
- The best matched language for the request
-
preferredLanguage
public LanguageHeader preferredLanguage()
- Returns:
- the users preferred locale.
-
pathParam
public String pathParam(String name)
- Parameters:
name
- the name of parameter as defined in path declaration- Returns:
- the actual value of the parameter or null if it doesn't exist
-
queryParams
public MultiMap queryParams()
- Returns:
- the multimap of query parameters
-
queryParam
public List<String> queryParam(String name)
- Parameters:
name
- The name of query parameter- Returns:
- The list of all parameters matching the parameter name. It returns an empty list if no query parameter with
name
was found
-
attachment
public RoutingContext attachment(String filename)
- Parameters:
filename
- the filename for the attachment- Returns:
- the instance of RoutingContext to chain method calls.
-
redirect
public io.smallrye.mutiny.Uni<Void> redirect(String url)
Seeredirect(java.lang.String)
.Unlike the bare Vert.x variant, this method returns a
Uni
. Don't forget to subscribe on it to trigger the operation.- Parameters:
url
-- Returns:
- the
uni
firing the result of the operation when completed, or a failure if the operation failed.
-
redirectAndAwait
public Void redirectAndAwait(String url)
Blocking variant ofredirect(String)
.This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
- Parameters:
url
-- Returns:
- the Void instance produced by the operation.
-
redirectAndForget
public RoutingContext redirectAndForget(String url)
Variant ofredirect(String)
that ignores the result of the operation.This method subscribes on the result of
redirect(String)
, but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation fromredirect(String)
but you don't need to compose it with other operations.- Parameters:
url
-- Returns:
- the instance of RoutingContext to chain method calls.
-
json
public io.smallrye.mutiny.Uni<Void> json(Object json)
Seejson(java.lang.Object)
.Unlike the bare Vert.x variant, this method returns a
Uni
. Don't forget to subscribe on it to trigger the operation.- Parameters:
json
-- Returns:
- the
uni
firing the result of the operation when completed, or a failure if the operation failed.
-
jsonAndAwait
public Void jsonAndAwait(Object json)
Blocking variant ofjson(Object)
.This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
- Parameters:
json
-- Returns:
- the Void instance produced by the operation.
-
jsonAndForget
public RoutingContext jsonAndForget(Object json)
Variant ofjson(Object)
that ignores the result of the operation.This method subscribes on the result of
json(Object)
, but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation fromjson(Object)
but you don't need to compose it with other operations.- Parameters:
json
-- Returns:
- the instance of RoutingContext to chain method calls.
-
is
public boolean is(String type)
- Parameters:
type
- content type- Returns:
- The most close value
-
isFresh
public boolean isFresh()
- Returns:
- true if content is fresh according to the cache.
-
etag
public RoutingContext etag(String etag)
- Parameters:
etag
- the etag value- Returns:
- the instance of RoutingContext to chain method calls.
-
lastModified
public RoutingContext lastModified(String instant)
- Parameters:
instant
- the last modified instant- Returns:
- the instance of RoutingContext to chain method calls.
-
end
public io.smallrye.mutiny.Uni<Void> end(String chunk)
Seeend(java.lang.String)
Unlike the bare Vert.x variant, this method returns a
Uni
. Don't forget to subscribe on it to trigger the operation.- Parameters:
chunk
-- Returns:
- the
uni
firing the result of the operation when completed, or a failure if the operation failed.
-
endAndAwait
public Void endAndAwait(String chunk)
Blocking variant ofend(String)
.This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
- Parameters:
chunk
-- Returns:
- the Void instance produced by the operation.
-
endAndForget
public RoutingContext endAndForget(String chunk)
Variant ofend(String)
that ignores the result of the operation.This method subscribes on the result of
end(String)
, but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation fromend(String)
but you don't need to compose it with other operations.- Parameters:
chunk
-- Returns:
- the instance of RoutingContext to chain method calls.
-
end
public io.smallrye.mutiny.Uni<Void> end(Buffer buffer)
Seeend(java.lang.String)
Unlike the bare Vert.x variant, this method returns a
Uni
. Don't forget to subscribe on it to trigger the operation.- Parameters:
buffer
-- Returns:
- the
uni
firing the result of the operation when completed, or a failure if the operation failed.
-
endAndAwait
public Void endAndAwait(Buffer buffer)
Blocking variant ofend(io.vertx.mutiny.core.buffer.Buffer)
.This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
- Parameters:
buffer
-- Returns:
- the Void instance produced by the operation.
-
endAndForget
public RoutingContext endAndForget(Buffer buffer)
Variant ofend(io.vertx.mutiny.core.buffer.Buffer)
that ignores the result of the operation.This method subscribes on the result of
end(io.vertx.mutiny.core.buffer.Buffer)
, but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation fromend(io.vertx.mutiny.core.buffer.Buffer)
but you don't need to compose it with other operations.- Parameters:
buffer
-- Returns:
- the instance of RoutingContext to chain method calls.
-
end
public io.smallrye.mutiny.Uni<Void> end()
Seeend(java.lang.String)
Unlike the bare Vert.x variant, this method returns a
Uni
. Don't forget to subscribe on it to trigger the operation.- Returns:
- the
uni
firing the result of the operation when completed, or a failure if the operation failed.
-
endAndAwait
public Void endAndAwait()
Blocking variant ofend(java.lang.String)
.This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
- Returns:
- the Void instance produced by the operation.
-
endAndForget
public RoutingContext endAndForget()
Variant ofend(java.lang.String)
that ignores the result of the operation.This method subscribes on the result of
end(java.lang.String)
, but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation fromend(java.lang.String)
but you don't need to compose it with other operations.- Returns:
- the instance of RoutingContext to chain method calls.
-
queryParams
public MultiMap queryParams(Charset encoding)
- Parameters:
encoding
- a non null character set.- Returns:
- the multimap of query parameters
-
lastModified
public RoutingContext lastModified(Instant instant)
- Parameters:
instant
- the last modified instant- Returns:
- the instance of RoutingContext to chain method calls.
-
newInstance
public static RoutingContext newInstance(io.vertx.ext.web.RoutingContext arg)
-
-