using httpbuilder - how to access response data

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

using httpbuilder - how to access response data

Akhil Kodali
Hi,

My apologies if this is a cross post.
I am trying to use httpbuilder in my grails app. 
There is a REST api which returns xml.
I have pasted the outputs from curl, httpbuilder code and the log4j debug.

Looks like I am missing something obvious?

1. Curl
curl "http://apisell.vendio.com/GetHostedStoresInfoServlet?verb=GCI&GCI.store=akhil20120213&GCI.detailLevel=1"

<?xml version="1.0" encoding="UTF-8" ?><Storefront responseTime="1329470776699" host="apisell04-vm.sv4.prod"><CategoriesInfo><Categories><Category hasSubcategories="Y" id="4188790" index="1" mature="N" name="test" parentId="-1"/><Category hasSubcategories="Y" id="4188791" index="2" mature="N" name="mytest" parentId="-1"/></Categories><Status>Success</Status></CategoriesInfo></Storefront>

2. The httpbuilder code
import groovyx.net.http.*
def http = new HTTPBuilder("http://apisell.vendio.com/GetHostedStoresInfoServlet")
//http.headers."Accept" = 'text/xml'
def options = ["verb":"GCI", "GCI.store":storeAccount.accessName, "GCI.detailLevel":1]
def resp = http.get(query:options)
println resp.data
println resp.data.Storefront.@responseTime

I get just new lines as output


3. The logout put from log4j

