3

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.

Community
  • 1
  • 1
Anthony Accioly
  • 21,918
  • 9
  • 70
  • 118

1 Answers1

6

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.

Dan Holevoet
  • 9,183
  • 1
  • 33
  • 49
  • Hi Dan, thanks for the report. I'm calling the endpoints directly through client ajax requests and I don't want to share the token between the client and the server... Is there a way to inject the access_token on the header at the server side? Maybe something like a `Filter`)? – Anthony Accioly Oct 22 '13 at 19:26
  • Another question... Seems like jcache (memcache) is also not working on the production server when requesting a cache entry from inside an api method (I can retrieve the same attribute through a Servlet and also through the memcache console...). Do you know if jcache was supposed to work? – Anthony Accioly Oct 23 '13 at 00:09
  • So are you saying it's not possible to use sessions with google app engine endpoints? It's been a year since you filed the request, any news? – hordurh Nov 19 '14 at 15:05
  • @hordurh it seems fixed now, it's added to the docs. Check this: https://cloud.google.com/appengine/docs/java/config/appconfig#Java_appengine_web_xml_Enabling_sessions – Pega88 Jan 03 '15 at 18:06
  • @Pega88, the linked article does not talk about implementation with Cloud Endpoints (CE). The sessions already worked with Servlets but not with CE. – Price Nov 18 '15 at 03:53