public final class RestRequest extends 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 |
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
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. |
RequestAttributes |
getAttributes()
Request attributes.
|
String |
getAuthorityPath()
Returns the URI authority portion of the request.
|
BeanSession |
getBeanSession()
Returns the
BeanSession associated with this request. |
RequestBody |
getBody()
Request body.
|
RestCallLoggerConfig |
getCallLoggerConfig()
Returns the logging configuration defined on the Java method that this request is executing against.
|
String |
getCharacterEncoding()
Returns the charset specified on the
|
Charset |
getCharset()
Wrapper around
getCharacterEncoding() that converts the value to a Charset . |
BasicHttpResource |
getClasspathHttpResource(String name)
Same as
getClasspathHttpResource(String, boolean) with resolveVars == |
BasicHttpResource |
getClasspathHttpResource(String name,
boolean resolveVars)
Same as
getClasspathHttpResource(String, boolean, MediaType, boolean) except uses the resource mime-type map
constructed using RestContextBuilder.mimeTypes(String...) to determine the media type. |
BasicHttpResource |
getClasspathHttpResource(String name,
boolean resolveVars,
MediaType mediaType,
boolean cached)
Returns an instance of a
BasicHttpResource that represents the contents of a resource text file from the
classpath. |
String |
getClasspathResourceAsString(String name)
Returns a classpath resource as a string,
|
String |
getClasspathResourceAsString(String name,
boolean resolveVars)
Returns a classpath resource as a string,
|
Config |
getConfig()
Config file associated with the resource.
|
List<MediaType> |
getConsumes()
Returns the media types that are valid for
|
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
|
String |
getHeader(String name) |
RequestHeaders |
getHeaders()
Request headers.
|
Enumeration<String> |
getHeaders(String name) |
RestInfoProvider |
getInfoProvider()
Resource information provider.
|
protected HttpServletRequest |
getInner()
Returns the wrapped servlet request.
|
ServletInputStream |
getInputStream()
Returns the HTTP body content as an
InputStream . |
Method |
getJavaMethod()
Returns the java method handling the request.
|
JsonSchemaGenerator |
getJsonSchemaGenerator()
Returns the schema generator with settings assigned on this method and class.
|
Locale |
getLocale() |
Enumeration<Locale> |
getLocales() |
RestCallLogger |
getLogger()
Deprecated.
|
String |
getMessage(String key,
Object... args)
Shortcut method for calling
getMessages() and Messages.getString(String,Object...) . |
Messages |
getMessages()
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.
|
ParserSessionArgs |
getParserSessionArgs()
Returns the session arguments to pass to parsers.
|
HttpPartParserSession |
getPartParser()
Returns the part serializer associated with this request.
|
HttpPartSerializerSession |
getPartSerializer()
Returns the part serializer associated with this request.
|
String |
getPath(String name)
Shortcut for calling
|
RequestPath |
getPathMatch()
Request path match.
|
String |
getPathRemainder()
Shortcut for calling
|
List<MediaType> |
getProduces()
Returns the media types that are valid for
|
RequestProperties |
getProperties()
Deprecated.
|
PropertyStore |
getPropertyStore()
Returns the
PropertyStore for this request. |
RequestQuery |
getQuery()
Query parameters.
|
String |
getQuery(String name)
Shortcut for calling
|
BufferedReader |
getReader()
Returns the HTTP body content as a
Reader . |
<T> T |
getRequest(Class<T> c)
Creates a proxy interface to retrieve HTTP parts of this request as a proxy bean.
|
<T> T |
getRequest(RequestBeanMeta rbm)
Same as
getRequest(Class) but used on pre-instantiated RequestBeanMeta objects. |
String |
getResourceDescription()
Returns the localized resource description.
|
String |
getResourceTitle()
Returns the localized resource title.
|
ResponseBeanMeta |
getResponseBeanMeta(Object o)
Returns metadata about the specified response object if it's annotated with
@Response . |
ResponsePartMeta |
getResponseBodyMeta(Object o)
Returns metadata about the specified response object if it's annotated with
@ResponseBody . |
ResponsePartMeta |
getResponseHeaderMeta(Object o)
Returns metadata about the specified response object if it's annotated with
@ResponseHeader . |
SerializerGroup |
getSerializers()
Returns the serializers associated with this request.
|
SerializerSessionArgs |
getSerializerSessionArgs()
Returns the session arguments to pass to serializers.
|
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()
Deprecated.
|
boolean |
isDebug()
Returns
|
boolean |
isPlainText()
Returns
|
RestRequest |
prop(String name,
Object value)
Deprecated.
|
void |
setCharacterEncoding(String charset)
Sets the charset to expect on the request body.
|
RestRequest |
setDebug()
Shortcut for calling
|
RestRequest |
setDebug(Boolean b)
Sets the
|
RestRequest |
setException(Throwable t)
Sets the
|
RestRequest |
setNoTrace()
Shortcut for calling
|
RestRequest |
setNoTrace(Boolean b)
Sets the
|
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()
@Deprecated public RequestProperties getProperties()
getAttributes()
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.
@Deprecated public RestRequest prop(String name, Object value)
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 HttpServletRequest
getHeader
in class HttpServletRequestWrapper
public Enumeration<String> getHeaders(String name)
getHeaders
in interface HttpServletRequest
getHeaders
in class HttpServletRequestWrapper
public List<MediaType> getProduces()
public List<MediaType> getConsumes()
public PropertyStore getPropertyStore()
PropertyStore
for this request.
Consists of a read-only roll-up of all configuration properties defined on this method and class.
public void setCharacterEncoding(String charset)
setCharacterEncoding
in interface ServletRequest
setCharacterEncoding
in class ServletRequestWrapper
public String getCharacterEncoding() throws UnsupportedMediaType
getCharacterEncoding
in interface ServletRequest
getCharacterEncoding
in class ServletRequestWrapper
UnsupportedMediaType
public Charset getCharset()
getCharacterEncoding()
that converts the value to a Charset
.Charset
.public Locale getLocale()
getLocale
in interface ServletRequest
getLocale
in class ServletRequestWrapper
public Enumeration<Locale> getLocales()
getLocales
in interface ServletRequest
getLocales
in class ServletRequestWrapper
public RequestAttributes getAttributes()
Returns a RequestAttributes
object that encapsulates access to attributes on the request.
part-parser
on the resource class.
RequestAttributes
object can also be passed as a parameter on the method.
@Attr
annotation can be used to access individual attribute values.
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 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)
name
- The query parameter name.public RequestFormData getFormData() throws InternalServerError
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.
InternalServerError
- If query parameters could not be parsed.FormData
public String getFormData(String name)
name
- The form data parameter name.public RequestPath getPathMatch()
Returns a RequestPath
object that encapsulates access to everything related to the URL path.
part-parser
on the resource class.
RequestPath
object can also be passed as a parameter on the method.
@Path
annotation can be used to access individual values.
public String getPath(String name)
name
- The path variable name.public String getPathRemainder()
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 ServletRequest
getReader
in class ServletRequestWrapper
IOException
public ServletInputStream getInputStream() throws IOException
InputStream
.
Automatically handles GZipped input streams.
getInputStream
in interface ServletRequest
getInputStream
in class 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 HttpServletRequest
getContextPath
in class HttpServletRequestWrapper
public String getAuthorityPath()
public String getServletPath()
getServletPath
in interface HttpServletRequest
getServletPath
in class 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
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:
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 HttpPartParserSession getPartParser()
public HttpPartSerializerSession getPartSerializer()
public String getMethod()
If
getMethod
in interface HttpServletRequest
getMethod
in class HttpServletRequestWrapper
public int getContentLength()
getContentLength
in interface ServletRequest
getContentLength
in class ServletRequestWrapper
public boolean isPlainText()
This indicates that the
This feature is useful for debugging.
&plainText=true
was specified as a URL parameterpublic Messages getMessages()
Messages
object can also be passed as a parameter on the method.
public String getMessage(String key, Object... args)
getMessages()
and Messages.getString(String,Object...)
.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)
.
public BeanSession getBeanSession()
BeanSession
associated with this request.public boolean isDebug()
public RestRequest setException(Throwable t)
This exception is used by BasicRestCallLogger
for logging purposes.
t
- The attribute value.public RestRequest setNoTrace(Boolean b)
This flag is used by BasicRestCallLogger
and tells it not to log the current request.
b
- The attribute value.public RestRequest setNoTrace()
public RestRequest setDebug(Boolean b) throws IOException
This flag is used by BasicRestCallLogger
to help determine how a request should be logged.
b
- The attribute value.IOException
- If body could not be cached.public RestRequest setDebug() throws IOException
IOException
- If body could not be cached.public VarResolverSession getVarResolverSession()
Used to resolve SVL variables in text.
VarResolverSession
object can also be passed as a parameter on the method.
public BasicHttpResource getClasspathHttpResource(String name, boolean resolveVars, MediaType mediaType, boolean cached) throws IOException
BasicHttpResource
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 cached
- If IOException
- Thrown by underlying stream.public String getClasspathResourceAsString(String name) throws IOException
name
- The resource name.IOException
- If a problem occurred reading the resource.public String getClasspathResourceAsString(String name, boolean resolveVars) throws IOException
name
- The resource name.resolveVars
- Resolve any SVL variables in the string.IOException
- If a problem occurred reading the resource.public BasicHttpResource getClasspathHttpResource(String name, boolean resolveVars) throws IOException
getClasspathHttpResource(String, boolean, MediaType, boolean)
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
- Thrown by underlying stream.public BasicHttpResource getClasspathHttpResource(String name) throws IOException
getClasspathHttpResource(String, boolean)
with resolveVars == false
name
- The name of the resource (i.e. the value normally passed to Class.getResourceAsStream(String)
.IOException
- Thrown by underlying stream.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.
@Deprecated public Map<String,Widget> getWidgets()
public <T> T getRequest(Class<T> c)
c
- The request bean interface to instantiate.public <T> T getRequest(RequestBeanMeta rbm)
getRequest(Class)
but used on pre-instantiated RequestBeanMeta
objects.rbm
- The metadata about the request bean interface to create.public SerializerSessionArgs getSerializerSessionArgs()
public ParserSessionArgs getParserSessionArgs()
@Deprecated public RestCallLogger getLogger()
Shortcut for calling
RestLogger
object can also be passed as a parameter on the method.
public RestCallLoggerConfig getCallLoggerConfig()
public ResponseBeanMeta getResponseBeanMeta(Object o)
@Response
.o
- The response POJO.@Response
.public ResponsePartMeta getResponseHeaderMeta(Object o)
@ResponseHeader
.o
- The response POJO.@ResponseHeader
.public ResponsePartMeta getResponseBodyMeta(Object o)
@ResponseBody
.o
- The response POJO.@ResponseBody
.public JsonSchemaGenerator getJsonSchemaGenerator()
protected HttpServletRequest getInner()
Copyright © 2016–2020 The Apache Software Foundation. All rights reserved.