Handling a WebHook is a straight and forward process in most cases. I’ve stumbled upon a bit of a problem when trying to consume Mailgun Webhooks in Embedded Jersey. My goal was to keep Jersey embedded configuration as light as possible and MultipartConfig annotation wasn’t working out of the box.
In my case the need for handling the events is no more than 10 lines of code. Its job is basically to count the number of bounced, delivered and dropped emails. Thats it.
Inspecting what is being sent from a webhook with requestb.in I figured there are 2 types Content-Type that need to be handled:
Apache Commons FileUpload library provides the parsing of multipart/form content type without the need of additional configuration and native servlet handles the application/x-www-form-urlencoded.
That way i can have 1 servlet and all required parsing in one simple method. The code could be shortened a bit but it does the job without wasting too much time on this.
All we need we’re left to do is Signature Validation and we’re done.
This code is used in www.sixthmass.com project for Automated Funnel Insights in conjunction with email campaigns. In this case Automated Funnels provide insight of conversion paths users chose to take after clicking on a link from email campaign.