Uploading a file using HTTP Post and Play! Framework Databinding on Google App engine

Using an http POST and sending to a Play! controller fails if the Controller action declares the request as java.io.File. So doing this would give a null value for the File variable in the controller:

HTML Form:

<form action="@{Application.uploadFile()}" method="POST" enctype="multipart/form-data">
    <input type="text" name="title" size="40"/>
    <input type="file" id="myfile" name="myfile" />
    <input type="submit" value="Send it..." />

And Controller:

    public static void uploadFile(File myfile, String title) {
    	if (myfile != null) {
    		Logger.info("Got a file");
    	} else {
    		Logger.info("Myfile is empty");
    	Logger.info("Title: " + title);

To fix this you should not use File but instead use play.data.Upload type as the argument type:

    public static void uploadFile(Upload myfile, String title) {
    	if (myfile != null) {
    		Logger.info("Got a file");
    	} else {
    		Logger.info("Myfile is empty");
    	Logger.info("Title: " + title);

For the curious the first instance fails on GAE because on GAE file writes are not allowed and the error

java.security.AccessControlException: access denied (java.io.FilePermission…)

is thrown in the Play! method public Map parse(InputStream body)  which tries to save the File to disk.

You can also retrieve the contents by using an undocumented variable in the request. You can obtain a List of Uploads from your controller using

List<Upload> uploads  = (List<Upload>) request.current().args.get("__UPLOADS");

But this is method is hacky and may break in the future.

Posted in Google App Engine, Play framework | Leave a comment

Accessing the Servlet API HttpServletRequest and HttpServletResponse from a Play! Application

The new version of Play! 1.1.2 has a new patch for accessing the request and response.

Here is the ticket

I am currently using git clone so I pull the new sources regularly.

But there is a method for those who are running older versions here

Hope this helps someone struggling to get access to these objects as I was, when trying to upload a file to the Google App Engine.

Posted in Google App Engine | Leave a comment

Updating web.xml on the Play! Framework 1.1.1

Play! automatically creates a web.xml file when deploying your application. There are times when you need to edit web.xml for various reasons.

I needed to setup a listener for Spring and thus needed to edit this file. The instructions for doing this were not easily available so I will outline them here.

First create a new directory in your Play! application “war/WEB-INF”

Now copy the template web.xml from <PLAY_HOME>/resources/war/web.xml to <PLAY_APP_HOME>/war/WEB-INF/.

You would see that this file contains replacement tokens that Play! uses when building you application. These must be left as is.  Otherwise you can edit to your heart’s content.

Posted in Uncategorized | 2 Comments

Installing Oracle Java on Ubuntu 10.10

add-apt-repository “deb http://archive.canonical.com/ lucid partner”
sudo apt-get update
sudo apt-get install sun-java6-bin sun-java6-jdk
sudo update-alternatives –config java

Posted in Uncategorized | Tagged , | Leave a comment

Developing using the Play! Framework, JDO and Google App Engine

The Play! framework is an excellent framework for developing on the Google App Engine. One of the many benefits is that the Play! framework encourages building stateless applications by design. This fits nicely with the GAE which can scale an application much better if it is stateless.

Using JDO on Google App Engine requires that you data model classes undergo instrumentation to allow them to work with Google’s datasource. This post compilation step is done automatically with using the Google SDK or plugin in Eclipse.

But if you work in Play, and “eclipsify” your project then it is not a project configured to use the GAE plugin. I have not found a way to combine the two facets.  Here are the steps that I have taken to get this JDO class enhancement working for a Play! application on GAE.

I have added the jdo config at <PLAY_APPLICATION_ROOT>/war/WEB-INF/classes/META-INF/jdoconfig.xml following the directions at JDO and App Engine.

I then use this Play! command to build an exploded war directory of my application:

play war peerwear -o peerwear.war

Using these instructions I have added an ANT build file at the same level as my Play! application war file. So it looks like this


Since Play! does not store it’s class files in the default location I have edited the build.xml

to add a new target which enhances my model classes:

<property name="models.dir" location="peerwear.war/WEB-INF/application/precompiled/java" />

<target name="datanucleusenhance"
description="Performs JDO enhancement on compiled Play! data classes.">
<enhance failonerror="true" verbose="true">
<pathelement path="${appengine.tools.classpath}"/>
<pathelement path="${models.dir}"/>
<fileset dir="${models.dir}" includes="**/models/*.class"/>

Now I can run “ant datanucleusenhance” to enhance the model classes.

To deploy to GAE locally I use

/bin/dev_appserver.sh peerwear.war/
Posted in Google App Engine, JDO | Tagged , | Leave a comment

Changing the listening address of the Google App Engine Jetty Server

Google App Engine (GAE) uses Jetty as the embedded webserver for the SDK. When developing locally the webserver listens on the localhost address and on port 8080.

But if you want to connect from an external address then you have to change this to listen at your external address.  This can be done it many ways, the simplest way is to pass a parameter to the startup script used by the GAE SDK.

I use Linux but it should be similar on Windows also.

Find <APP_ENGINE_SDK>/bin/dev_appserver.sh

Edit the last line so that it looks like:

com.google.appengine.tools.development.DevAppServerMain –address= $*

I have added the argument “–address=” which tells the server to listen on all addresses.

You can find the official documentation here: http://code.google.com/appengine/docs/java/tools/devserver.html


Posted in Google App Engine | Leave a comment

Emulator Host Mode on Emulator

There is a very easy way to download files off the emulator that is given very little recognition in the Palm development documentation. It may be so because it is still beta; indeed I never got it to work as intended. Emulator Host Mode is supposed to allow a developer to view a webos application in a desktop browser. It does so by forwarding a local port on the emulator via shh. The command to accomplish this on Linux is:

ssh -p 5522 -L 5581:localhost:8080 root@localhost

After doing this you should be able to browse internal and third-party apps at

http://localhost:5581/PalmApps and

But I simply point my browser at http://localhost:5581 to see the entire emulator contents. One use I have found is to download html5 databases for offline inspection. These are stored at


Posted in webOS | Leave a comment

Importing webOS SDK Samples in Eclipse IDE

Ubuntu: Ubuntu 10.04 LTS – Lucid Lynx
Eclispse: Eclipse Java EE IDE for Web Developers 3.6.*
WebOS SDK: palm-sdk_1.4.5-svn307799-sdk1457-pho465_i386.deb

The samples are installed at /opt/PalmSDK/Current/share/samplecode/samples

Create a new project with the same name as the sample you wish to import:

Ex: For the UIWidgets sample

Navigate to – File>New>Palm webOS>Basic Application
In Project Name enter “UIWidgets” and select Finish
Right-Click on the new UIWidgets project and Select Import>File System
Browse to /opt/PalmSDK/Current/share/samplecode/samples/UIWidgets
Select All and click Finish
On the next screen when prompted choose to overwrite all files.

You should now be able to run this application on the Emulator or the Device.

Posted in webOS | Tagged , , | Leave a comment