public EventHandlerStatus dispatchEvent ( HttpServletRequest httpRequest ) { ApiContext apiContext = new MozuApiContext ( httpRequest ) ; Event event = null ; // get the event from the request and validate try { String body = IOUtils . toString ( httpRequest . getInputStream ( ) ) ; logger . debug ( "Event body: " + body ) ; event = mapper . readValue ( body , Event . class ) ; logger . info ( "Dispatching Event. Correlation ID: " + event . getCorrelationId ( ) ) ; if ( ! Crypto . isRequestValid ( apiContext , body ) ) { StringBuilder msg = new StringBuilder ( "Event is not authorized." ) ; logger . warn ( msg . toString ( ) ) ; return ( new EventHandlerStatus ( msg . toString ( ) , HttpServletResponse . SC_UNAUTHORIZED ) ) ; } } catch ( IOException exception ) { StringBuilder msg = new StringBuilder ( "Unable to read event: " ) . append ( exception . getMessage ( ) ) ; logger . error ( msg . toString ( ) ) ; return ( new EventHandlerStatus ( msg . toString ( ) , HttpServletResponse . SC_INTERNAL_SERVER_ERROR ) ) ; } try { invokeHandler ( event , apiContext ) ; } catch ( Exception exception ) { StringBuilder msg = new StringBuilder ( "Unable to process event with correlation id " ) . append ( event . getCorrelationId ( ) ) . append ( ". Message: " ) . append ( exception . getMessage ( ) ) ; logger . error ( msg . toString ( ) ) ; return ( new EventHandlerStatus ( msg . toString ( ) , HttpServletResponse . SC_INTERNAL_SERVER_ERROR ) ) ; } return ( new EventHandlerStatus ( null , HttpServletResponse . SC_OK ) ) ; }
Takes the event notification message parses it and dispatches the event to the registered handler for the event category and type .