简体   繁体   中英

Google Cloud Endpoint Backend - Is it possible to retrieve attributes of the HttpSession?

I'm trying to access the HttpSession object (or similar API that let me fetch session attributes) from inside of a Google Cloud Endpoints backend method...

Reading this answer I've learn that I can inject a HttpRequest object as a parameter.

What I'm trying to do is retrieve a facebook access token previously stored by a Servlet.

Within the Development Web Server I can retrieve the HttpSession and get the desired attribute:

@ApiMethod
public MyResponse getResponse(HttpServletRequest req) {
    String accessToken = (String) req.getSession().getAttribute("accessToken");
}

But, once I deploy my application to GAE, the retrieved access token is always null.

So is there a way to recover session attributes from inside api methods?

And if there isn't, how can I retrieve my access token from someplace else? Answers and comments in the mentioned question suggests the use of the data store, but I really can't think of a good natural candidate for a key... As far as GAE authentication mechanism is concerned my users aren't even logged in, I don't know how to retrieve the access_token of the current user from the Datastore / memcached or any other mechanism.

I've filed a feature request to support sessions in production, as I can confirm it's not working right now.

For now, I recommend you continue passing the access token on subsequent requests in a header. Header information is similarly available through the injected HttpServletRequest .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM