RestBuilder authorization

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

RestBuilder authorization

wxlund
I need to build an additional report page from information using the Restful API to vFabric Data Director.  The call works from the command line with curl:

curl -k --user user:password -s -S -i -H "Accept: application/json" -X GET  "https://[ip]:443/datadirector/api/databases/"
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Cache-Control: private
Expires: Thu, 01 Jan 1970 00:00:00 UTC
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 31 Oct 2012 15:48:08 GMT

[{"href":"https://114.80.85.36/datadirector/api/database/187","name":"a","description":null},{"href":"https://114.80.85.36/datadirector/api/database/182","name":"sp","description":null},{"href":"https://114.80.85.36/datadirector/api/database/180","name":"aftab","description":null},{"href":"https://114.80.85.36/datadirector/api/database/189","name":"a","description":null}]

but with Restbuilder I get the following:

def restBuilder = new RestBuilder()
result = restBuilder.get("http://114.80.85.36:443/datadirector/api/databases") {
        auth(user, password)
        contentType("application/json")
}
println result

console:

Caught: org.springframework.web.client.ResourceAccessException: I/O error: Unexpected end of file from server; nested exception is java.net.SocketException: Unexpected end of file from server
org.springframework.web.client.ResourceAccessException: I/O error: Unexpected end of file from server; nested exception is java.net.SocketException: Unexpected end of file from server
        at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:453)
        at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:401)
        at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:377)
        at grails.plugins.rest.client.RestBuilder.doRequestInternal(RestBuilder.groovy:73)
        at grails.plugins.rest.client.RestBuilder.get(RestBuilder.groovy:34)
        at grails.plugins.rest.client.RestBuilder$get.call(Unknown Source)
        at TestDDRest.run(TestDDRest.groovy:13)
Caused by: java.net.SocketException: Unexpected end of file from server
        at org.springframework.http.client.SimpleClientHttpResponse.getStatusCode(SimpleClientHttpResponse.java:48)
        at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:46)
        at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:439)
        ... 6 more

What am I doing wrong?
Reply | Threaded
Open this post in threaded view
|

Re: RestBuilder authorization

pledbrook
> but with Restbuilder I get the following:
>
> def restBuilder = new RestBuilder()
> result =
> restBuilder.get("http://114.80.85.36:443/datadirector/api/databases") {

It may be because you're accessing the URL via HTTP rather than HTTPS,
although the exception isn't very helpful here.

You might want consider configuring RestTemplate to use Apache
HttpClient as described in this blog post:

    http://aruld.info/resttemplate-the-spring-way-of-accessing-restful-services/

The reason for that is you can enable logging of the requests and the
responses via

    debug "httpclient.wire"

Alternatively, use a proxy to inspect the requests and responses, such
as Charles on Mac.

Hope that helps,

Peter

--
Peter Ledbrook
Developer Advocate
VMware

t: @pledbrook

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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: RestBuilder authorization

sameer23
In reply to this post by wxlund
My friend have told me about how to restart in windows 10 So this makes you visible to many things.