Google Cloud Endpoint后端 - 是否可以检索HttpSession的属性? [英] Google Cloud Endpoint Backend - Is it possible to retrieve attributes of the HttpSession?
问题描述
我试图从Google Cloud Endpoints后端方法的内部访问 HttpSession
对象(或者可让我获取会话属性的类似API) p>
阅读这个答案我已经知道我可以注入一个 HttpRequest
对象作为参数。
我试图做的是检索facebook 访问令牌以前由Servlet存储。
在开发Web服务器中,我可以检索 HttpSession
并获得所需的属性:
@ApiMethod
public MyResponse getResponse(HttpServletRequest req){
String accessToken =(String)req.getSession()。getAttribute 的accessToken);
}
但是,一旦我将应用程序部署到GAE,令牌始终为空。
那么是否有办法从api方法中恢复会话属性?
如果没有,我如何从其他地方检索我的访问令牌?在提到的问题中的答案和评论建议使用数据存储,但我真的不能想到一个好的自然候选人的关键...就GAE认证机制而言,我的用户甚至没有登录,我不知道如何检索当前的 access_token
>
我已经提交了一个功能请求来支持生产中的会话,如我可以确认它现在不能正常工作。
现在,我建议您继续在标头中的后续请求上传递访问令牌。通过注入的 HttpServletRequest
也可以得到头信息。
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
.
这篇关于Google Cloud Endpoint后端 - 是否可以检索HttpSession的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!