Vaadin + Google AppEngine. Weird behaviour.

Hi there all!

I just started playing with Vaadin, and to make life a bit more difficult, I decided to do it in combination with Googles App Engine (also for the first time), all in one go. (Here’s my tiny little app deployed:

What I try to do is a minimal example that uses the Google Accounts API for logging in and logging out.

Deploying the app works fine, and the page comes up as expected.

Clicking on the Login link works fine, and the login verification seems to be successful.

When coming back to the app, it doesn’t seem to be able to detect that I’m actually logged in.

(And as a curious fact, I’ve also managed to end up in a situation where my app beleived me to be logged in. And then when clicking the Logout-link, it wouldn’t recognize me as being logged. out.

I’ve followed the instructions at
, and added
to my appengine-web.xml .

What is the matter with this? Am I being too naïve about it, or is there some problem in the combination Vaadin/App Engine? Any help is greatly appreciated.

Kind Regards,
Peter Olin

Heres the code :

package com.example.appengingsample1;

import com.vaadin.Application;
import com.vaadin.terminal.ExternalResource;
import com.vaadin.ui.*;

public class AppEngineLoginApplication extends Application {

	private static final String HOMEPAGE = "";

	public void init() {

		String systemMessage;
		Link l;

		// Create the basic display area
		Window mainWindow = new Window("3 Vaadin + AppEngine Login");
		VerticalLayout vl = new VerticalLayout();

		// Get user/login details
		UserService userService = UserServiceFactory.getUserService();
		User user = userService.getCurrentUser();

		// Test login status and display appropriate info and link.
		if (user == null || !userService.isUserLoggedIn()) {
			systemMessage = "You are not logged in. Please login.";
			vl.addComponent(new Label(systemMessage));
			String loginUrl = userService.createLoginURL(HOMEPAGE);
			l = new Link("Login", new ExternalResource(loginUrl));

		} else {

			systemMessage = "Hello " + user.getNickname() + "("
					+ user.getEmail() + ")" + "! All you can do is to logout.";
			vl.addComponent(new Label(systemMessage));
			String logoutUrl = userService.createLogoutURL(HOMEPAGE);
			l = new Link("Logout", new ExternalResource(logoutUrl));



And here’s appengine-web.xml

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="">
	<!-- Configure java.util.logging -->
		<property name="java.util.logging.config.file" value="WEB-INF/"/> 

And web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "">
<web-app id="WebApp_ID">
		<description>Vaadin production mode</description>
		<servlet-name>Appengingsample1 Application</servlet-name>
			<description>Vaadin application class to start</description>
		<servlet-name>Appengingsample1 Application</servlet-name>


The problem is probably that init() is not called when you come back - it’s only called when the Application is first created (once for the lifetime of a session, if you don’t explicitly close the application).

Try using a parameter handler if you can make Google Accounts API pass a parameter to your application, or perhaps a transaction listener, which is called each time a request is handled by the application.
There are other ways as well, ymmv.

Best Regards,

Just as Marc explained, init() is wrong place to check for authentication.

Your authentication code seems to work though. I pressed login, logged in and then added ?restartApplication to url. The new application instance called init() and correctly recognized that I had logged in.