I am trying to access web services through Java in a Google Web Application Project that i created.
The code is supposed to hit the endpoint URL and authenticate the user via the username/password and fetch the jsessionID that the server provides in a cookie. The authentication works fine but I am unable to extract the JsessionID from the cookie.
Following is the code I am using :-
private static String getCookieFromHeaders(HttpURLConnection wsConnection) {
String headerName;
String headerValue = "FAIL";
for (int i = 0;; i++) {
headerName = wsConnection.getHeaderFieldKey(i);
if (headerName != null && headerName.equals("Set-Cookie")) {
headerValue = wsConnection.getHeaderField(i);
break;
}
}
// return the header value (FAIL string for not found)
return headerValue;
}
variable headerName is just giving “null” in an infinite loop.
Please advise, a complete Java noob here.
actually the cookie was being received, the header was “set-cookie” instead of “Set-Cookie”.
Just couldn’t spot it because of the stupid infinite loop!