Category Archives: AppEngine

Getting Started With Spring MVC and Google App Engine

It is amazingly easy to get Spring running on Google App Engine. Here is how you do it.

Install the development environment

I’m assuming you installed a recent version of the JDK. Once Java is installed on your system download either Eclipse or the Spring Tool Suite (STS), which is build on top of Eclipse.

I personally decided for the Spring Tool Suite because it makes it ridiculously simple to install additional plug-ins like for example the Google Plugin and comes with support for Groovy and Grails which I both want to try out at some point. After starting up STS, you’re presented with the STS Dashboard.

Click on the “Extensions”-link and search for the “Google Plugin”. I already installed it, that’s why it’s displayed as installed on below screenshot, but when you get to that page the first time, you can click the check-box on the left and then hit the “Install” button in the lower right corner. It will take a little to install the plugin, but once that’s done you’re ready to go.

Create an App Engine Project

For the sake of simplicity I will create an App Engine project only without Google Web Toolkit. Click on the Google Plugin icon () and specify a project name, a package and disable the GWT check-box.

The plug-in will auto-generate some example code for you which you can deploy straight away to App Engine.

Deploying the App to App Engine

If you haven’t signed up for Google App Engine yet, now is the right time to do so: code.google.com/intl/de/appengine.
Next navigate to appengine.google.com. All you will see is a rather empty screen (at least if you just signed up for App Engine). Click on the “Create Application”-button and fill in the form.

Typically it requires some creativity to select an app ID. I usually use the name I want to use and add some random numbers. That works out well most of the time. If you plan to develop and production application, the app ID doesn’t really matter anyway because you can use a custom domain later on. Once things are set up on Google’s side, hit the “Deploy”-button in STS:

On the upcoming screen, click “App Engine Project Settings …” and specify the app ID you chose in the last step.

Type in the app ID and confirm with OK. Now type in your Gmail address and the password and hit deploy. After a couple of seconds your app will be available at “your app id”.appspot.com.

Adding Spring

Now you will add Spring to the application. Instead of using a simple servlet to return the “Hello World” string you will use a Spring MVC controller.

Adding the right JARs

  1. Download the latest version of Spring 3. I used Spring 3.0.4.
  2. Extract the zip file a copy following JARs to the /war/WEB-INF/lib directory:
    • org.springframework.asm-3.0.4.RELEASE.jar
    • org.springframework.beans-3.0.4.RELEASE.jar
    • org.springframework.context-3.0.4.RELEASE.jar
    • org.springframework.core-3.0.4.RELEASE.jar
    • org.springframework.expression-3.0.4.RELEASE.jar
    • org.springframework.web-3.0.4.RELEASE.jar
    • org.springframework.web.servlet-3.0.4.RELEASE.jar
  3. Additionally you’ll have to add these JARs to your lib directory:
  4. Rename commons-logging-1.1.1.jar to something else, e.g. commons-logging-1.1.1-personal.jar
  5. Add the JARs to your Build Path.

Configuring the App

First, you tell the application to use the Spring Dispatcher Servlet and map it to the root URL. This is the web.xml after the changes:

< ?xml version="1.0" encoding="utf-8"?>
<web -app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
	<servlet>
        </servlet><servlet -name>SpringAppEngine</servlet>
        <servlet -class>org.springframework.web.servlet.DispatcherServlet</servlet>
        <load -on-startup>1</load>
 
	<servlet -mapping>
        </servlet><servlet -name>SpringAppEngine</servlet>
        <url -pattern>/</url>
 
	<welcome -file-list>
		</welcome><welcome -file>index.html</welcome>
 
</web>

Now create a file named “SpringAppEngine-servlet.xml” and paste below XML:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
< ?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
 
        <context:component -scan base-package="com.projectsierra.springappengine" />
 
        <bean id="viewResolver"
                class="org.springframework.web.servlet.view.InternalResourceViewResolver"
                p:prefix="/WEB-INF/views/" p:suffix=".jsp" />
 
</beans>

Line 8 tells Spring where to look for your controllers. Line 10 specifies that you will use JSPs as View technology.

Now, the last two things you need to do, is to create an actual controller and a JSP view. First, delete the auto-generated SpringAppEngineServlet class and instead create a HelloWorldController:

package com.projectsierra.springappengine;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
@Controller
public final class HelloWorldController {
 
	@RequestMapping(value = "/springappengine",  method = RequestMethod.GET)
	public String HelloWorld() {
		return "MyView";
	}
}

Next create a folder “views” within the WEB-INF folder. Add a file named MyView.jsp. The sole content of MyView.jsp is the string “Hello World”.

That’s it. Start up the development server and hit http://localhost:8888/springappengine:

By clicking the deployment button a second time you can deploy this version of the application to App Engine. If you want to preserve the first version, change the version number in the App Engine Project Settings before you deploy. A live version of above code runs at http://2.springapptest987654321.appspot.com/springappengine.

Resources

DeliciousTwitterFacebookLinkedInRedditSlashdotTechnorati FavoritesDiggShare
Posted in AppEngine | Leave a comment

Google Dev Day 2010 in Prague

Wow, Google Dev Day 2010 in Prague is over and there was lots of interesting information presented in the sessions. Below some notes I took during some of the sessions.

