class AcmAuditRequestInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
    {
        log.trace("Request audit interceptor called");

        if (auditConfig.getRequestsLoggingEnabled())
        {
            AuditEvent auditEvent = new AuditEvent();
            auditEvent.setEventDate(new Date());
            auditEvent.setIpAddress(MDC.get(MDCConstants.EVENT_MDC_REQUEST_REMOTE_ADDRESS_KEY));
            auditEvent.setRequestId(UUID.fromString(MDC.get(MDCConstants.EVENT_MDC_REQUEST_ID_KEY)));
            auditEvent.setFullEventType(EVENT_TYPE);
            auditEvent.setEventResult(AuditConstants.EVENT_RESULT_SUCCESS);
            auditEvent.setObjectType(AuditConstants.EVENT_OBJECT_TYPE_WEB_REQUEST);
            auditEvent.setStatus(AuditConstants.EVENT_STATUS_COMPLETE);
            auditEvent.setUserId(MDC.get(MDCConstants.EVENT_MDC_REQUEST_USER_ID_KEY) != null
                    ? MDC.get(MDCConstants.EVENT_MDC_REQUEST_USER_ID_KEY)
                    : AuditConstants.USER_ID_ANONYMOUS);
            auditEvent.setEventProperties(getEventProperties(request));

            log.trace("Request created AuditEvent: {}", auditEvent.toString());

            getAuditService().audit(auditEvent);
        }

        return true;
    }

}