Problems When Deploying Working Application on Google App Engine

Table of contents
Reading Time: 3 minutes

Google Dev and production environment has differences. You may run into problems if you expect that application will also run fine on app engine if there are no errors on app engine development server. We are in process of porting an existing application on Google App engine. The application we are building uses Wicket, Spring and JPA. If you read the will it play in app engine you will find that Spring is compatible, Jpa works with datanucleus implementation and Wicket is semi compatible.

Most of the work required for porting the application required changes in data layer of the application. You can read more about the way to use jpa for persistence in Google App engine here. Wicket does work with the workarounds mentioned here. For wicket application we need to enable sessions in app engine config file.
[sourcecode]
<sessions-enabled>true</sessions-enabled>
[/sourcecode]

Second we need to disable thread monitoring resource watcher.
[sourcecode language=”java”]
@override
protected void init() {
super.init();
this.getResourceSettings().setResourcePollFrequency(null);
}
[/sourcecode]

and at last we need to override the newSessionStore() to return HttpSession store because the default second level session store uses java.io.File which Google App Engine does not allow.
[sourcecode language=”java”]
@override
protected void newSessionStore() {
return new HttpSessionStore(this);
}
[/sourcecode]

After the changes described above for porting the application we were able to successfully run the application on Google App Engine development server. Finally we tried deploying the working application on Google App Engine. It was a different story, to our surprise the application simply failed to start on Google App Engine environment.

First problem we encountered was that our application did not start on Google App Engine after it failed with the trace: “java.lang.NoClassDefFoundError: javax/naming/NamingException”. Some classes in Spring JPA support uses javax.naming.NamingException which is not available in Google App Engine. There is an issue logged here. We are using Spring version 2.5.6 and we used the following workaround. We defined a bean in our application context file.
[sourcecode]
<bean id="org.springframework.context.annotation.internalPersistenceAnnotationProcessor" class="com.inphina.rrm.GaeFixInternalPersistenceAnnotationProcessor" />
[/sourcecode]
and created a class GaeFixInternalPersistenceAnnotationProcessor.
[sourcecode language=”java”]
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GaeFixInternalPersistenceAnnotationProcessor {

private static final Logger log = LoggerFactory.getLogger(GaeFixInternalPersistenceAnnotationProcessor.class);

public GaeFixInternalPersistenceAnnotationProcessor() {
log.info("Creating fake internalPersistenceAnnotationProcessor to bypass GAE blacklist problem");

}

}
[/sourcecode]

This resolved the error and our application came up to life. But our excitement died out soon the moment we logged in our application. We just encountered our second problem we encountered a trace “java.lang.RuntimeException: java.io.NotSerializableException: org.datanucleus.store.appengine.query.DatastoreQuery$2″.

This problem occurred when we directly used the query results in our Wicket components. The query result returned by the data nucleus implementation is not serializable. As it is evident from the error, we can only use classes that can be Serialized in our wicket components. The work around for this problem was to use an unattached list of objects rather than an attached list. For example if we have a DAO which returns a List of departments in our Wicket component then we have to make sure we create a new List of departments and add all elements of departments returned from the DAO.
Here is the old code
[sourcecode language=”java”]
List<Department> departments = departmentDAO.findAll();
[/sourcecode]
after the discussed changes
[sourcecode language=”java”]
List<Department> departments = new ArrayList();
departments.addAll(departmentDAO.findAll());
[/sourcecode]

We learnt that there are differences in the Google App Engine development server environment and Google App Engine environment. We expected that if an application works fine on Google App Engine development environment then it will do the same on Google App Engine environment. Can it also happen that application runs fine on Google App Engine environment but not so on our development environment? well for now, none that we have encountered. From our experience of porting our application to Google App Engine, the help Google App engine community, we believe that it is a fantastic platform to port our application to and with time it will grow better and better.

1 thought on “Problems When Deploying Working Application on Google App Engine4 min read

Comments are closed.

Discover more from Knoldus Blogs

Subscribe now to keep reading and get access to the full archive.

Continue reading