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:
http://posample1.appspot.com/
)

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
http://vaadin.com/wiki/-/wiki/Main/Google%20AppEngine%20HOWTO
, and added
true
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.google.appengine.api.users.*;
import com.vaadin.Application;
import com.vaadin.terminal.ExternalResource;
import com.vaadin.ui.*;

public class AppEngineLoginApplication extends Application {

	private static final String HOMEPAGE = "http://posample1.appspot.com/";

	@Override
	public void init() {

		String systemMessage;
		Link l;

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

		// 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));
			vl.addComponent(l);

		} 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));
			vl.addComponent(l);
		}

		setMainWindow(mainWindow);
	}

}

And here’s appengine-web.xml

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
	<application>posample1</application>
	<version>3</version>
	<sessions-enabled>true</sessions-enabled> 
	<!-- Configure java.util.logging -->
	<system-properties>
		<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/> 
	</system-properties>
	
</appengine-web-app>

And web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app id="WebApp_ID">
	<display-name>AppEngingSample1</display-name>
	<context-param>
		<param-name>productionMode</param-name>
		<param-value>false</param-value>
		<description>Vaadin production mode</description>
	</context-param>
	<servlet>
		<servlet-name>Appengingsample1 Application</servlet-name>
		<servlet-class>
		com.vaadin.terminal.gwt.server.GAEApplicationServlet
		</servlet-class>
		<init-param>
			<param-name>application</param-name>
			<param-value>com.example.appengingsample1.AppEngineLoginApplication</param-value>
			<description>Vaadin application class to start</description>
		</init-param>
	</servlet>
	<servlet-mapping>
		<servlet-name>Appengingsample1 Application</servlet-name>
		<url-pattern>/*</url-pattern>
	</servlet-mapping>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>
</web-app>

Hi,

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,
Marc

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.