简体   繁体   English

Servlet中的App Engine UserService调用引发线程异常-Eclipse Java

[英]App Engine UserService calls in servlet throw thread exception - Eclipse java

I have a basic Google App Engine java project in Eclipse that uses GWT. 我在Eclipse中有一个使用GWT的基本Google App Engine Java项目。 I followed the instructions to set up the app engine SDK and latest GWT in Eclipse and set the environment variables path in Windows to point to the SDK root folder. 我按照说明在Eclipse中设置了App Engine SDK和最新的GWT,并在Windows中将环境变量路径设置为指向SDK根文件夹。

When a login servlet is called by clicking the login link on the start page (as defined in the web.xml file) the call is routed to my HttpServlet handler class as expected. 通过单击起始页上的登录链接(在web.xml文件中定义)调用登录servlet时,调用将按预期路由到我的HttpServlet处理程序类。 So that works fine. 这样就可以了。 In the code I create the UserService via the factory method, but then any call such as isUserLoggedIn() or createLoginURL() results in an exception . 在代码中,我通过factory方法创建了UserService,但是任何调用(例如isUserLoggedIn()或createLoginURL())都会导致异常 I'm hoping the problem is obvious but I've spent hours trying to figure out what is causing this problem with no luck :( 我希望问题很明显,但是我花了数小时试图找出是什么原因导致了这个问题,但是没有运气:(

protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException, ServletException {

    UserService userService = UserServiceFactory.getUserService();
    if (userService.isUserLoggedIn()) {

Here is the console output for when the call to isUserLoggedIn() happens: 这是调用isUserLoggedIn()时的控制台输出:

java.lang.IllegalStateException: Operation not allowed in a thread that is neither the original request thread nor a thread created by ThreadManager
at com.google.appengine.api.users.UserServiceImpl.getCurrentEnvironmentOrThrow(UserServiceImpl.java:152)
at com.google.appengine.api.users.UserServiceImpl.isUserLoggedIn(UserServiceImpl.java:96)

Does this look familiar to anyone using this type of development environment? 使用这种类型的开发环境的任何人看起来都熟悉吗? I'm hoping it is a simple setting in the project or xml config files or something I'm missing. 我希望它是项目或xml配置文件中的简单设置,或者是我所缺少的东西。 I've successfully run similar code several years ago but just getting back to working with GAE so maybe something important has changed with servlets or project setup. 几年前,我已经成功运行了类似的代码,但只是回到了GAE的工作,所以servlet或项目设置可能已经改变了一些重要的事情。 Thanks so much for any help and tips. 非常感谢您的帮助和提示。

To make use of App Engine APIs, you must run/debug your apps locally using the Development App Server . 要使用App Engine API,您必须使用Development App Server在本地运行/调试应用程序 Within Eclipse, right-click on the project and select Run As > App Engine or Debug As > App Engine . 在Eclipse中,右键单击项目,然后选择运行方式> App Engine调试方式> App Engine See the docs for a bit more detail. 有关更多详细信息,请参阅文档

To enable GWT, you'll need to configure the GWT SDM Builder by right-clicking on the project and selecting Configure > Enable GWT SDM builder . 要启用GWT,您需要通过右键单击项目并选择Configure> Enable GWT SDM builder配置GWT SDM Builder

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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