Native Client

  • Currently supported languages: C, C++. There are plans to extend the platform for other languages like C# and also to integrate with IDEs like Visual Studio and Eclipse.
  • Currently works reliably only in Google Chrome; can be used for extension development.
  • Possible use cases: client side encryption, image processing, games
  • Native Client is sandboxed in two layers: Native Client Sandbox, Google Chrome Sandbox.
  • Additionally certain IO and system calls are blocked.
  • Code must be verifiable, which has a size and performance impact.
  • http://code.google.com/p/nativeclient/

In my opinion Native Client probably won’t become popular in main stream applications, but I see a lot potential for Chrome Extensions.

What’s new in Google App Engine

  • AE for Business has been released recently. Main highlights are a Service Level Agreement and SQL support.
  • New features and API’s
    • Channel API: bidirectional client server communication.
    • Mapper API: Support for full MapReduce. Ideal for dealing with large datasets and distributable problems. App Engine Map Reduce.
    • Multi-Tenancy: Very easily usable by implementing a servlet filter and setting a namespace.
    • Matcher API: Document matching infrastructure.
    • High Performance Image Processing

All in all App Engine made a much more mature impression than last year. Together with SpringRoo, GWT and the Spring Source Tool Suite it’s a great environment for rapid application development …. if you are into Java …

Storage, Big Query, Prediction API

  • While App Engine is a Platform As A Service (PAAS) offering, Storage, BigQuery and Prediction API are the first products of Google’s Infrastructure As A Service (IAAS) offering.
  • Storage: essentially like Amazon S3. Compatible with S3′s REST API.
  • BigQuery and Prediction API builds on top of Storage
  • Data is stored in US data centers, but distributed through Google’s global network. Thus latency is very low.
  • Currently no Amazon-like areas are supported.
  • Comes with a command line util: gsutil. gsutil can be used together with S3, too.
  • Prediction API is an API to Google’s machine learning algorithms. Essentially you can upload a dataset to Google Storage, train the algorithm and then ask for a prediction based on a new input. The algorithms themselves are a blackbox; you don’t have any influence and no way to configure / fine tune them.
  • BigQuery: lets you query large datasets with a subset of SQL very quickly. Great for reporting.

Android News

New in Android 2.2

  • Licensing Verfication Library and Service
  • Application Error Reports (integrated into the market place, including the possibility for customers to provide feedback)
  • Just in time compiler: makes native apps 2x – 5x faster
  • Uses now V8 Javascript engine: makes web applications 2x – 3x faster
  • Device admin API: Enforcing enterprise Security Policies (e.g. max password length, etc)
  • Cloud to device messaging: Great for server push. Saves battery on the client side and provides a much better user experience.
  • App Data Backup API: Additionally to restoring the users apps on a new device, this gives the developer the opportunity to restore the users application data, too
  • Speech API
  • Easier configuration of “Install on SD”: simply configure this in your manifest file.
DeliciousTwitterFacebookLinkedInRedditSlashdotTechnorati FavoritesDiggShare
Posted in Android, AppEngine, Cloud Computing, Conference, GWT | Leave a comment

JRuby and Rails on AppEngine

JRuby and Ioke on Google App Engine for Java

key topics:

  • Why it actually might be interesting to let your Ruby app run with Jruby instead of MRI: threading, Unicode, performance, memory (much better garbage collection), c extensions > Java extensions, use Java code directly from Ruby
  • Warbler: packages your Rails / Ruby application into a WAR ready to deploy
  • How get Ruby work on AppEngine
  • Testing: local testing problematic, functional tests need to run on AppEngine directly

All in all I got the feeling that you shouldn’t run your production Rails application on AppEngine yet. There are to many caveats currently. It might be worth considering to move specific services of your application to AppEngine though. Especially those which could benefit most from the scaling advantages in the cloud.

The main points for getting your Rails app running on AppEngine you can read here and here.

DeliciousTwitterFacebookLinkedInRedditSlashdotTechnorati FavoritesDiggShare
Posted in AppEngine, Ruby | Leave a comment

Thoughtworks on App Engine For Java

Noch ein Session Video von der Google I/O: ThoughtWorks on App Engine for Java: An Enterprise Cumulonimbus? Präsentiert von Martin Fowler und Rebecca Parsons.

Nicht ganz so interessant wie andere und aus diesem Grund ist eventuell nicht wirklich wert eine ganze Stunde dafür zu opfern. Hier einige Notizen:

Testing

  • Local Server clones GAE not yet a 100%. Testing just on GAE is slow. Testing is possible but might be a little arkward until the local server really clones GAE.

Persistence

  • GAE uses a Nested Hash Map as a Data Storage. That is perfectly fine but might cause troubles or at least require a new thinking for developers who are used to relational databases.

Concurrency

  • Classical Java uses one single memory stack and runs multiple threads in this memory. GAE however only runs one thread per memory. Trying to create a new thread causes an exception. This particularly causes problems for many of the existing Java libraries. Key point: You might not be able to use all Java libraries you’d like to until they’re ported.

How to classify GAE?
This is how they classify GAE:

Quelle: http://code.google.com/intl/de-DE/events/io/sessions/ThoughtWorksAppEngineJava.html
Quelle: http://code.google.com/intl/de-DE/events/io/sessions/ThoughtWorksAppEngineJava.html

As example for infrastructure clouds they mentioned Amazons EC2. GAE belongs to the Platform category and Salesforce is a common example for Application clouds.

Es gab einige Anmerkungen mehr. Interessierte sollten das Session Video oder die Präsentationsfolien anschauen.

DeliciousTwitterFacebookLinkedInRedditSlashdotTechnorati FavoritesDiggShare
Posted in AppEngine | Leave a comment