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.

Advertisements
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

build.xml
peerwear.war

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">
<classpath>
<pathelement path="${appengine.tools.classpath}"/>
<pathelement path="${models.dir}"/>
</classpath>
<fileset dir="${models.dir}" includes="**/models/*.class"/>
</enhance>
</target

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=0.0.0.0 $*

I have added the argument “–address=0.0.0.0” 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
http://localhost:5581/Apps.

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
http://localhost:5581/home/root/html5-databases/

Sweet.

Posted in webOS | Leave a comment

Importing webOS SDK Samples in Eclipse IDE

Environment:
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