Using the IRestDispatchPlugin plugin
The IRestDispatchPlugin interface contains methods to preprocess, handle,
and log REST API requests. Guidewire provides a default implementation class for the plugin,
DefaultRestDispatchPlugin. However, if you want to implement your own
implementation class for the IRestDispatchPlugin plugin, keep the following
details in mind.
Preprocessing the request
- handleReceiveRequest
- handlePreExecute
The preprocessing of the request can occur either prior to the start of the work of handling the request or prior to invoking the API handler that performs the actual work of the request.
Use preprocessing to set global variables on the method's RequestContext object, or to set any other global context that needs to be thread-local, such as logging contexts. You can also use preprocessing to log request information prior to the start of the work of processing the request.
Rewriting the response to the request
Use the rewriteResponse method on the IRestDispatchPlugin interface to rewrite outgoing responses generated by the request. For example, you can create a lightweight servlet filter to inject global custom response headers or to implement CORS (cross-origin resource sharing) by rewriting the responses for OPTIONS requests to include the appropriate CORS headers.
Rewriting errors generated by a request
Use the rewriteErrorInfo method on the IRestDispatchPlugin interface to control exactly what error and exception information the plugin returns while handling the REST request. It is important to understand that the plugin invokes the rewriteErrorInfo method only if the response framework or the API handler throws an error or exception during request processing.
Use your implementation of the rewriteErrorInfo method to define your own specific best practices around information exposure in error messages. Different environments or different teams have different tolerances for exposing detailed error information to client systems. As it is possible to provide implementation classes for the plugin that behave differently in production and development environments, you can specifically set a more restrictive set of policies to apply to production servers, while allowing development systems to return more detailed information.
Logging the request activity
The handleRequestProcessed method on the IRestDispatchPlugin interface uses arguments whose values provide information and context about the processing of the REST request, for example:
- The amount of time that the request took
- The response the request generated
- Any errors or exceptions thrown during the course of processing the request
