I am writing a test application for using Google's App Engine. I would like to provide login functionality using the default UserService. To login, a request i made from the client to the server:
public class ShoppingList implements EntryPoint {
...
private ShoppingListServiceAsync service = (ShoppingListServiceAsync) GWT.create(ShoppingListService.class);
public void onModuleLoad() {
login();
}
private void login() {
AsyncCallback callback = new AsyncCallback() {
@Override
public void onFailure(Throwable caught) {
Window.alert("Login failed.");
}
@Override
public void onSuccess(Object result) {
Window.open((String) result, "_self", "");
}
};
// Get login URL; after login, return to current page.
service.getLoginURL(GWT.getHostPageBaseURL(), callback);
}
}
The server generates the login URL which is returned to the client:
public class ShoppingListServiceImpl extends RemoteServiceServlet implements ShoppingListService {
...
@Override
public String getLoginURL(String returnURL) {
UserService userService = UserServiceFactory.getUserService();
Boolean loggedIn = userService.isUserLoggedIn();
String url = userService.createLoginURL("http://google.com");
User user = userService.getCurrentUser();
return returnURL;
}
}
The code compiles and runs. Now, my problem is that the userService object is somehow not loaded correctly. When i call any method on it (e.g. isUserLoggedIn()) a null pointer exception is thrown. What am i missing?
Since you didn't post the Code of UserServiceFactory, it's hard to figure out the source of your problem. But I guess that the UserService-Instance is not instanciated correctly in your Factory.