Dear reader of Juri's TechBlog,
I moved my blog to a new domain and a new hosting solution as well. I'm now blogging on juristr.com.

GWT, App Engine and App Engine Data Classes

I currently have some time before starting with my Master thesis project which will bring me back to Android programming. So to make use of that, I started to develop a project I already wanted to implement a couple of years ago, but due to my Master studies I didn't have the time to. I'll need some beta testers soon, so keep track of my blog here to catch the moment when everything goes online.
What I can reveal so far is that it will be a web application, using Google's GWT and it will be hosted on Google's cloud computing platform App Engine.

Today I was finishing the implementation of the basic CRUD operations, using JDO and App Engine's DataNucleus DataStore. Now the app possibly needs to store large strings surely more than 255 characters. You'd think that shouldn't be a problem, but App Engine's DataStore has some implications one should be aware of. Beside these, there are some well defined core value types, under which there is the restriction that you have to use the com.google.appengine.api.datastore.Text instead of the String datatype if you plan to store more than 255 character strings. Ok, that shouldn't be a problem for us, should it? Well...not exactly. If you plan to use App Engine together with plain old JSP or whatever view technology that it won't be a problem, but if you use GWT you have to keep in mind that you're implementing a client-server system. The difference: the GWT client lives within the browser. So the data has to be transferred between the two end-points and has to be serializable accordingly. com.google.appengine.api.datastore.Text isn't serializable though. This means you cannot share your POJOs between your GWT client app and server-side code. Now you have different possibilities. Some that come to my mind right now are..

  • using DTOs (Data Transfer Objects) which isn't that comfortable 'cause it causes a lot of boilerplate code
  • writing a serializable version of com.google.appengine.api.datastore.Text data class.
Fortunately a guy has already implemented such a serializable version of Text and provides it for free. I just tried it out and it works seamlessly, without writing a single additional line of code. Here some steps on how to use it (available descriptions on the web are really bad).
  1. Download the necessary jar files from http://www.resmarksystems.com/code/:
    appengine-utils-client-1.0.jar
    appengine-utils-server-1.0.jar

  2. Include the appengine-utils-client-1.0.jar in your build path. Copy the appengine-utils-server-1.0.jar to your WEB-INF/lib folder.

  3. On your GWT module file add the following:

    <inherits name="com.resmarksystems.AppEngineDataTypes"/>
    
    
  4. Restart your GWT app or compile it and everything should work as expected.
Resmarksystem's version doesn't just provide serializable versions of Text but also for Key, ShortBlob, Blob, Link, User.
If you get exceptions like
java.lang.ClassCastException: java.lang.String cannot be cast to com.google.appengine.api.datastore.Text
or
An IncompatibleRemoteServiceException was thrown while processing this call. 
then it's probably because you didn't correctly include the jar files as mentioned in step 2 above.

Posts you might also be interested in..

Credits: Hoctro | Jack Book

2 Comments:

David said...

Thanks!!!

Mitch said...

Thanks, but all I get is the following:

Loading modules
org.catadoptionteam.catserve.CATServe
Loading inherited module 'com.resmarksystems.AppEngineDataTypes'
[ERROR] Unable to find 'com/resmarksystems/AppEngineDataTypes.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
[ERROR] Line 16: Unexpected exception while processing element 'inherits'

I'm a newbie, so it's likely I don't understand the install directions. A Google searc says this means I need the source code, but I don't have it.

http://code.google.com/webtoolkit/doc/1.6/FAQ_Troubleshooting.html#Unable_to_find_type_%27com.foo.client._MyApp_%27

Post a Comment