2012-02-17 15:04:36,070 [Thread-48] DEBUG http.wire  - >> "GET /GetHostedStoresInfoServlet?verb=GCI&GCI.store=akhil20120213&GCI.detailLevel=1 HTTP/1.1[EOL]"
2012-02-17 15:04:36,071 [Thread-48] DEBUG http.wire  - >> "Accept: */*[EOL]"
2012-02-17 15:04:36,071 [Thread-48] DEBUG http.wire  - >> "Host: apisell.vendio.com[EOL]"
2012-02-17 15:04:36,071 [Thread-48] DEBUG http.wire  - >> "Connection: Keep-Alive[EOL]"
2012-02-17 15:04:36,071 [Thread-48] DEBUG http.wire  - >> "Accept-Encoding: gzip,deflate[EOL]"
2012-02-17 15:04:36,071 [Thread-48] DEBUG http.wire  - >> "[EOL]"
2012-02-17 15:04:36,071 [Thread-48] DEBUG http.headers  - >> GET /GetHostedStoresInfoServlet?verb=GCI&GCI.store=akhil20120213&GCI.detailLevel=1 HTTP/1.1
2012-02-17 15:04:36,071 [Thread-48] DEBUG http.headers  - >> Accept: */*
2012-02-17 15:04:36,071 [Thread-48] DEBUG http.headers  - >> Host: apisell.vendio.com
2012-02-17 15:04:36,071 [Thread-48] DEBUG http.headers  - >> Connection: Keep-Alive
2012-02-17 15:04:36,072 [Thread-48] DEBUG http.headers  - >> Accept-Encoding: gzip,deflate
2012-02-17 15:04:36,376 [Thread-48] DEBUG http.wire  - << "HTTP/1.1 200 OK[EOL]"
2012-02-17 15:04:36,377 [Thread-48] DEBUG http.wire  - << "Server: [EOL]"
2012-02-17 15:04:36,377 [Thread-48] DEBUG http.wire  - << "X-Powered-By: Servlet 2.4; JBoss-4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)/Tomcat-5.5[EOL]"
2012-02-17 15:04:36,377 [Thread-48] DEBUG http.wire  - << "Content-Type: text/xml;charset=UTF-8[EOL]"
2012-02-17 15:04:36,377 [Thread-48] DEBUG http.wire  - << "Cteonnt-Length: 392[EOL]"
2012-02-17 15:04:36,377 [Thread-48] DEBUG http.wire  - << "Date: Fri, 17 Feb 2012 09:34:35 GMT[EOL]"
2012-02-17 15:04:36,377 [Thread-48] DEBUG http.wire  - << "Cache-Control: private[EOL]"
2012-02-17 15:04:36,378 [Thread-48] DEBUG http.wire  - << "Content-Encoding: gzip[EOL]"
2012-02-17 15:04:36,378 [Thread-48] DEBUG http.wire  - << "Content-Length:        242[EOL]"
2012-02-17 15:04:36,378 [Thread-48] DEBUG http.wire  - << "[EOL]"
2012-02-17 15:04:36,378 [Thread-48] DEBUG http.headers  - << HTTP/1.1 200 OK
2012-02-17 15:04:36,378 [Thread-48] DEBUG http.headers  - << Server: 
2012-02-17 15:04:36,378 [Thread-48] DEBUG http.headers  - << X-Powered-By: Servlet 2.4; JBoss-4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)/Tomcat-5.5
2012-02-17 15:04:36,378 [Thread-48] DEBUG http.headers  - << Content-Type: text/xml;charset=UTF-8
2012-02-17 15:04:36,379 [Thread-48] DEBUG http.headers  - << Cteonnt-Length: 392
2012-02-17 15:04:36,379 [Thread-48] DEBUG http.headers  - << Date: Fri, 17 Feb 2012 09:34:35 GMT
2012-02-17 15:04:36,379 [Thread-48] DEBUG http.headers  - << Cache-Control: private
2012-02-17 15:04:36,379 [Thread-48] DEBUG http.headers  - << Content-Encoding: gzip
2012-02-17 15:04:36,379 [Thread-48] DEBUG http.headers  - << Content-Length:        242
2012-02-17 15:04:36,382 [Thread-48] DEBUG http.wire  - << "[0x1f]"
2012-02-17 15:04:36,382 [Thread-48] DEBUG http.wire  - << "[0x8b]"
2012-02-17 15:04:36,382 [Thread-48] DEBUG http.wire  - << "[0x8]"
2012-02-17 15:04:36,382 [Thread-48] DEBUG http.wire  - << "[0x0]"
2012-02-17 15:04:36,382 [Thread-48] DEBUG http.wire  - << "[0x0][0x0][0x0][0x0][0x0][0x3]"
2012-02-17 15:04:36,383 [Thread-48] DEBUG http.wire  - << "[0x8d][0x90]?k[0xc3]@[0xc][0xc5][0xf7]B[0xbf][0x83][0xd0][0xee][0xbf]5[0xb1][0x3]>g([0x4][0xb2]dq:t[0xbc][0xda]Jr[0xe0][0xbb]3[0xa7][0xb3]I[0xbe]}.4[\r][0x1e]2t[0x93]xz?=[0xa9][0xde]\[0xf4][0x0]39V[0xd6][0x8][0xcc][0xe2][0x14][0x81]Lg{eN[0x2][0xbf][0xe][0xdb][0xa8]B[0xd8]4u[0xeb][0xad][0xa3][0xa3][0xb3][0xc6][0x83]#[0x1e][0xad]a:(M[0xc1][0xf1][0x91][0xaf][0x8b]2[0xcb][0xcb]U[0x9e][0x16][0x8]g[0xcb]^[0xa0][0x1c][0x15][0xd3]0[0xa4][0xab]h[0xd6]1[0xcf]E<:[0xdb]cSJO'[0xeb][0x14][0xf1][0xce][0x1c][0xed][0xb2][0xd6]W8Kn[0xa7][0x9f][0xee])[0x9][0xfc]FP[0xbd][0xc0]"[0xab][0xaa]r[0x1d][0x2]*[0xd3][0xd3]%[0xac]F[0xd0][0xd2]O.[0xa4][0xd8]#[0x18]y[0x8f][0xe3][0x89]=[0xc2]([0x1d][0x19][0xbf][0xb][0x9e]([0xc3][0xe4][0xff][0xec]@|[0xb0][0xf3][0x17]l}}MO[0x96]g[0xb4]>[0xd8][0xb8]i[0xa7][0xae]#[0xe6]:y[0xf4][0xcb][0xa1][0xdf][0xdb][0x83][0xf2][0xf7][0xd2][0xe6][0xfd][0xed][0x6][0xe7][0x95][0x83]n[0x88][0x1][0x0][0x0]"


----
Regards,
Akhil Kodali
Reply | Threaded
Open this post in threaded view
|

Re: using httpbuilder - how to access response data

Konstantyn Smirnov
def builder = new HTTPBuilder( 'http://some.url' )      

builder.request( GET, BINARY ){ req ->
        response.failure = { resp -> log.error "resonse status: $resp.status" }
        response.success = { resp, stream ->
          doStuff stream // stream holds your payload data
        }
      }
Reply | Threaded
Open this post in threaded view
|

Re: using httpbuilder - how to access response data

Sebastien Blanc
As a side note, you could also use the rest plugin which encapsulate some of the boiler plate code of httpbuilder

Envoyé de mon iPhone

Le Feb 17, 2012 à 11:24, Konstantyn Smirnov <[hidden email]> a écrit :

> def builder = new HTTPBuilder( 'http://some.url' )      
>
> builder.request( GET, BINARY ){ req ->
>        response.failure = { resp -> log.error "resonse status:
> $resp.status" }
>        response.success = { resp, stream ->
>          doStuff stream // stream holds your payload data
>        }
>      }
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/using-httpbuilder-how-to-access-response-data-tp4396821p4396854.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: using httpbuilder - how to access response data

friar_joe
In reply to this post by Akhil Kodali
Akhil,

If you don't mind, could you tell me how you configured log4j to output httpBuilder log messages?

Thank you!