Working with RequestContext objects
Public interface RequestContext contains the following useful methods
for working with
RequestContext objects. - getApiFqn()
- The method returns the fully-qualified name of the Swagger schema that published this API, if any. The getApiFqn method is not available with the IRestDispatchPlugin.handleReceiveRequest(RequestContext) method.
- getBodyAsBytes()
- The method returns the body of the request as a
byte[]array. - getBodyAsString()
- The method returns the body of the request as a
Stringobject. - getHeaderParameterValue(headerName)
- The method returns the deserialized value of the named header parameter. This method does not work for arbitrary request headers. It only works for header parameters listed explicitly as part of the operation. The getHeaderParameterValue method is not available with the IRestDispatchPlugin.handleReceiveRequest(RequestContext) method.
- getLogger()
- The method returns the logger (
Logger) in use for logging within this request context. - getOperation()
- The method returns the operation information needed to execute this request. The getOperation method is not available with the IRestDispatchPlugin.handleReceiveRequest(RequestContext) method.
- getPathParameterValue(pathName)
- The method returns the deserialized value of the given path parameter. The getPathParameterValue method is not available with the IRestDispatchPlugin.handleReceiveRequest(RequestContext) method.
- getPathTemplate()
- The method returns the template-formatted path string that the REST API framework
matched for this request, if any. For example, suppose the following:
- The Swagger schema has a base path of /contacts/v1.
- The path item has a path of /contacts/{contactId}.
- The incoming request is to path /contacts/v1/contacts/cc:123.
- /contacts/v1/contacts/{contactId}
- getProperty(property)
- The method returns a previously stored property value given the property name as
input. The input name cannot be
null. - getQueryParameterValue(parameterName)
- The method returns the deserialized query parameter value, rather than the raw
String value. The method returns
nullfor both of the following cases:- Query parameters that appear with no value.
- Query parameters that do not appear at all.
- getRawHeaderValue(headerName)
- The method takes the name of a request header as input
(
headerName). The return value is one of the following:- The raw String value for the given header.
- A comma-separated list of the raw String values if the header appears multiple times in the request.
- A
nullvalue if the header is not included in the request.
getHeaderParameterValuemethod instead of the getRawHeaderValue method. - getRawPathParameters()
- The method returns the set of raw path parameter values extracted from the request
path as
Map<String, String>. - getRawQueryParameterNames()
- The method returns the query parameter names found in this request as
Set<String>. - getRawQueryParameterValues(queryParameter)
- The method takes the name of a query parameter as input
(
queryParameter). The return value is one of the following:- A
Listobject that contains the values with which the parameter appeared. - An empty list if the parameter appears without any value.
- A
nullvalue if the query parameter does not appear anywhere in the queryString.
- A
- getRawRequest()
- The method returns the raw
HttpServletRequestobject associated with this request. - getRequestContentType()
- The method returns the request content type (as a
MediaTypeobject), as specified in theContent-Typeheader of the request. - getRequestStartTime()
- The method returns the timestamp (as a
Dateobject) for when the API received the REST request. - getResponseContentType()
- The method returns the negotiated content type of the API response.
- hasQueryParameter(queryName)
- The method returns one of the following:
true- The specified query parameter exists in the request's query string.false- The query parameter does not appear on the request's query string.
- pushCloseable(block)
- The method adds an
AutoCloseableobject that the REST API framework executes upon completion of the REST request. - putProperty(property, value)
- The method stores property values. It uses the following inputs:
property- The property name, which cannot benull.value- The property value.
The method returns the data type of the value stored in this operation.
- setLogger(logger)
- The method sets the logger to use for logging with this request context.
