Few REST APIs not working when i use them via Java.

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

Few REST APIs not working when i use them via Java.

Paritosh
Hi,

I recently started using Glu REST APIs, however i got stuck when i tried to achieve the same via Java.

For example if i do curl request for getting all the fabrics it works -
curl -v -u "<username>:<password>" "http://sd-glu1:8080/console/rest/v1/-"

But when i call the same via java it gives me 302 and redirects to select fabric url. logs for the same -
=============================================
getModelURI- http://sd-glu1.pv.sd.nextag.com:8080/console/rest/v1/-
Exception in thread "main" org.apache.commons.httpclient.HttpException: Glu returned an error for the request containing
Status code: 302
Response headers: [Date: Tue, 19 Aug 2014 03:29:04 GMT
, Set-Cookie: JSESSIONID=yarul85apaz276fe1r12bcvv;Path=/console
, Set-Cookie: rememberMe=deleteMe; Path=/console; Max-Age=0; Expires=Mon, 18-Aug-2014 03:29:05 GMT
, Location: http://sd-glu1.pv.sd.nextag.com:8080/console/fabric/select?__roles=%7BGET%3DUSER%7D
, Set-Cookie: fabric=;Path=/console;Expires=Thu, 01-Jan-1970 00:00:00 GMT
, Expires: Thu, 01 Jan 1970 00:00:00 GMT
, Content-Length: 0
, Server: Jetty(8.1.10.v20130312)
]
Response text:
==============================================

Only API i can successfully test using java is - uploading json model for a fabric but yes all are working correctly when i run them using curl command.

Any thoughts ?

Thanks
Paritosh
Reply | Threaded
Open this post in threaded view
|

Re: Few REST APIs not working when i use them via Java.

frenchyan
Administrator
This is certainly quite odd. Since it works with curl but not with java, it seems pretty obvious that whatever the code is doing to generate the request, is doing it very differently. From the stack trace it looks like you are using httpclient. Are you sure you are setting the authorization header properly?

I am not too sure what is happening, but the best way is to troubleshoot what is going on by thoroughly analyzing the traffic between the client and the server (since it is not encrypted it is pretty easy). For example a tool like tcpmon.

With curl you can usually use the -v option and it shows you the headers. Unclear with httpclient which is why an external tool may just be easier.

Yan