All posts by

Enabling Tomcat NIO Connector with Grails 2.0

grails-title

At dozens of different sources, even in Graeme Rocher’s corresponding Jira ticket, it says that you need to put grails.tomcat.nio=true into your Config.groovy file. I believed that, too, and it drove me nuts to see that the org.apache.coyote.http11.Http11NioProtocol class wasn’t even instantiated.

I had to review the commit logs to figure out that the property should actually be in the BuildConfig.groovy file.

Now I finally got the log messages that I expected to see…

| Loading Grails 2.0.0
| Configuring classpath.
| Environment set to development.....
| Packaging Grails application.....
| Running Grails application
| Enabling Tomcat NIO connector
http11.Http11NioProtocol Initializing ProtocolHandler ["http-nio-8080"]
| Server running. Browse to http://localhost:8080/...

MongoDB: can only have 1 index plugin / bad index key pattern

While working with MongoDB and the MongoDB Java driver I got the following exception when attempting to iterate over a result set.

com.mongodb.MongoException: can only have 1 index plugin / bad index key pattern
at com.mongodb.MongoException.parse(MongoException.java:82)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:312)
at com.mongodb.DBCursor._check(DBCursor.java:369)
at com.mongodb.DBCursor._hasNext(DBCursor.java:498)
at com.mongodb.DBCursor.hasNext(DBCursor.java:523)

This exception drove me nuts. I checked the index definition in Java, which looked fine, compared it to the index result in Mongo shell (db.collectionName.getIndexes()), which looked fine too, made several desperate attempts to drop and recreate the index, re-index the collection, etc.

Then I cut down the DB query and recognized that removing my sort() call made a difference. Eventually it turned out that the sort order was specified as a String instead of an Integer, see below:

BasicDBObject query = ...
// WRONG:
// BasicDBObject sort = new BasicDBObject("column1", "1").append("column2", "-1");
// RIGHT:
BasicDBObject sort = new BasicDBObject("column1", 1).append("column2", -1);
mongoDB.getCollection("collectionName").find(query).sort(sort);

Using Grails without a database

grails-title

If you’re using Grails for a frontend without direct database access, there are four things you need to do.

  1. Remove Grails’ Hibernate plugin.
    grails uninstall-plugin hibernate
  2. Delete the datasource configuration file conf/DataSource.groovy
  3. Explicitly declare services as non-transactional. The default is true and your class methods would be proxied, but without the Hibernate plugin there is no transaction manager and the deployment will fail.
    class SomeService {
    	static transactional = false
    	// ...
    }
  4. Use command objects instead of domain objects, particularly if you need validation.

9 out of 10 startups fail

Disclaimer: I’ve chosen a rather provocative title for this posting. It has no qualified basis but it’s something you hear very often in one way or another. 7 out of 10 fail, 9 out of 10 fail, etc.

I was interested in whether there’s any truth in this startup-scene meme, so I took some time to walk through 13 startups who presented 30 second pitches at Web 2.0 summit 2010, a little more than one year ago.

Here’s the outcome – all startups in the order of appearance with a number of open permanent positions at the time of this writing.

I’ve just put a reminder in my calendar to revisit this list in one year. Let’s see how it’s looking like then.

Deprecation of ConfigurationHolder in Grails 2

grails-title

While porting my Grails applications to 2.0 RC1, I recognized that ConfigurationHolder is now deprecated. The new way to access the configuration is through dependency injection of the grailsApplication bean.

Before 2.0:

import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH
...
def value = CH.config.my.configEntry

With 2.0:

class MyService/MyController {
	def grailsApplication
	def method {
		def value = grailsApplication.config.my.configEntry
	}
}

Grails cheat sheet

grails-title

This is a little cheat sheet I created for learning purposes. I’m extending this as I need. Many of the tips are collected from the Getting Started With Grails minibook, which is a great resource for a kickstart.

All stuff after the break… click “Continue” to continue reading.

Continue Reading →

Learning Grails the hard way: Facebook Authentication

grails-title

Every now and then I try to explore a new programming language. Last year, I tried Scala, this year, I’m fiddling around with Grails. My first attempt was to try something I already implemented in other languages, like verifying Facebook’s signed_request. It’s fun to see what I tried to get it running and how a short version by a more experienced Groovy coder looks like.

Compare both versions after the break if you like.

Continue Reading →

Android Application Development Tips: Disabling scrollbars for WebView

