Class RoutingContext
- All Implemented Interfaces:
MutinyDelegate
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 -
Constructor Summary
ConstructorsConstructorDescriptionRoutingContext
(io.vertx.ext.web.RoutingContext delegate) RoutingContext
(Object delegate) -
Method Summary
Modifier and TypeMethodDescriptionint
addBodyEndHandler
(Runnable handler) Deprecated.io.smallrye.mutiny.Uni<Void>
Add an end handler for the request/response context.Blocking variant ofaddEndHandler()
.void
Variant ofaddEndHandler()
that ignores the result of the operation.int
addHeadersEndHandler
(Runnable handler) attachment
(String filename) body()
void
void
Deprecated.instead useUserContext.logout()
int
Deprecated.UseHttpServerRequest#cookieCount()
Deprecated.UseHttpServerRequest#cookieMap()
data()
io.smallrye.mutiny.Uni<Void>
end()
io.smallrye.mutiny.Uni<Void>
io.smallrye.mutiny.Uni<Void>
Blocking variant ofend(java.lang.String)
.endAndAwait
(Buffer buffer) Blocking variant ofend(io.vertx.mutiny.core.buffer.Buffer)
.endAndAwait
(String chunk) Blocking variant ofend(String)
.Variant ofend(java.lang.String)
that ignores the result of the operation.endAndForget
(Buffer buffer) Variant ofend(io.vertx.mutiny.core.buffer.Buffer)
that ignores the result of the operation.endAndForget
(String chunk) Variant ofend(String)
that ignores the result of the operation.boolean
void
fail
(int statusCode) void
void
boolean
failed()
failure()
<T> T
<T> T
getBody()
Deprecated.Usebody()
instead.io.vertx.core.json.JsonObject
Deprecated.Usebody()
instead.io.vertx.core.json.JsonObject
getBodyAsJson
(int maxAllowedLength) Deprecated.Usebody()
instead.io.vertx.core.json.JsonArray
Deprecated.Usebody()
instead.io.vertx.core.json.JsonArray
getBodyAsJsonArray
(int maxAllowedLength) Deprecated.Usebody()
instead.Deprecated.Usebody()
instead.getBodyAsString
(String encoding) Deprecated.Usebody()
instead.Deprecated.UseHttpServerRequest#getCookie(String)
Get the cookie with the specified name.io.vertx.ext.web.RoutingContext
int
hashCode()
boolean
boolean
isFresh()
boolean
io.smallrye.mutiny.Uni<Void>
jsonAndAwait
(Object json) Blocking variant ofjson(Object)
.jsonAndForget
(Object json) Variant ofjson(Object)
that ignores the result of the operation.lastModified
(String instant) lastModified
(Instant instant) static RoutingContext
newInstance
(io.vertx.ext.web.RoutingContext arg) void
next()
Deprecated.queryParam
(String name) queryParams
(Charset encoding) io.smallrye.mutiny.Uni<Void>
redirectAndAwait
(String url) Blocking variant ofredirect(String)
.redirectAndForget
(String url) Variant ofredirect(String)
that ignores the result of the operation.<T> T
boolean
removeBodyEndHandler
(int handlerID) removeCookie
(String name) Deprecated.UseHttpServerResponse#removeCookie(String)
Expire a cookie, notifying a User Agent to remove it from its cookie jar.removeCookie
(String name, boolean invalidate) Deprecated.UseHttpServerResponse#removeCookie(String, boolean)
Remove a cookie from the cookie set.boolean
removeEndHandler
(int handlerID) boolean
removeHeadersEndHandler
(int handlerID) request()
void
void
response()
session()
void
setAcceptableContentType
(String contentType) void
Deprecated.This method is internal.void
setSession
(Session session) Deprecated.This method is internal.void
Deprecated.this method should not be called, application authentication should rely onAuthenticationHandler
implementations.int
toString()
user()
vertx()
-
Field Details
-
__TYPE_ARG
-
-
Constructor Details
-
RoutingContext
public RoutingContext(io.vertx.ext.web.RoutingContext delegate) -
RoutingContext
-
-
Method Details
-
getDelegate
public io.vertx.ext.web.RoutingContext getDelegate()- Specified by:
getDelegate
in interfaceMutinyDelegate
- Returns:
- the delegate used by this Mutiny object of generated type
-
toString
-
equals
-
hashCode
public int hashCode() -
request
- Returns:
- the HTTP request object
-
response
- Returns:
- the HTTP response object
-
next
public void next() -
fail
public void fail(int statusCode) - Parameters:
statusCode
- the HTTP status code
-
fail
- Parameters:
throwable
- a throwable representing the failure
-
fail
- Parameters:
statusCode
- the HTTP status codethrowable
- a throwable representing the failure
-
put
- Parameters:
key
- the key for the dataobj
- the data- Returns:
- a reference to this, so the API can be used fluently
-
get
- Parameters:
key
- the key for the data- Returns:
- the data
-
get
- 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
- Parameters:
key
- the key for the data- Returns:
- the previous data associated with the key
-
vertx
- Returns:
- the Vert.x instance associated to the initiating
Router
for this context
-
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
- Returns:
- the current route this context is being routed through.
-
normalisedPath
Deprecated.- Returns:
-
normalizedPath
- Returns:
- normalized path
-
getCookie
Deprecated.UseHttpServerRequest#getCookie(String)
Get the cookie with the specified name.- Parameters:
name
- the cookie name- Returns:
- the cookie
-
addCookie
Deprecated.UseHttpServerResponse#addCookie(Cookie)
Add a cookie. This will be sent back to the client in the response.- Parameters:
cookie
- the cookie- Returns:
- a reference to this, so the API can be used fluently
-
removeCookie
Deprecated.UseHttpServerResponse#removeCookie(String)
Expire a cookie, notifying a User Agent to remove it from its cookie jar.- Parameters:
name
- the name of the cookie- Returns:
- the cookie, if it existed, or null
-
removeCookie
Deprecated.UseHttpServerResponse#removeCookie(String, boolean)
Remove a cookie from the cookie set. If invalidate is true then it will expire a cookie, notifying a User Agent to remove it from its cookie jar.- Parameters:
name
- the name of the cookieinvalidate
-- Returns:
- the cookie, if it existed, or null
-
cookieCount
Deprecated.UseHttpServerRequest#cookieCount()
- Returns:
- the number of cookies.
-
cookieMap
Deprecated.UseHttpServerRequest#cookieMap()
- Returns:
- a map of all the cookies.
-
getBodyAsString
Deprecated.Usebody()
instead.- 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
Deprecated.Usebody()
instead. Get the entire HTTP request body as a string, assuming the specified encoding. The context must have first been routed to aBodyHandler
for this to be populated.- Parameters:
encoding
- the encoding, e.g. "UTF-16"- Returns:
- the body
-
getBodyAsJson
Deprecated.Usebody()
instead. Gets the current body buffer as aJsonObject
. If a positive limit is provided the parsing will only happen if the buffer length is smaller or equal to the limit. Otherwise anIllegalStateException
is thrown. When the application is only handling uploads in JSON format, it is recommended to set a limit onBodyHandler.setBodyLimit(long)
as this will avoid the upload to be parsed and loaded into the application memory.- 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
Deprecated.Usebody()
instead. Gets the current body buffer as aJsonArray
. If a positive limit is provided the parsing will only happen if the buffer length is smaller or equal to the limit. Otherwise anIllegalStateException
is thrown. When the application is only handling uploads in JSON format, it is recommended to set a limit onBodyHandler.setBodyLimit(long)
as this will avoid the upload to be parsed and loaded into the application memory.- 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
Deprecated.Usebody()
instead.- 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
Deprecated.Usebody()
instead.- 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
Deprecated.Usebody()
instead.- Returns:
- Get the entire HTTP request body as a . The context must have first been routed to a
BodyHandler
for this to be populated.
-
body
-
fileUploads
- Returns:
- a list of
FileUpload
(if any) for the request. The context must have first been routed to aBodyHandler
for this to work.
-
cancelAndCleanupFileUploads
public void cancelAndCleanupFileUploads() -
session
- Returns:
- the session.
-
isSessionAccessed
public boolean isSessionAccessed()- Returns:
- true if the session has been accessed.
-
user
- Returns:
- the user, or null if the current user is not authenticated.
-
userContext
- Returns:
- the user context
-
failure
- Returns:
- the throwable used when signalling failure
-
statusCode
public int statusCode()- Returns:
- the status code used when signalling failure
-
getAcceptableContentType
- Returns:
- the most acceptable content type.
-
parsedHeaders
- Returns:
- A container with the parsed headers.
-
addHeadersEndHandler
- 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
- 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
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
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
Deprecated.This method is internal. Users that really need to use it should refer toRoutingContextInternal.setBody(Buffer)
Set the body. Used by theBodyHandler
. You will not normally call this method.- Parameters:
body
- the body
-
setSession
Deprecated.This method is internal. Users that really need to use it should refer toio.vertx.ext.web.impl.RoutingContextInternal#setSession(Session)
Set the session. Used by theSessionHandler
. You will not normally call this method.- Parameters:
session
- the session
-
setUser
Deprecated.this method should not be called, application authentication should rely onAuthenticationHandler
implementations.- Parameters:
user
- the user
-
clearUser
Deprecated.instead useUserContext.logout()
-
setAcceptableContentType
- Parameters:
contentType
- the content type
-
reroute
- Parameters:
path
- the new http path.
-
reroute
- Parameters:
method
- the new http requestpath
- the new http path.
-
acceptableLanguages
- Returns:
- The best matched language for the request
-
preferredLanguage
- Returns:
- the users preferred locale.
-
pathParams
- Returns:
- the map of named parameters
-
pathParam
- 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
- Returns:
- the multimap of query parameters
-
queryParam
- 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
- Parameters:
filename
- the filename for the attachment- Returns:
- the instance of RoutingContext to chain method calls.
-
redirect
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
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
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
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
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
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
- Parameters:
type
- content type- Returns:
- The most close value
-
isFresh
public boolean isFresh()- Returns:
- true if content is fresh according to the cache.
-
etag
- Parameters:
etag
- the etag value- Returns:
- the instance of RoutingContext to chain method calls.
-
lastModified
- Parameters:
instant
- the last modified instant- Returns:
- the instance of RoutingContext to chain method calls.
-
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.- Parameters:
chunk
-- Returns:
- the
uni
firing the result of the operation when completed, or a failure if the operation failed.
-
endAndAwait
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
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
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
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
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
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
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
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.
-
data
- Returns:
- all the context data as a map
-
queryParams
- Parameters:
encoding
- a non null character set.- Returns:
- the multimap of query parameters
-
lastModified
- Parameters:
instant
- the last modified instant- Returns:
- the instance of RoutingContext to chain method calls.
-
newInstance
-
HttpServerResponse#addCookie(Cookie)
Add a cookie.