public void handleEvent ( HttpServletRequest request ) throws GitLabApiException { String eventName = request . getHeader ( "X-Gitlab-Event" ) ; if ( eventName == null || eventName . trim ( ) . isEmpty ( ) ) { LOGGER . warning ( "X-Gitlab-Event header is missing!" ) ; return ; } if ( ! isValidSecretToken ( request ) ) { String message = "X-Gitlab-Token mismatch!" ; LOGGER . warning ( message ) ; throw new GitLabApiException ( message ) ; } LOGGER . info ( "handleEvent: X-Gitlab-Event=" + eventName ) ; switch ( eventName ) { case BuildEvent . BUILD_HOOK_X_GITLAB_EVENT : case BuildEvent . JOB_HOOK_X_GITLAB_EVENT : case IssueEvent . X_GITLAB_EVENT : case MergeRequestEvent . X_GITLAB_EVENT : case NoteEvent . X_GITLAB_EVENT : case PipelineEvent . X_GITLAB_EVENT : case PushEvent . X_GITLAB_EVENT : case TagPushEvent . X_GITLAB_EVENT : case WikiPageEvent . X_GITLAB_EVENT : break ; default : String message = "Unsupported X-Gitlab-Event, event Name=" + eventName ; LOGGER . warning ( message ) ; throw new GitLabApiException ( message ) ; } try { Event event ; if ( LOGGER . isLoggable ( Level . FINE ) ) { LOGGER . fine ( HttpRequestUtils . getShortRequestDump ( eventName + " webhook" , true , request ) ) ; String postData = HttpRequestUtils . getPostDataAsString ( request ) ; LOGGER . fine ( "Raw POST data:\n" + postData ) ; event = jacksonJson . unmarshal ( Event . class , postData ) ; LOGGER . fine ( event . getObjectKind ( ) + " event:\n" + jacksonJson . marshal ( event ) + "\n" ) ; } else { InputStreamReader reader = new InputStreamReader ( request . getInputStream ( ) ) ; event = jacksonJson . unmarshal ( Event . class , reader ) ; } event . setRequestUrl ( request . getRequestURL ( ) . toString ( ) ) ; event . setRequestQueryString ( request . getQueryString ( ) ) ; fireEvent ( event ) ; } catch ( Exception e ) { LOGGER . warning ( "Error parsing JSON data, exception=" + e . getClass ( ) . getSimpleName ( ) + ", error=" + e . getMessage ( ) ) ; throw new GitLabApiException ( e ) ; } }
Parses and verifies an Event instance from the HTTP request and fires it off to the registered listeners .