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 String object.
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.
In this case, the method returns the template-formatted path string as the following:
  • /contacts/v1/contacts/{contactId}
The getPathTemplate method is not available with the IRestDispatchPlugin.handleReceiveRequest(RequestContext) method.
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 null for both of the following cases:
  • Query parameters that appear with no value.
  • Query parameters that do not appear at all.
The getQueryParameterValue method is not available with the IRestDispatchPlugin.handleReceiveRequest(RequestContext) method.
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 null value if the header is not included in the request.
To retrieve the deserialized value of a header explicitly declared in the schema as a header parameter, use the getHeaderParameterValue method 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 List object that contains the values with which the parameter appeared.
  • An empty list if the parameter appears without any value.
  • A null value if the query parameter does not appear anywhere in the query String.
To retrieve the deserialized value rather than the raw String value, use the getQueryParameterValue method instead of the getRawQueryParameterValues method.
getRawRequest()
The method returns the raw HttpServletRequest object associated with this request.
getRequestContentType()
The method returns the request content type (as a MediaType object), as specified in the Content-Type header of the request.
getRequestStartTime()
The method returns the timestamp (as a Date object) 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 AutoCloseable object 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 be null.
  • 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.