public class RequestUtils extends Object
Modifier and Type | Method and Description |
---|---|
static AppContext |
appContext()
Returns instance of
AppContext . |
static String |
context()
Provides a context of the request - usually an app name (as seen on URL of request).
|
static Cookie |
cookie(String name)
Returns a cookie by name, null if not found.
|
static List<Cookie> |
cookies()
Returns collection of all cookies browser sent.
|
static String |
cookieValue(String name)
Convenience method, returns cookie value.
|
static boolean |
exists(String name)
Tests if a request parameter exists.
|
static String |
format()
Returns a format part of the URI, or null if URI does not have a format part.
|
static String |
getId()
Returns value of ID if one is present on a URL.
|
static Locale |
getLocale()
Same as
locale() . |
static String |
getRequestHost()
This method returns a host name of a web server if this container is fronted by one, such that
it sets a header
X-Forwarded-Host on the request and forwards it to the Java container. |
static int |
getRequestPort()
This method returns a port of a web server if this Java container is fronted by one, such that
it sets a header
X-Forwarded-Port on the request and forwards it to the Java container. |
static String |
getRequestProperties() |
static String |
getRequestProtocol()
This method returns a protocol of a request to web server if this container is fronted by one, such that
it sets a header
X-Forwarded-Proto on the request and forwards it to the Java container. |
static Route |
getRoute()
Returns instance of
Route to be used for potential conditional logic inside controller filters. |
static String |
header(String name)
Returns a request header by name.
|
static Map<String,String> |
headers()
Returns all headers from a request keyed by header name.
|
static String |
host()
Returns local host name on which request was received.
|
static String |
ipAddress()
Returns local IP address on which request was received.
|
static String |
ipForwardedFor()
Returns IP address that the web server forwarded request for.
|
static boolean |
isDelete()
True if this request uses HTTP DELETE method, false otherwise.
|
static boolean |
isGet()
True if this request uses HTTP GET method, false otherwise.
|
static boolean |
isHead()
True if this request uses HTTP HEAD method, false otherwise.
|
static boolean |
isMethod(String method) |
static boolean |
isMultipartContent() |
static boolean |
isPost()
True if this request uses HTTP POST method, false otherwise.
|
static boolean |
isPut()
True if this request uses HTTP PUT method, false otherwise.
|
static boolean |
isXhr()
Returns true if this request is Ajax.
|
static Locale |
locale()
Returns locale of request.
|
static String |
method()
Returns an HTTP method from the request.
|
static String |
param(String name)
Returns value of routing user segment, or route wild card value, or request parameter.
|
static String |
param(String name,
List<FormItem> formItems)
Convenience method to get a parameter value in case
multipart/form-data request was used. |
static Map<String,String[]> |
params()
Returns an instance of
java.util.Map containing parameter names as keys and parameter values as map values. |
static List<String> |
params(String name)
Returns multiple request values for a name.
|
static List<String> |
params(String name,
List<FormItem> formItems)
Convenience method to get parameter values in case
multipart/form-data request was used. |
static Map<String,String> |
params1st()
Returns a map where keys are names of all parameters, while values are the first value for each parameter, even
if such parameter has more than one value submitted.
|
static Map<String,String> |
params1st(List<FormItem> formItems)
Convenience method to get parameters in case
multipart/form-data request was used. |
static String |
path()
Returns a path of the request.
|
static int |
port()
Returns port on which the of the server received current request.
|
static String |
protocol()
Returns protocol of request, for example: HTTP/1.1.
|
static String |
queryString()
Returns query string of the request.
|
static String |
remoteAddress()
IP address of the requesting client.
|
static String |
remoteHost()
Host name of the requesting client.
|
static boolean |
requestHas(String name)
Synonym of
exists(String) . |
Object |
session(String name) |
void |
session(String name,
Object value)
Sets an object on a current session.
|
static String |
uri()
Returns URI, or a full path of request.
|
static String |
url()
Returns a full URL of the request, all except a query string.
|
static String |
userAgent()
Helper method, returns user-agent header of the request.
|
static boolean |
xhr()
Synonym for
isXhr() . |
public static boolean isMultipartContent()
public static String param(String name)
IllegalArgumentException
.name
- name of parameter.public static String param(String name, List<FormItem> formItems)
multipart/form-data
request was used.
Returns a value of one named parameter from request. Will only return form fields, and not files.name
- name of parameter.formItems
- form items retrieved from multipart/form-data
request.multipart/form-data
request or null if not found.public static String getId()
/controller/action/id
.
This depends on a type of a URI, and whether controller is RESTful or not.public static String format()
/books.xml
, here "xml" is a format.public static AppContext appContext()
AppContext
.AppContext
.public static boolean isXhr()
public static String userAgent()
public static boolean xhr()
isXhr()
.public static Route getRoute()
Route
to be used for potential conditional logic inside controller filters.Route
public static boolean exists(String name)
name
- name of request parameter to test.public static boolean requestHas(String name)
exists(String)
.name
- name of request parameter to test.public static String host()
public static String ipAddress()
public static String getRequestProtocol()
X-Forwarded-Proto
on the request and forwards it to the Java container.
If such header is not present, than the protocol()
method is used.X-Forwarded-Proto
header is found, otherwise current
protocol.public static int getRequestPort()
X-Forwarded-Port
on the request and forwards it to the Java container.
If such header is not present, than the port()
method is used.X-Forwarded-Port
header is found, otherwise port of the Java container.public static int port()
public static String protocol()
public static String getRequestHost()
X-Forwarded-Host
on the request and forwards it to the Java container.
If such header is not present, than the host()
method is used.X-Forwarded-Host
header is found, otherwise local host name.public static String ipForwardedFor()
public static List<String> params(String name)
name
- name of multiple values from request.public static List<String> params(String name, List<FormItem> formItems)
multipart/form-data
request was used.
Returns multiple request values for a name.name
- name of multiple values from request.formItems
- form items retrieved from multipart/form-data
request.public static Map<String,String> params1st()
public static Map<String,String> params1st(List<FormItem> formItems)
multipart/form-data
request was used.
Returns a map where keys are names of all parameters, while values are the first value for each parameter, even
if such parameter has more than one value submitted.formItems
- form items retrieved from multipart/form-data
request.public static Map<String,String[]> params()
java.util.Map
containing parameter names as keys and parameter values as map values.
The keys in the parameter map are of type String. The values in the parameter map are of type String array.java.util.Map
containing parameter names as keys and parameter values as map values.
The keys in the parameter map are of type String. The values in the parameter map are of type String array.public static Locale locale()
public static List<Cookie> cookies()
public static Cookie cookie(String name)
name
- name of a cookie.public static String cookieValue(String name)
name
- name of cookie.public static String path()
/controller/action/id
public static String url()
public static String queryString()
public static String method()
public static boolean isGet()
public static boolean isPost()
public static boolean isPut()
public static boolean isDelete()
public static boolean isMethod(String method)
public static boolean isHead()
public static String context()
/mywebapp
public static String uri()
/mywebapp/controller/action/id
public static String remoteHost()
public static String remoteAddress()
public static String header(String name)
name
- name of headerpublic static Map<String,String> headers()
public Object session(String name)
name
- name of an object in sessionpublic void session(String name, Object value)
name
- name of objectvalue
- value of objectpublic static String getRequestProperties()
Copyright © 2019 JavaLite. All rights reserved.