@Immutable public final class RequestHelper extends Object
HttpServletRequest objects.| Modifier and Type | Field and Description |
|---|---|
static String |
ATTACHMENT
Content-disposition value for file attachment.
|
static String |
DEFAULT_CHECKBOX_HIDDEN_FIELD_PREFIX
The prefix to appended to the field name of the checkbox to create the
hidden field.
|
static String |
FORM_DATA
Content-disposition value for form data.
|
static String |
MULTIPART
Part of HTTP content type header.
|
static String |
MULTIPART_FORM_DATA
HTTP content type header for multipart forms.
|
static String |
MULTIPART_MIXED
HTTP content type header for multiple uploads.
|
static String |
SERVLET_ATTR_CLIENT_CERTIFICATE |
static String |
SERVLET_ATTR_SSL_CIPHER_SUITE |
static String |
SERVLET_ATTR_SSL_KEY_SIZE |
| Modifier and Type | Method and Description |
|---|---|
static com.helger.http.AcceptCharsetList |
getAcceptCharsets(javax.servlet.http.HttpServletRequest aHttpRequest) |
static com.helger.http.AcceptEncodingList |
getAcceptEncodings(javax.servlet.http.HttpServletRequest aHttpRequest) |
static com.helger.http.AcceptLanguageList |
getAcceptLanguages(javax.servlet.http.HttpServletRequest aHttpRequest) |
static com.helger.http.AcceptMimeTypeList |
getAcceptMimeTypes(javax.servlet.http.HttpServletRequest aHttpRequest) |
static com.helger.http.basicauth.BasicAuthClientCredentials |
getBasicAuthClientCredentials(javax.servlet.http.HttpServletRequest aHttpRequest)
Get the Basic authentication credentials from the passed HTTP servlet
request from the HTTP header
CHttpHeader.AUTHORIZATION. |
static String |
getCheckBoxHiddenFieldName(String sFieldName)
Get the name of the automatic hidden field associated with a check-box.
|
static long |
getContentLength(javax.servlet.http.HttpServletRequest aHttpRequest)
Get the content length of the passed request.
|
static int |
getDefaultServerPort(String sScheme) |
static com.helger.http.digestauth.DigestAuthClientCredentials |
getDigestAuthClientCredentials(javax.servlet.http.HttpServletRequest aHttpRequest)
Get the Digest authentication credentials from the passed HTTP servlet
request from the HTTP header
CHttpHeader.AUTHORIZATION. |
static StringBuilder |
getFullServerName(javax.servlet.http.HttpServletRequest aHttpRequest) |
static StringBuilder |
getFullServerName(String sScheme,
String sServerName,
int nServerPort) |
static String |
getFullServerNameAndPath(String sScheme,
String sServerName,
int nServerPort,
String sPath,
String sQueryString) |
static com.helger.commons.http.EHttpMethod |
getHttpMethod(javax.servlet.http.HttpServletRequest aHttpRequest)
Get the HTTP method associated with the given HTTP request
|
static String |
getHttpReferer(javax.servlet.http.HttpServletRequest aHttpRequest) |
static String |
getHttpUserAgentStringFromRequest(javax.servlet.http.HttpServletRequest aHttpRequest)
Get the user agent from the given request.
|
static com.helger.http.EHttpVersion |
getHttpVersion(javax.servlet.http.HttpServletRequest aHttpRequest)
Get the HTTP version associated with the given HTTP request
|
static String |
getPathInfo(javax.servlet.http.HttpServletRequest aHttpRequest)
Get the request path info without an eventually appended session
(";jsessionid=...")
|
static String |
getPathWithinServlet(javax.servlet.http.HttpServletRequest aHttpRequest)
Return the path within the servlet mapping for the given request, i.e. the
part of the request's URL beyond the part that called the servlet, or "" if
the whole URL has been used to identify the servlet.
|
static String |
getPathWithinServletContext(javax.servlet.http.HttpServletRequest aHttpRequest)
Return the URI of the request within the servlet context.
|
static X509Certificate[] |
getRequestClientCertificates(javax.servlet.http.HttpServletRequest aHttpRequest)
Get the client certificates provided by a HTTP servlet request.
|
static com.helger.commons.http.HttpHeaderMap |
getRequestHeaderMap(javax.servlet.http.HttpServletRequest aHttpRequest)
Get a complete request header map as a copy.
|
static IRequestParamMap |
getRequestParamMap(javax.servlet.http.HttpServletRequest aHttpRequest) |
static String |
getRequestSSLCipherSuite(javax.servlet.http.HttpServletRequest aHttpRequest) |
static Integer |
getRequestSSLKeySize(javax.servlet.http.HttpServletRequest aHttpRequest) |
static String |
getRequestURI(javax.servlet.http.HttpServletRequest aHttpRequest)
Get the request URI without an eventually appended session
(";jsessionid=...").
|
static StringBuilder |
getRequestURL(javax.servlet.http.HttpServletRequest aHttpRequest)
Reconstructs the URL the client used to make the request.
|
static int |
getServerPortToUse(String sScheme,
int nServerPort) |
static String |
getSessionID(com.helger.commons.url.ISimpleURL aURL)
Get the session ID of the passed string (like in
"test.html;JSESSIONID=1234").
|
static String |
getSessionID(String sValue)
Get the session ID of the passed string (like in
"test.html;JSESSIONID=1234").
|
static com.helger.useragent.uaprofile.UAProfile |
getUAProfile(javax.servlet.http.HttpServletRequest aHttpRequest)
Get the user agent object from the given HTTP request.
|
static String |
getURI(javax.servlet.http.HttpServletRequest aHttpRequest)
Get the full URI (excl. protocol) and parameters of the passed request.
|
static String |
getURL(javax.servlet.http.HttpServletRequest aHttpRequest)
Get the full URL (incl. protocol) and parameters of the passed request.
|
static com.helger.useragent.IUserAgent |
getUserAgent(javax.servlet.http.HttpServletRequest aHttpRequest)
Get the user agent object from the given HTTP request.
|
static com.helger.commons.url.SimpleURL |
getWithoutSessionID(com.helger.commons.url.ISimpleURL aURL)
Get the passed string without an eventually contained session ID like in
"test.html;JSESSIONID=1234?
|
static String |
getWithoutSessionID(String sValue)
Get the passed string without an eventually contained session ID like in
"test.html;JSESSIONID=1234".
|
static boolean |
isMultipartContent(javax.servlet.http.HttpServletRequest aHttpRequest)
Utility method that determines whether the request contains multipart
content.
|
static boolean |
isMultipartContent(String sContentType)
Utility method that determines whether the request contains multipart
content.
|
static boolean |
isMultipartFormDataContent(javax.servlet.http.HttpServletRequest aHttpRequest)
Utility method that determines whether the request contains multipart
content.
|
static boolean |
isMultipartFormDataContent(String sContentType)
Utility method that determines whether the request contains
multipart/form-data content. |
public static final String SERVLET_ATTR_SSL_CIPHER_SUITE
public static final String SERVLET_ATTR_SSL_KEY_SIZE
public static final String SERVLET_ATTR_CLIENT_CERTIFICATE
public static final String FORM_DATA
public static final String ATTACHMENT
public static final String MULTIPART
public static final String MULTIPART_FORM_DATA
public static final String MULTIPART_MIXED
public static final String DEFAULT_CHECKBOX_HIDDEN_FIELD_PREFIX
@Nonnull public static String getWithoutSessionID(@Nonnull String sValue)
sValue - The value to strip the session ID from. May not be
null.@Nonnull public static com.helger.commons.url.SimpleURL getWithoutSessionID(@Nonnull com.helger.commons.url.ISimpleURL aURL)
aURL - The value to strip the session ID from the path@Nullable public static String getSessionID(@Nonnull String sValue)
sValue - The value to get the session ID from. May not be null.null if no session ID
is present.@Nullable public static String getSessionID(@Nonnull com.helger.commons.url.ISimpleURL aURL)
aURL - The URL to get the session ID from. May not be null.null if no session ID
is present.@Nullable public static String getRequestURI(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
| First line of HTTP request | Returned Value |
|---|---|
| POST /some/path.html;JSESSIONID=4711 | /some/path.html |
| GET http://foo.bar/a.html;JSESSIONID=4711 | /a.html |
| HEAD /xyz;JSESSIONID=4711?a=b | /xyz |
aHttpRequest - The HTTP request@Nullable public static String getPathInfo(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
aHttpRequest - The HTTP request@Nonnull public static String getPathWithinServletContext(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
aHttpRequest - The HTTP request. May not be null.null. By
default "/" is returned is an empty request URI is determined.@Nonnull public static String getPathWithinServlet(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
aHttpRequest - current HTTP request@Nonnull @Nonempty public static StringBuilder getRequestURL(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
If this request has been forwarded using
RequestDispatcher.forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse), the server path in the
reconstructed URL must reflect the path used to obtain the
RequestDispatcher, and not the server path specified by the client.
Because this method returns a StringBuilder, not a string, you
can modify the URL easily, for example, to append query parameters.
This method is useful for creating redirect messages and for reporting errors.
aHttpRequest - The HTTP request to get the request URL from. May not be
null.StringBuilder object containing the reconstructed
URL@Nonnull @Nonempty public static String getURL(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
http://hostname.com/mywebapp/servlet/dir/a/b.xml=123?d=789
aHttpRequest - The request to use. May not be null.getURI to retrieve the URL without the
server scheme and name.@Nonnull @Nonempty public static String getURI(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
/mywebapp/servlet/dir/a/b.xml=123?d=789
aHttpRequest - The request to use. May not be null.getURL to retrieve the absolute URL@CheckForSigned public static int getDefaultServerPort(@Nullable String sScheme)
@CheckForSigned public static int getServerPortToUse(@Nonnull String sScheme, @CheckForSigned int nServerPort)
@Nonnull @Nonempty public static StringBuilder getFullServerName(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
@Nonnull @Nonempty public static StringBuilder getFullServerName(@Nullable String sScheme, @Nullable String sServerName, int nServerPort)
@Nonnull @Nonempty public static String getFullServerNameAndPath(@Nonnull String sScheme, @Nonnull String sServerName, int nServerPort, @Nullable String sPath, @Nullable String sQueryString)
@Nullable public static String getHttpReferer(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
@Nullable public static com.helger.http.EHttpVersion getHttpVersion(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
aHttpRequest - The http request to query. May not be null.null if no supported HTTP version is contained@Nullable public static com.helger.commons.http.EHttpMethod getHttpMethod(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
aHttpRequest - The http request to query. May not be null.null if no supported HTTP method is contained@Nonnull @ReturnsMutableCopy public static com.helger.commons.http.HttpHeaderMap getRequestHeaderMap(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
aHttpRequest - The source HTTP request. May not be null.null.@Nonnull public static IRequestParamMap getRequestParamMap(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
@CheckForSigned public static long getContentLength(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
request.getContentLength() but instead parsing the HTTP header
field CHttpHeader.CONTENT_LENGTH manually!aHttpRequest - Source HTTP request. May not be null.@Nullable public static String getRequestSSLCipherSuite(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
aHttpRequest - he HTTP servlet request to extract the information from. May not be
null.null if no such attribute is
present@Nullable public static Integer getRequestSSLKeySize(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
aHttpRequest - he HTTP servlet request to extract the information from. May not be
null.null if no such attribute
is present@Nullable public static X509Certificate[] getRequestClientCertificates(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
aHttpRequest - The HTTP servlet request to extract the information from. May not be
null.null if the passed request does not contain any client
certificatepublic static boolean isMultipartContent(@Nullable String sContentType)
sContentType - The content type to be checked. May be null.true if the request is multipart; false
otherwise.public static boolean isMultipartContent(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
aHttpRequest - The servlet request to be evaluated. Must be non-null.true if the request is multipart; false
otherwise.public static boolean isMultipartFormDataContent(@Nullable String sContentType)
multipart/form-data content.sContentType - The content type to be checked. May be null.true if the passed, lowercased content type starts
with multipart/form-data; false
otherwise.public static boolean isMultipartFormDataContent(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
aHttpRequest - The servlet request to be evaluated. Must be non-null.true if the request is multipart; false
otherwise.@Nonnull public static com.helger.http.AcceptCharsetList getAcceptCharsets(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
@Nonnull public static com.helger.http.AcceptEncodingList getAcceptEncodings(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
@Nonnull public static com.helger.http.AcceptLanguageList getAcceptLanguages(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
@Nonnull public static com.helger.http.AcceptMimeTypeList getAcceptMimeTypes(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
@Nullable public static com.helger.http.basicauth.BasicAuthClientCredentials getBasicAuthClientCredentials(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
CHttpHeader.AUTHORIZATION.aHttpRequest - The HTTP request to be interpreted. May be null.null if the passed request does not contain a valid
HTTP Basic Authentication header value.@Nullable public static com.helger.http.digestauth.DigestAuthClientCredentials getDigestAuthClientCredentials(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
CHttpHeader.AUTHORIZATION.aHttpRequest - The HTTP request to be interpreted. May be null.null if the passed request does not contain a valid
HTTP Digest Authentication header value.@Nullable public static String getHttpUserAgentStringFromRequest(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
aHttpRequest - The HTTP request to get the UA from.null if no user agent string is present@Nonnull public static com.helger.useragent.IUserAgent getUserAgent(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
aHttpRequest - The HTTP request to extract the information from.null user agent object.@Nonnull public static com.helger.useragent.uaprofile.UAProfile getUAProfile(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
aHttpRequest - The HTTP request to extract the information from.null user agent object.@Nonnull @Nonempty public static String getCheckBoxHiddenFieldName(@Nonnull @Nonempty String sFieldName)
sFieldName - The name of the check-box.Copyright © 2016–2019 Philip Helger. All rights reserved.