public final class RestRequest extends javax.servlet.http.HttpServletRequestWrapper
Equivalent to HttpServletRequest
except with some additional convenience methods.
For reference, given the URL
Method | Value |
---|---|
getContextPath() | /contextRoot |
getPathInfo() | /foo |
getPathTranslated() | path-to-deployed-war-on-filesystem/foo |
getQueryString() | bar=baz |
getRequestURI() | /contextRoot/servletPath/foo |
getRequestURL() | http://localhost:9080/contextRoot/servletPath/foo |
getServletPath() | /servletPath |
Modifier and Type | Method and Description |
---|---|
RestRequest |
attr(String name,
Object value)
Shorthand method for calling
ServletRequestWrapper.setAttribute(String, Object) fluently. |
Object |
getAttribute(String name,
Object def)
Same as
ServletRequestWrapper.getAttribute(String) but returns a default value if not found. |
BeanSession |
getBeanSession()
Returns the
BeanSession associated with this request. |
RequestBody |
getBody()
Request body.
|
String |
getCharacterEncoding()
Returns the charset specified on the
Content-Type header, or |
ReaderResource |
getClasspathReaderResource(String name)
Same as
getClasspathReaderResource(String, boolean) with resolveVars == |
ReaderResource |
getClasspathReaderResource(String name,
boolean resolveVars)
Same as
getClasspathReaderResource(String, boolean, MediaType) except uses the resource mime-type map
constructed using RestContextBuilder.mimeTypes(String...) to determine the media type. |
ReaderResource |
getClasspathReaderResource(String name,
boolean resolveVars,
MediaType mediaType)
Returns an instance of a
ReaderResource that represents the contents of a resource text file from the
classpath. |
Config |
getConfig()
Config file associated with the resource.
|
List<MediaType> |
getConsumes()
Returns the media types that are valid for
Content-Type headers on the request. |
int |
getContentLength() |
RestContext |
getContext()
Returns the resource context handling the request.
|
String |
getContextPath() |
String |
getDescription()
Returns a string of the form
|
RequestFormData |
getFormData()
Form-data.
|
String |
getFormData(String name)
Shortcut for calling
getFormData().getString(name) . |
String |
getHeader(String name) |
RequestHeaders |
getHeaders()
Request headers.
|
Enumeration<String> |
getHeaders(String name) |
HttpMethod |
getHttpMethod()
Returns the HTTP 1.1 method name of the request as an enum.
|
RestInfoProvider |
getInfoProvider()
Resource information provider.
|
javax.servlet.ServletInputStream |
getInputStream()
Returns the HTTP body content as an
InputStream . |
Method |
getJavaMethod()
Returns the java method handling the request.
|
Locale |
getLocale() |
Enumeration<Locale> |
getLocales() |
RestLogger |
getLogger()
Logger.
|
String |
getMessage(String key,
Object... args)
Shortcut method for calling
MessageBundle.getString(Locale, String, Object...) based on the request locale. |
MessageBundle |
getMessageBundle()
Returns the resource bundle for the request locale.
|
String |
getMethod()
Returns the method of this request.
|
String |
getMethodDescription()
Returns the localized method description.
|
String |
getMethodSummary()
Returns the localized method summary.
|
ParserGroup |
getParsers()
Returns the parsers associated with this request.
|
String |
getPath(String name)
Shortcut for calling
getPathMatch().get(name) . |
RequestPathMatch |
getPathMatch()
Request path match.
|
List<MediaType> |
getProduces()
Returns the media types that are valid for
Accept headers on the request. |
RequestProperties |
getProperties()
Retrieve the properties active for this request.
|
RequestQuery |
getQuery()
Query parameters.
|
String |
getQuery(String name)
Shortcut for calling
getQuery().getString(name) . |
BufferedReader |
getReader()
Returns the HTTP body content as a
Reader . |
String |
getResourceDescription()
Returns the localized resource description.
|
String |
getResourceTitle()
Returns the localized resource title.
|
SerializerGroup |
getSerializers()
Returns the serializers associated with this request.
|
String |
getServletPath() |
String |
getSiteName()
Returns the localized site name.
|
Swagger |
getSwagger()
Returns the localized swagger associated with the resource.
|
URI |
getUri(boolean includeQuery,
Map<String,?> addQueryParams)
Returns the URI for this request.
|
UriContext |
getUriContext()
Returns the URI context of the request.
|
UriResolver |
getUriResolver()
|
UriResolver |
getUriResolver(UriResolution resolution,
UriRelativity relativity)
Returns a URI resolver that can be used to convert URIs to absolute or root-relative form.
|
VarResolverSession |
getVarResolverSession()
Request-level variable resolver session.
|
Map<String,Widget> |
getWidgets()
Returns the widgets used for resolving
|
boolean |
isPlainText()
Returns
&plainText=true was specified as a URL parameter. |
RestRequest |
prop(String name,
Object value)
Shortcut for calling
getProperties().append(name, value); fluently. |
void |
setCharacterEncoding(String charset)
Sets the charset to expect on the request body.
|
String |
toString() |
authenticate, changeSessionId, getAuthType, getCookies, getDateHeader, getHeaderNames, getIntHeader, getPart, getParts, getPathInfo, getPathTranslated, getQueryString, getRemoteUser, getRequestedSessionId, getRequestURI, getRequestURL, getSession, getSession, getUserPrincipal, isRequestedSessionIdFromCookie, isRequestedSessionIdFromUrl, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isUserInRole, login, logout, upgrade
getAsyncContext, getAttribute, getAttributeNames, getContentLengthLong, getContentType, getDispatcherType, getLocalAddr, getLocalName, getLocalPort, getParameter, getParameterMap, getParameterNames, getParameterValues, getProtocol, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequest, getRequestDispatcher, getScheme, getServerName, getServerPort, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, isWrapperFor, isWrapperFor, removeAttribute, setAttribute, setRequest, startAsync, startAsync
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getAsyncContext, getAttribute, getAttributeNames, getContentLengthLong, getContentType, getDispatcherType, getLocalAddr, getLocalName, getLocalPort, getParameter, getParameterMap, getParameterNames, getParameterValues, getProtocol, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequestDispatcher, getScheme, getServerName, getServerPort, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, removeAttribute, setAttribute, startAsync, startAsync
public String getDescription()
public Object getAttribute(String name, Object def)
ServletRequestWrapper.getAttribute(String)
but returns a default value if not found.name
- The request attribute name.def
- The default value if the attribute doesn't exist.public RestRequest attr(String name, Object value)
ServletRequestWrapper.setAttribute(String, Object)
fluently.name
- The request attribute name.value
- The request attribute value.public RequestProperties getProperties()
This contains all resource and method level properties from the following:
The returned object is modifiable and allows you to override session-level properties before
they get passed to the serializers.
However, properties are open-ended, and can be used for any purpose.
public RestRequest prop(String name, Object value)
getProperties().append(name, value);
fluently.name
- The property name.value
- The property value.public RequestHeaders getHeaders()
Returns a RequestHeaders
object that encapsulates access to HTTP headers on the request.
part-parser
on the resource class.
RequestHeaders
object can also be passed as a parameter on the method.
@Header
annotation can be used to access individual header values.
public String getHeader(String name)
getHeader
in interface javax.servlet.http.HttpServletRequest
getHeader
in class javax.servlet.http.HttpServletRequestWrapper
public Enumeration<String> getHeaders(String name)
getHeaders
in interface javax.servlet.http.HttpServletRequest
getHeaders
in class javax.servlet.http.HttpServletRequestWrapper
public List<MediaType> getProduces()
Accept
headers on the request.public List<MediaType> getConsumes()
Content-Type
headers on the request.public void setCharacterEncoding(String charset)
setCharacterEncoding
in interface javax.servlet.ServletRequest
setCharacterEncoding
in class javax.servlet.ServletRequestWrapper
public String getCharacterEncoding()
Content-Type
header, or getCharacterEncoding
in interface javax.servlet.ServletRequest
getCharacterEncoding
in class javax.servlet.ServletRequestWrapper
public Locale getLocale()
getLocale
in interface javax.servlet.ServletRequest
getLocale
in class javax.servlet.ServletRequestWrapper
public Enumeration<Locale> getLocales()
getLocales
in interface javax.servlet.ServletRequest
getLocales
in class javax.servlet.ServletRequestWrapper
public RequestQuery getQuery()
Returns a RequestQuery
object that encapsulates access to URL GET parameters.
Similar to ServletRequestWrapper.getParameterMap()
but only looks for query parameters in the URL and not form posts.
part-parser
on the resource class.
RequestQuery
object can also be passed as a parameter on the method.
@Query
annotation can be used to access individual query parameter values.
public String getQuery(String name)
getQuery().getString(name)
.name
- The query parameter name.public RequestFormData getFormData()
Returns a RequestFormData
object that encapsulates access to form post parameters.
Similar to ServletRequestWrapper.getParameterMap()
, but only looks for form data in the HTTP body.
part-parser
on the resource class.
RequestFormData
object can also be passed as a parameter on the method.
@FormDAta
annotation can be used to access individual form data parameter values.
FormData
public String getFormData(String name)
getFormData().getString(name)
.name
- The form data parameter name.public RequestPathMatch getPathMatch()
Returns a RequestPathMatch
object that encapsulates access to everything related to the URL path.
part-parser
on the resource class.
RequestPathMatch
object can also be passed as a parameter on the method.
@Path
and @PathRemainder
annotations can be used to access individual values.
public String getPath(String name)
getPathMatch().get(name)
.name
- The path variable name.public RequestBody getBody()
Returns a RequestBody
object that encapsulates access to the HTTP request body.
RequestBody
object can also be passed as a parameter on the method.
@Body
annotation can be used to access the body as well.
public BufferedReader getReader() throws IOException
Reader
.
If allowHeaderParams
init parameter is true, then first looks for &body=xxx
in the URL query
string.
Automatically handles GZipped input streams.
getReader
in interface javax.servlet.ServletRequest
getReader
in class javax.servlet.ServletRequestWrapper
IOException
public javax.servlet.ServletInputStream getInputStream() throws IOException
InputStream
.
Automatically handles GZipped input streams.
getInputStream
in interface javax.servlet.ServletRequest
getInputStream
in class javax.servlet.ServletRequestWrapper
IOException
- If any error occurred while trying to get the input stream or wrap it in the GZIP wrapper.public String getContextPath()
getContextPath
in interface javax.servlet.http.HttpServletRequest
getContextPath
in class javax.servlet.http.HttpServletRequestWrapper
public String getServletPath()
getServletPath
in interface javax.servlet.http.HttpServletRequest
getServletPath
in class javax.servlet.http.HttpServletRequestWrapper
public UriContext getUriContext()
The URI context contains all the information about the URI of the request, such as the servlet URI, context path, etc...
public UriResolver getUriResolver(UriResolution resolution, UriRelativity relativity)
resolution
- The URI resolution rule.relativity
- The relative URI relativity rule.public UriResolver getUriResolver()
public URI getUri(boolean includeQuery, Map<String,?> addQueryParams)
Similar to HttpServletRequestWrapper.getRequestURI()
but returns the value as a URI
.
It also gives you the capability to override the query parameters (e.g. add new query parameters to the existing
URI).
includeQuery
- If addQueryParams
- Augment the request URI with the specified query parameters.public RestInfoProvider getInfoProvider()
Returns a RestInfoProvider
object that encapsulates all the textual meta-data on this resource such as
descriptions, titles, and Swagger documentation.
RestInfoProvider
object can also be passed as a parameter on the method.
public Swagger getSwagger()
A shortcut for calling getInfoProvider().getSwagger(request);
Swagger
object can also be passed as a parameter on the method.
public String getSiteName()
The site name is intended to be a title that can be applied to the entire site.
One possible use is if you want to add the same title to the top of all pages by defining a header on a common parent class like so:
htmldoc=
Equivalent to calling RestInfoProvider.getSiteName(RestRequest)
with this object.
public String getResourceTitle()
Equivalent to calling RestInfoProvider.getTitle(RestRequest)
with this object.
public String getResourceDescription()
Equivalent to calling RestInfoProvider.getDescription(RestRequest)
with this object.
public String getMethodSummary()
Equivalent to calling RestInfoProvider.getMethodSummary(Method, RestRequest)
with this object.
public String getMethodDescription()
Equivalent to calling RestInfoProvider.getMethodDescription(Method, RestRequest)
with this object.
public SerializerGroup getSerializers()
public ParserGroup getParsers()
public String getMethod()
If allowHeaderParams
init parameter is &method=xxx
in the URL query string.
getMethod
in interface javax.servlet.http.HttpServletRequest
getMethod
in class javax.servlet.http.HttpServletRequestWrapper
public HttpMethod getHttpMethod()
Note that non-RFC2616 method names resolve as HttpMethod.OTHER
.
public int getContentLength()
getContentLength
in interface javax.servlet.ServletRequest
getContentLength
in class javax.servlet.ServletRequestWrapper
public boolean isPlainText()
&plainText=true
was specified as a URL parameter.
This indicates that the Content-Type
of the output should always be set to
This feature is useful for debugging.
&plainText=true
was specified as a URL parameterpublic MessageBundle getMessageBundle()
MessageBundle
object can also be passed as a parameter on the method.
public String getMessage(String key, Object... args)
MessageBundle.getString(Locale, String, Object...)
based on the request locale.key
- The message key.args
- Optional MessageFormat
-style arguments.public RestContext getContext()
Can be used to access servlet-init parameters or annotations during requests, such as in calls to
RestGuard.guard(RestRequest, RestResponse)
..
public Method getJavaMethod()
Can be used to access the method name or method annotations during requests, such as in calls to
RestGuard.guard(RestRequest, RestResponse)
.
null
if the method has not yet been resolved.public BeanSession getBeanSession()
BeanSession
associated with this request.public VarResolverSession getVarResolverSession()
Used to resolve SVL variables in text.
VarResolverSession
object can also be passed as a parameter on the method.
public ReaderResource getClasspathReaderResource(String name, boolean resolveVars, MediaType mediaType) throws IOException
ReaderResource
that represents the contents of a resource text file from the
classpath.
name
- The name of the resource (i.e. the value normally passed to Class.getResourceAsStream(String)
.resolveVars
- If getVarResolverSession()
.
RestContext.getVarResolver()
for the list of supported variables.mediaType
- The value to set as the IOException
public ReaderResource getClasspathReaderResource(String name, boolean resolveVars) throws IOException
getClasspathReaderResource(String, boolean, MediaType)
except uses the resource mime-type map
constructed using RestContextBuilder.mimeTypes(String...)
to determine the media type.name
- The name of the resource (i.e. the value normally passed to Class.getResourceAsStream(String)
.resolveVars
- If getVarResolverSession()
.
RestContext.getVarResolver()
for the list of supported variables.IOException
public ReaderResource getClasspathReaderResource(String name) throws IOException
getClasspathReaderResource(String, boolean)
with resolveVars == false
name
- The name of the resource (i.e. the value normally passed to Class.getResourceAsStream(String)
.IOException
public Config getConfig()
Returns a config file with session-level variable resolution. The config file is identified via one of the following:
Config
object can also be passed as a parameter on the method.
public Map<String,Widget> getWidgets()
public RestLogger getLogger()
Shortcut for calling getContext().getLogger()
.
RestLogger
object can also be passed as a parameter on the method.
Copyright © 2018 Apache. All rights reserved.