5

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.

SkyWalker
  • 28,384
  • 14
  • 74
  • 132
Sarbyn
  • 340
  • 1
  • 13
  • To make sure I understand you correctly.. the part at the end of your example starting with ID is the body of the Post request, or is it part of the URL? – pczeus Apr 01 '16 at 02:17
  • Is the body of the request – Sarbyn Apr 01 '16 at 19:03
  • I don't see any built in way to automatically parse the request body into a pogo. Are you open to other alternatives? – pczeus Apr 04 '16 at 01:33

2 Answers2

0

Can you try this ?

def readChargify() {
    String requestData = request.reader.text
    def reqMap = org.grails.web.util.WebUtils.fromQueryString(requestData)
}
JChap
  • 1,421
  • 9
  • 23
  • It does not work, for example from the request body `id=81197881&event=statement_settled&payload[site][id]=12345&payload[site][subdomain]=test-sandbox` it will create a request map like: `[id:81197881, event:statement_settled, payload[site][id] : 12345, payload[site][subdomain] : test-sandbox]` and not a nested map like `{id='81197881', event='statement_settled', site=Site{subdomain='test-sandbox', id='12345'}}` – Sarbyn Apr 07 '16 at 13:25
0

This Java library to parse the body of webhooks was contributed by another Chargify customer and may be helpful:

https://github.com/prowave/chargify-webhook-java

Wendy Smoak
  • 168
  • 5