Scrollbars for a WebView can be easily disabled from XML using the scrollbars attribute.

<WebView
	android:layout_height="wrap_content"
	android:layout_width="wrap_content"
	android:scrollbars="none"
	/>

arcadiaCharts public alpha released

The wait has come to an end and it’s quite a relief to finally be able to write about (and promote) something I’ve been involved in my spare time, mainly in 2009 and partly in 2010 as well.

In December 2008 I had the pleasure to meet members of the management board of element5, one of the world’s largest outsourcing partners for the software industry, who were just kicking off a new little project: a charting library for JavaScript and Java. My colleague Oliver created the GWT Canvas project which was used for the rendering and I designed most of the project architecture and laid grounds for the available chart types. Unfortunately I had to reduce my involvement in late 2009 due to other personal projects and more responsibilities in my day job and made way for Joern and Andreas as the current main developers, but I’m still part of the development team and a little proud to see the first alpha come to light.

The first public release is an alpha version for testing purposes, so if you’re interested in a flexible, yet easy to use chart library for JavaScript/GWT, have a look at arcadiaCharts.com.

Android Application Development Tips: Pull screenshot with ADB

For some reason, pulling screenshots in the DDMS view in Eclipse doesn’t always work. In that case, the following calls became handy (tested with HTC Hero):

adb pull /dev/graphics/fb0 fb0
dd bs=1920 count=800 if=fb0 of=fb0b
ffmpeg -vframes 1 -vcodec rawvideo -f rawvideo -pix_fmt rgb565 -s 320x480 -i fb0 -f image2 -vcodec png image.png

More examples available at the source.

Android Application Development Tips: ADB server didn’t ACK

If you’re working on Windows and have HTC Sync installed, you may run into this error message. I hardly develop under Windows anymore, but since the Android plugin was a little buggy on OSX, I had to. This message drove me nuts and I did a little research: with netstat -o I could see which process ID was occupying the port and with Process Explorer I could see that HTC Sync itself was the culprit. I killed it but this didn’t help until I hindered it completely from auto-starting and restarted my machine afterwards.

GWT 2.1 compilation issues on OSX

Today I experienced a compilation problem with GWT 2.1 and the Maven GWT plugin:

[INFO] Compiling module com.mycompany.platform.crm.ui.gwt.Crm
[INFO] Validating newly compiled units
[INFO] [WARN] Warnings in ‘jar:file:/Users/myuser/.m2/repository/com/google/gwt/gwt-dev/2.1.0/gwt-dev-2.1.0.jar!/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Cast.java’
[INFO] [WARN] Line 29: Referencing field ‘java.lang.Object.castableTypeMap’: unable to resolve field, expect subsequent failures
[INFO] [WARN] Line 29: Referencing field ‘java.lang.Object.castableTypeMap’: unable to resolve field, expect subsequent failures
[INFO] [WARN] Line 38: Referencing field ‘java.lang.Object.castableTypeMap’: unable to resolve field, expect subsequent failures
[INFO] [WARN] Line 38: Referencing field ‘java.lang.Object.castableTypeMap’: unable to resolve field, expect subsequent failures
[INFO] [WARN] Warnings in ‘jar:file:/Users/myuser/.m2/repository/com/google/gwt/gwt-dev/2.1.0/gwt-dev-2.1.0.jar!/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Util.java’
[INFO] [WARN] Line 27: Referencing field ‘java.lang.Object.castableTypeMap’: unable to resolve field, expect subsequent failures
[INFO] [WARN] Line 35: Referencing field ‘java.lang.Object.castableTypeMap’: unable to resolve field, expect subsequent failures
[INFO] [WARN] Warnings in ‘jar:file:/Users/myuser/.m2/repository/com/google/gwt/gwt-user/2.1.0/gwt-user-2.1.0.jar!/com/google/gwt/emul/java/util/Arrays.java’
[INFO] [WARN] Line 1348: Referencing method ‘com.google.gwt.lang.LongLib.compare([D[D)': unable to resolve method, expect subsequent failures
[INFO] [WARN] Line 1358: Referencing method ‘com.google.gwt.lang.LongLib.compare([D[D)': unable to resolve method, expect subsequent failures
[INFO] [ERROR] An internal compiler exception occurred
[INFO] com.google.gwt.dev.jjs.InternalCompilerException: Unable to locate index method: GWT.isProdMode
[INFO] at com.google.gwt.dev.jjs.ast.JProgram.getIndexedMethod(JProgram.java:824)
[INFO] at com.google.gwt.dev.jjs.impl.GenerateJavaAST$JavaASTGenerationVisitor.processType(GenerateJavaAST.java:550)
[INFO] at com.google.gwt.dev.jjs.impl.GenerateJavaAST.exec(GenerateJavaAST.java:3147)
[INFO] at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.precompile(JavaToJavaScriptCompiler.java:519)
[INFO] at com.google.gwt.dev.jjs.JavaScriptCompiler.precompile(JavaScriptCompiler.java:32)
[INFO] at com.google.gwt.dev.Precompile.precompile(Precompile.java:545)
[INFO] at com.google.gwt.dev.Precompile.precompile(Precompile.java:466)
[INFO] at com.google.gwt.dev.Compiler.run(Compiler.java:205)
[INFO] at com.google.gwt.dev.Compiler.run(Compiler.java:177)
[INFO] at com.google.gwt.dev.Compiler$1.run(Compiler.java:149)
[INFO] at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:87)
[INFO] at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:81)
[INFO] at com.google.gwt.dev.Compiler.main(Compiler.java:156)
[INFO] [ERROR] at GWT.java(26): final class GWT extends Object
[INFO] com.google.gwt.dev.jjs.ast.JClassType

I couldn’t really identify the origin of the problem, but scrapping the whole gwt Maven repository subdirectory and redownloading the 2.1.0 dependencies resolved the issue for me.

AirPort Connection Timeout with MacBook Pro

As it seems, there are dozens of other users who experienced a connection timeout using AirPort W-LAN connections on Macs. There are dozens of different solutions described in the forums, I tried plenty of them. From reboot to deleting the WPA2 key from the keyring, nothing worked.

Eventually I tried the following and this worked for me. (Note that I’m using a German installation, the real English translation may be slightly different.)

  1. Go to Mac (the Apple symbol in the top left) -> Location -> Network Settings
  2. Click on the “Airport” entry on the left
  3. Click on the “additional options” button
  4. On the Airport tab, click the “+” button below the “preferred networks” list
  5. Click on the “show networks” button and select your W-LAN from the list
  6. Enter your password

That way, I could connect without problems. It may be coincidence that exactly this way worked, and none else, but maybe there’s really some strange difference.

Let me know if this helps.

10 years sechsta sinn

Silently, we passed our 10th anniversary some days ago. As a little gift, here’s an older video right from the DVW game engine.

Music Tip: Parov Stelar

I got a bit lazy with my code music list to the right. However, I’m currently addicted to the great music of Parov Stelar (bought three albums at once on iTunes recently, sad I didn’t find him earlier), so I thought I could share some videos.

A live example:

(I’d love to have this unfortunately unreleased recording.)

And a studio mix:

Plenty of other tracks are available on YouTube.

We are our choices

When you are 80 years old
and in a quiet moment of reflection
narrating for only yourself
the most personal version of your life story
the telling that will be most compact and meaningful
will be the series of choices you have made.
In the end we are our choices.
Build yourself a great story!

Jeff Bezos, founder of amazon.com, at a Princeton Graduation Speech. Via TED.

Facebook/Flattr/… Clickjacking Examples And How To Avoid It

Facebook’s “Like!” button, the Flattr button and plenty of other widgets work pretty much the same. You either create some IFRAME directly (Facebook non-XFBML method) or include some JavaScript which then injects the IFRAME into your DOM once it’s ready (Facebook XFBML, Flattr). The widgets provide you with some cool social one-click-functionality. That’s nice and easy… unless someone’s planning to mess around with it.

Continue Reading →

Nice Concept: Blog A Day

I stumbled across an interesting concept. 14 independent developers get one slot per week on iDevBlogADay.com to publish articles; if they don’t blog, the spot is given to the next developer on the waiting list.

Android Game Development (Day 6)

It took some time until I finally could get back to my little Android game and I must admit that this wasn’t really a “day” I worked on it. Instead, it were multiple, scattered and short sessions where I worked on the collision testing and response code, some effects and UI stuff. It’s simply too hot currently… so bear with me that there’s no cool video this time.

ProjectA - Now with collision testing and explosions

ProjectA - Now with collision testing and explosions

Keep reading below if you’re interested in the recent progress. Comments are welcome! In case you missed it, also don’t forget to read the earlier reports on my steps in Android game development: Steps 1-3, Step 4, Step 5.

Continue Reading →

Sleep…

…is overestimated.