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
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description List<LanguageHeader>
acceptableLanguages()
int
addBodyEndHandler(Runnable handler)
RoutingContext
addCookie(Cookie cookie)
Deprecated.UseHttpServerResponse#addCookie(Cookie)
Add a cookie.io.smallrye.mutiny.Uni<Void>
addEndHandler()
Add an end handler for the request/response context.Void
addEndHandlerAndAwait()
Blocking variant ofaddEndHandler()
.void
addEndHandlerAndForget()
Variant ofaddEndHandler()
that ignores the result of the operation.int
addHeadersEndHandler(Runnable handler)
RoutingContext
attachment(String filename)
RequestBody
body()
void
clearUser()
int
cookieCount()
Deprecated.UseHttpServerRequest#cookieCount()
Map<String,Cookie>
cookieMap()
Deprecated.UseHttpServerRequest#cookieMap()
Route
currentRoute()
Map<String,Object>
data()
io.smallrye.mutiny.Uni<Void>
end()
io.smallrye.mutiny.Uni<Void>
end(Buffer buffer)
io.smallrye.mutiny.Uni<Void>
end(String chunk)
Void
endAndAwait()
Blocking variant ofend(java.lang.String)
.Void
endAndAwait(Buffer buffer)
Blocking variant ofend(io.vertx.mutiny.core.buffer.Buffer)
.Void
endAndAwait(String chunk)
Blocking variant ofend(String)
.RoutingContext
endAndForget()
Variant ofend(java.lang.String)
that ignores the result of the operation.RoutingContext
endAndForget(Buffer buffer)
Variant ofend(io.vertx.mutiny.core.buffer.Buffer)
that ignores the result of the operation.RoutingContext
endAndForget(String chunk)
Variant ofend(String)
that ignores the result of the operation.boolean
equals(Object o)
RoutingContext
etag(String etag)
void
fail(int statusCode)
void
fail(int statusCode, Throwable throwable)
void
fail(Throwable throwable)
boolean
failed()
Throwable
failure()
List<FileUpload>
fileUploads()
<T> T
get(String key)
<T> T
get(String key, T defaultValue)
String
getAcceptableContentType()
Buffer
getBody()
Deprecated.Usebody()
instead.io.vertx.core.json.JsonObject
getBodyAsJson()
Deprecated.Usebody()
instead.io.vertx.core.json.JsonObject
getBodyAsJson(int maxAllowedLength)
Deprecated.Usebody()
instead.io.vertx.core.json.JsonArray
getBodyAsJsonArray()
Deprecated.Usebody()
instead.io.vertx.core.json.JsonArray
getBodyAsJsonArray(int maxAllowedLength)
Deprecated.Usebody()
instead.String
getBodyAsString()
Deprecated.Usebody()
instead.String
getBodyAsString(String encoding)
Deprecated.Usebody()
instead.Cookie
getCookie(String name)
Deprecated.UseHttpServerRequest#getCookie(String)
Get the cookie with the specified name.io.vertx.ext.web.RoutingContext
getDelegate()
int
hashCode()
boolean
is(String type)
boolean
isFresh()
boolean
isSessionAccessed()
io.smallrye.mutiny.Uni<Void>
json(Object json)
Void
jsonAndAwait(Object json)
Blocking variant ofjson(Object)
.RoutingContext
jsonAndForget(Object json)
Variant ofjson(Object)
that ignores the result of the operation.RoutingContext
lastModified(String instant)
RoutingContext
lastModified(Instant instant)
String
mountPoint()
static RoutingContext
newInstance(io.vertx.ext.web.RoutingContext arg)
void
next()
String
normalisedPath()
Deprecated.String
normalizedPath()
ParsedHeaderValues
parsedHeaders()
String
pathParam(String name)
Map<String,String>
pathParams()
LanguageHeader
preferredLanguage()
RoutingContext
put(String key, Object obj)
List<String>
queryParam(String name)
MultiMap
queryParams()
MultiMap
queryParams(Charset encoding)
io.smallrye.mutiny.Uni<Void>
redirect(String url)
Void
redirectAndAwait(String url)
Blocking variant ofredirect(String)
.RoutingContext
redirectAndForget(String url)
Variant ofredirect(String)
that ignores the result of the operation.<T> T
remove(String key)
boolean
removeBodyEndHandler(int handlerID)
Cookie
removeCookie(String name)
Deprecated.UseHttpServerResponse#removeCookie(String)
Expire a cookie, notifying a User Agent to remove it from its cookie jar.Cookie
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)
HttpServerRequest
request()
void
reroute(io.vertx.core.http.HttpMethod method, String path)
void
reroute(String path)
HttpServerResponse
response()
Session
session()
void
setAcceptableContentType(String contentType)
void
setBody(Buffer body)
Deprecated.This method is internal.void
setSession(Session session)
Deprecated.This method is internal.void
setUser(User user)
int
statusCode()
String
toString()
User
user()
Vertx
vertx()
-
-
-
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
@Deprecated public Cookie getCookie(String name)
Deprecated.UseHttpServerRequest#getCookie(String)
Get the cookie with the specified name.- Parameters:
name
- the cookie name- Returns:
- the cookie
-
addCookie
@Deprecated public RoutingContext addCookie(Cookie cookie)
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 public Cookie removeCookie(String name)
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 public Cookie removeCookie(String name, boolean invalidate)
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 public int cookieCount()
Deprecated.UseHttpServerRequest#cookieCount()
- Returns:
- the number of cookies.
-
cookieMap
@Deprecated public Map<String,Cookie> cookieMap()
Deprecated.UseHttpServerRequest#cookieMap()
- Returns:
- a map of all the cookies.
-
getBodyAsString
@Deprecated public String 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 public String getBodyAsString(String encoding)
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 public io.vertx.core.json.JsonObject getBodyAsJson(int maxAllowedLength)
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 public io.vertx.core.json.JsonArray getBodyAsJsonArray(int maxAllowedLength)
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 public io.vertx.core.json.JsonObject 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 public io.vertx.core.json.JsonArray 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 public Buffer 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
public RequestBody body()
-
fileUploads
public List<FileUpload> fileUploads()
- Returns:
- a list of
FileUpload
(if any) for the request. The context must have first been routed to aBodyHandler
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
@CheckReturnValue 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
@Deprecated public void setBody(Buffer body)
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 public void setSession(Session session)
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
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
@CheckReturnValue 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
@CheckReturnValue 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
@CheckReturnValue 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
@CheckReturnValue 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
@CheckReturnValue 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)
-
-