Interface Request
- Since:
- 2.1.0
-
Method Summary
Modifier and TypeMethodDescriptionGets the acceptable media types for the request.Get the body of this Request.Get the IP address of the caller.getFormParameterValueOrError(String formParameterName) Get a form-parameter, as passed in the post body of a POST form request.getFormParameterValueOrError(String formParameterName, Function<String, ? extends RuntimeException> exceptionSupplier) Get a form-parameter, as passed in the post body of a POST form request.getFormParameterValues(String formParameterName) Get a form-parameter, as passed in the post body of a POST form request, or an empty Collection if the form-parameter was not provided.Get theHttpHeadersof the request.Get the HTTP method used by this Request.getParameterValueOrError(String parameterName) Get the value for a parameter.getParameterValueOrError(String parameterName, Function<String, ? extends RuntimeException> exceptionSupplier) Get the value for a parameter.getParameterValues(String parameterName) Get all values for a parameter.getPath()Get the path of the requested resource.Get aSetof all query parameter names.getQueryParameterValueOrError(String queryParameterName, Function<String, ? extends RuntimeException> exceptionSupplier) Get a query-parameter, as passed in the query string of a request.getQueryParameterValues(String queryParameterName) Get a query-parameter, as passed in the query string of a request, or an empty Collection if the query-parameter was not provided.Gets the encoded version of the query string or null if the request did not contain one.Get the scheme used for this request.getUrl()Get the full URL used in this request.booleanReturns true if there's a session associated with this request, false otherwise.booleanReturns true if this request uses the GET- or HEAD method, false otherwise.booleanReturns true if this request uses the HEAD method, false otherwise.booleanReturns true if this request uses the POST method, false otherwise.
-
Method Details
-
getParameterValueOrError
Get the value for a parameter.The parameter may be provided in the query string or in the form body (in case this is a form POST request).
If more than one value is found for this parameter, a default error is thrown (use the
getParameterValueOrError(String, Function)method if a custom error is desirable).If no value is found, null is returned.
Warning: When including a parameter in the response, attributes, and/or token, the client should verify that the provided value is included as expected.
- Parameters:
parameterName- name of parameter to look up- Returns:
- value of parameter, or null when no value was provided
- Throws:
RuntimeException- if several values were provided for this parameter
-
getParameterValueOrError
@Nullable @Nullable String getParameterValueOrError(String parameterName, Function<String, ? extends RuntimeException> exceptionSupplier) Get the value for a parameter.The parameter may be provided in the query string or in the form body (in case this is a form POST request).
If more than one value is found for this parameter, the error provided by the
exceptionSupplieris thrown.If no value is found, null is returned.
Warning: When including a parameter in the response, attributes, and/or token, the client should verify that the provided value is included as expected.
- Parameters:
parameterName- name of parameter to look upexceptionSupplier- a supplier of the exception to be thrown when multiple values are found for the parameter- Returns:
- value of parameter, or null when no value was provided
- Throws:
RuntimeException- if several values were provided for this parameter
-
getParameterValues
Get all values for a parameter.The parameter may be provided in the query string or in the form body (in case this is a form POST request).
If the parameter does not exist, an empty Collection is returned.
Warning: When including a parameter in the response, attributes, and/or token, the client should verify that the provided value is included as expected.
- Parameters:
parameterName- name of parameter to look up in the query String or form- Returns:
- values of parameter in the query String, or an empty collection when no value was provided
- See Also:
-
getFormParameterValues
Get a form-parameter, as passed in the post body of a POST form request, or an empty Collection if the form-parameter was not provided.Warning: When including a form parameter in the response, attributes, and/or token, the client should verify that the provided value is included as expected.
- Parameters:
formParameterName- name of parameter to look up in form data- Returns:
- values of the parameter in the form data
- See Also:
-
getFormParameterValueOrError
@Nullable @Nullable String getFormParameterValueOrError(String formParameterName, Function<String, ? extends RuntimeException> exceptionSupplier) Get a form-parameter, as passed in the post body of a POST form request.If more than one value is found for this parameter, the error provided by the
exceptionSupplieris thrown.If no value is found, null is returned.
Warning: When including a form parameter in the response, attributes, and/or token, the client should verify that the provided value is included as expected.
- Parameters:
formParameterName- name of parameter to look up in form dataexceptionSupplier- a supplier of the exception to be thrown when multiple values are found for the parameter- Returns:
- value of parameter, or null when no value was provided
- Throws:
RuntimeException- if several values were provided for this parameter- See Also:
-
getFormParameterValueOrError
Get a form-parameter, as passed in the post body of a POST form request.If more than one value is found for this parameter, a default error is thrown (use the
getFormParameterValueOrError(String, Function)method if a custom error is desirable).If no value is found, null is returned.
Warning: When including a form parameter in the response, attributes, and/or token, the client should verify that the provided value is included as expected.
- Parameters:
formParameterName- name of parameter to look up in form data- Returns:
- value of parameter, or null when no value was provided
- Throws:
RuntimeException- if several values were provided for this parameter- See Also:
-
getQueryParameterValues
Get a query-parameter, as passed in the query string of a request, or an empty Collection if the query-parameter was not provided.Warning: When including a query string parameter in the response, attributes, and/or token, the client should verify that the provided value is included as expected.
- Parameters:
queryParameterName- name of parameter to look up in the query string- Returns:
- values of the parameter in the query string
- See Also:
-
getQueryParameterValueOrError
@Nullable @Nullable String getQueryParameterValueOrError(String queryParameterName, Function<String, ? extends RuntimeException> exceptionSupplier) Get a query-parameter, as passed in the query string of a request.If more than one value is found for this parameter, the error provided by the
exceptionSupplieris thrown.Warning: When including a query string parameter in the response, attributes, and/or token, the client should verify that the provided value is included as expected.
- Parameters:
queryParameterName- name of parameter to look up in the query stringexceptionSupplier- a supplier of the exception to be thrown when multiple values are found for the parameter- Returns:
- value of parameter, or null when no value was provided
- Throws:
RuntimeException- if several values were provided for this parameter- See Also:
-
getScheme
String getScheme()Get the scheme used for this request.- Returns:
- scheme of the request
-
getClientIpAddress
String getClientIpAddress()Get the IP address of the caller.If the server is behind a reverse proxy, this method will report the IP of the
X-Forwarded-Forheaders first entry, if and only if the proxy is in the environment configuration of white listed proxies (white-listed-proxies).- Returns:
- The IP address of the originating client (i.e., the first in the sequence of clients) or, if the IP address of the caller is a proxy that is not found in the white-list of allowed proxies or if that white-list is empty, then the IP address of the calling client.
-
getUrl
String getUrl()Get the full URL used in this request.- Returns:
- the full URL used in this request.
-
getPath
Get the path of the requested resource. Does not include the hostname, port and query parameters.- Returns:
- the path of the requested resource. Does not include the hostname, port and query parameters.
-
getMethod
String getMethod()Get the HTTP method used by this Request.Note: this method will return the "GET" string also when the request method is HEAD. In general, it is recommended to treat HEAD requests as if they were GET requests, and let the server deal with the relevant differences in the response. Use
isHeadRequest()when it's necessary to differentiate between GET and HEAD.- Returns:
- the HTTP method used by this Request.
- See Also:
-
isGetRequest
boolean isGetRequest()Returns true if this request uses the GET- or HEAD method, false otherwise.Note: this method will return
truealso when the request method is HEAD. In general, it is recommended to treat HEAD requests as if they were GET requests, and let the server deal with the relevant differences in the response. UseisHeadRequest()when it's necessary to differentiate between GET and HEAD.- Returns:
- true if this request uses the GET- or HEAD method, false otherwise.
- See Also:
-
isPostRequest
boolean isPostRequest()Returns true if this request uses the POST method, false otherwise.- Returns:
- true if this request uses the POST method, false otherwise.
-
isHeadRequest
boolean isHeadRequest()Returns true if this request uses the HEAD method, false otherwise.- Returns:
- true if this request uses the HEAD method, false otherwise.
- Since:
- 6.5.0
- See Also:
-
hasSession
boolean hasSession()Returns true if there's a session associated with this request, false otherwise.- Returns:
- true if there's a session associated with this request, false otherwise.
-
getHeaders
HttpHeaders getHeaders()Get theHttpHeadersof the request.- Returns:
- the request headers.
-
getQueryParameterNames
Get aSetof all query parameter names.- Returns:
- the name of all query parameters.
-
getFormParameterNames
- Returns:
- the name of all form parameters.
This method only applies to requests whose body has the "application/x-www-form-urlencoded" content-type.
-
getParameterNames
- Returns:
- the name of all form and query parameters.
- See Also:
-
getQueryString
Gets the encoded version of the query string or null if the request did not contain one.When a query value was present in the request which was not URL safe, the resulting string will be encoded. To decode it, the client may decode it:
String decodedQueryString = URLDecoder.decode(request.getQueryString(), StandardCharsets.UTF_8.name());Warning: When including a query string parameter in the response, attributes, and/or token, the client should verify that the provided value is included as expected.
- Returns:
- the full query String of this request, or null if no query was provided. The value is not decoded.
- See Also:
-
getCookies
RequestCookies getCookies()- Returns:
- the cookies sent with this request.
-
getAcceptableMediaTypes
String getAcceptableMediaTypes()Gets the acceptable media types for the request.The returned value is never null. If not provided, this method returns */*. If many values are acceptable, they are all returned as a comma-separated String.
- Returns:
- the acceptable media types for this request (comma-separated items).
-
getBodyAsString
String getBodyAsString()Get the body of this Request.Note that if the client sent an
Expect: 100-continueheader, calling this method causes the server to respond with the CONTINUE (100) status code immediately.- Returns:
- the body of this request. If this request does not have a body, return the empty String.
-