Posts mit dem Label AppEngine werden angezeigt. Alle Posts anzeigen
Posts mit dem Label AppEngine werden angezeigt. Alle Posts anzeigen

Sonntag, 30. Mai 2010

Geospatial JDO queries on the Google AppEngine (+ GWT)

From time to time one might feel the urgent need to execute geospatial queries on the Google AppEngine. Thinking in common SQL this is pretty easy, just a combined WHERE clause:

SELECT * FROM t_spatialdata
WHERE latitude >= south AND latitude <= north AND longitude >= west AND longitude <= east

Unfortunately something like this is not possible, when using AppEngine, as you can only filter by one argument (i.e. only by latitude). I think the reason for this is that AppEngine internally sorts the table and then 'cuts' away what doesn't match the filter.

So this problem can basically be solved, by using a algorithm called Geohash, which unfortunately didn't want to return proper results, at least not the implementations I found. (The 'official' implementation uses the BitSet-Class which is not present when using AppEngine/GWT)

The solution I went for is the "javageomodel"-project which follows (afaik) a similar algorithm but worked. http://code.google.com/p/javageomodel/

The problem you will face, when trying to use this in your AppEngine project is that it will be missing (just at runtime!) two classes from the Apache Commons project: StringUtils and Validator. At least the latter one is over 1MByte in size. So I decided to replace the Validator lines with standard "assert"-calls, but adding the jars probably would have worked too.

For your convenience I uploaded the final jar that works fine:
http://rapidshare.com/files/393375528/libjavageomodel.jar.html
A how to use this for actual queries is located here:
http://code.google.com/p/javageomodel/source/browse/trunk/geocell/src/test/java/com/beoui/utils/HowToUseGeocell.java

Donnerstag, 20. Mai 2010

HttpServlet doGet / doPost throwing unexpected Exception

Ever wondered why your HttpServlet on Google AppEngine didn't work, even if the code looks sooooo right?
You might have (accidentally) called super.doPost(...,...); or super.doGet(...,...); which calls the default implementation of HttpServlet, which throws an Exception!
package org.crazy.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CrazyServlet extends HttpServlet {

 @Override
 protected void doGet(final HttpServletRequest pReq, final HttpServletResponse pResp) throws ServletException, IOException {
  this.doPost(pReq, pResp);
 }

 @Override
 protected void doPost(final HttpServletRequest pReq, final HttpServletResponse pResp) throws ServletException, IOException {
   super.doPost(pReq, pResp); // <-- DON'T !!! Just delete this line
  // Insert actual work here...
 }
}
Took me quite some to figure this out =D

Sonntag, 7. Februar 2010

AppEngine + Scala + JDO + GWT + Google Visualization API

Hi guys,

the last days I found myself playing with the Google AppEngine, a very easy to use and powerful cloud-hosting service powered by Google. I felt the need to code the server-side using Scala which resulted in some very neat and small code. (Special thanks to the superb XML-parsing and collection-framework in Scala)

Recently I enjoy playing a game called Heroes Of Newerth that is the successor of the famous Dota. This game as a public XML-API that I daily pull stats from - of user that 'registered' at my site:
So I parse the XML-data using Scala, make it persistent saving Java Data Objects (JDO) to the Datastore of the AppEngine. Users than can get the Data visualized using a combination of the Google Web Toolkit (GWT 2.0) and the Google Visualization API. I could create a pretty rich user-experience writing only about 1.000 Lines of Code Java/Scala code and a hand full of HTML and CSS.

Best Regards,
Nicolas