Reputation: 873
hi I'm trying to get all cookies of the browser, like I did in my java projects.
javax.servlet.http.Cookie
String value = "";
Cookie cookie;
Cookie[] allcookies = request.getCookies();
for(int i=0;i<allscookies.length;i++){
cookie = allcookies[i];
if(cookie.getDomain().equals("mydomain") && cookie.getName().equals("cookiename")){
value = cookie.getValue();
}
}
but does not work on my Google App Engine project and I get this error
HTTP ERROR 500
Caused by:
java.lang.NullPointerException
Anyone knows any other way.Also try with this library but can not find how to use it no where com.google.appengine.repackaged.org.json.Cookie
Upvotes: 1
Views: 2033
Reputation: 13620
It's not about GAE.
Cookie[] allcookies = request.getCookies();
May be null
in any environment - it depends on whether the browser sent any cookies for the URL you're calling. Presumably your browser always had some cookies for the test URL you've used before deploying to GAE, and no cookies for the GAE URL.
Simply add an if (allcookies != null) { ... }
around the loop.
Upvotes: 4