简体   繁体   中英

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. 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.

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. 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 . 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:

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. 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. 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 . Within Eclipse, right-click on the project and select Run As > App Engine or Debug As > 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 .

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