Annotation Type RestEndCall


Identifies a method that gets called right before we exit the servlet service method.

At this point, the output has been written and flushed.

The list of valid parameter types are as follows:

  • Servlet request/response objects:
    • HttpServletRequest
    • HttpServletResponse

The following attributes are set on the HttpServletRequest object that can be useful for logging purposes:

  • "Exception" - Any exceptions thrown during the request.
  • "ExecTime" - Execution time of the request.
Example:

@Rest(...) public class MyResource extends BasicRestServlet { // Log the time it took to execute the request. @RestEndCall public void onEndCall(HttpServletRequest req, Logger logger) { Exception exception = (Exception)req.getAttribute("Exception"); Long execTime = (Long)req.getAttribute("ExecTime"); if (exception != null) logger.warn(exception, "Request failed in {0}ms.", execTime); else logger.fine("Request finished in {0}ms.", execTime); } }

Notes:
  • The method should return void although if it does return any value, the value will be ignored.
  • The method should be public although other visibilities are valid if the security manager allows it.
  • Static methods can be used.
  • Multiple END_CALL methods can be defined on a class.
    END_CALL methods on parent classes are invoked before END_CALL methods on child classes.
    The order of END_CALL method invocations within a class is alphabetical, then by parameter count, then by parameter types.
  • The method can throw any exception, although at this point it is too late to set an HTTP error status code.
  • Note that if you override a parent method, you probably need to call super.parentMethod(...).
    The method is still considered part of the parent class for ordering purposes even though it's overridden by the child class.
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Dynamically apply this annotation to the specified methods.