Thursday, April 7, 2016

Parsing FORM-ENCODED parameters with GRAILS (chargify webhooks)

Leave a Comment

I have a GRAILS 3 controller that receive an HTTP post from a webservice (Chargify) with this format (the payload section has about 100 entries with a lot of sub-fields):

POST / HTTP/1.1 Accept: */*; q=0.5, application/xml Accept-Encoding: gzip, deflate Content-Type: application/x-www-form-urlencoded X-Chargify-Webhook-Id: 81309408 X-Chargify-Webhook-Signature: xxxxxxxxxxxxx X-Chargify-Webhook-Signature-Hmac-Sha-256: yyyyyyyyyyyyyy Content-Length: 48 User-Agent: Ruby X-Newrelic-Id: xxxxxx X-Newrelic-Transaction: aaaaaaaaaaaaaa= Host: myhost.test.it  id=81197881&event=statement_settled&payload[site][id]=12345&payload[site][subdomain]=test-sandbox 

Is there any way with GRAILS to parse the "payload" part and convert it dynamically to a POJO (or also a simple hashmap)?. Chargify use this strange format not recognized by GRAILS framework and I'm unable to parse it automatically.

Is there anyone to help me for parsing? Advance thanks for helping.

1 Answers

Answers 1

Can you try this ?

def readChargify() {     String requestData = request.reader.text     def reqMap = org.grails.web.util.WebUtils.fromQueryString(requestData) } 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment