我使用 Google Channel api 并在 adreess /_ah/channel/connected/ 注册了 servlet 来处理用户通道连接。当在发布消息处理程序中发生连接时,我发现 UserServiceget.CurrentUser() 返回 null,而在我的应用程序的其他 servlet 中它返回用户。请问是什么情况告诉我。servlet 代码是这样的:
@SuppressWarnings("serial")
public class ConnectServlet extends HttpServlet {
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if( user != null ){
String user_name = user.getNickname();
Logger.getLogger("server").log( Level.WARNING, "User " + user_name + " connected" );
}
}
}
安全约束是:
<security-constraint>
<web-resource-collection>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
</security-constraint>