Earlier last week, I installed Nginx with a Tomcat on a newly installed Ubuntu VPS. Unfortunately, although it comes with a lower memory footprint, it was noticably slower than my earlier Apache installation. It seemed like the simple proxying that I had in place was too slow. I decided to give the “APR based Apache Tomcat Native library” a try. Here’s what I did.
All posts in Software Engineering
No signature of method addTo* is applicable
Last night, I started getting an exception in one of my pet projects, created with Grails:
No signature of method: package.Parent.addToChildren() is applicable for argument types: (package.Child) values: [package.Child : null]
Possible solutions: getChildren(). Stacktrace follows:
groovy.lang.MissingMethodException: No signature of method: package.Parent.addToChildren() is applicable for argument types: (package.Child) values: [package.Child : null]
I searched for the problem, read dozens of different hints regarding proper general ORM one-to-many setups, GORM-specific hasMany/belongsTo relationships, cascading, saving before adding, etc. All were different problems leading to the same exception.
My problem, however, was far more trivial. Here’s the code that made me want to tear my hair out.
class Parent {
static hasMany = {
children: Child
}
}
Do you spot the mistake?
I used curly braces for the hasMany relationship. Groovy doesn’t complain at all, as it’s valid syntax. But to make GORM work the expected way, it should be square brackets:
class Parent {
static hasMany = [
children: Child
]
}
I’ve lost two hours of my life to this one.
Enabling Tomcat NIO Connector with Grails 2.0
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
If you’re using Grails for a frontend without direct database access, there are four things you need to do.
- Remove Grails’ Hibernate plugin.
grails uninstall-plugin hibernate
- Delete the datasource configuration file
conf/DataSource.groovy - Explicitly declare services as non-transactional. The default is
trueand 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 // ... } - Use command objects instead of domain objects, particularly if you need validation.
Deprecation of ConfigurationHolder in Grails 2
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
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.
Learning Grails the hard way: Facebook Authentication
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.
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.
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.
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.
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.
Android Game Development (Day 5)
Day #5, Sunday, June 27th.
Here’s the rough concept for timed events I already mentioned in my last posting. It’s working for now, but I’ll do some more tweaks to abstract this even further and make it more flexible.
Android Game Development – Steps 4-5 from Matthias Gall on Vimeo.
Keep reading below if you’re interested in today’s progress. Comments are welcome! In case you missed it, also don’t forget to read the reports on my steps in Android game development: Steps 1-3 and Step 4.
Android Game Development (Day 4)
Day #4, Saturday, June 26th.
Keep reading below if you’re interested in today’s progress. Comments are welcome! In case you missed it, also don’t forget to read the report on my first three steps in Android game development.
Android Game Development
I’m building rather boring enterprise applications at work and I love creating more appealing things in my spare time, so I do a bit of game development whenever I can. The main problem for a programmer is to get some graphics, but fortunately I have some nice renderings from my old Project E tutorial and the even older Project D game by sechsta sinn on my harddisk that I could put into use (all done by my friend and favorite artist Martin Ernst, btw.).
This is what I managed to do in three after work sessions so far, if you’re interested in the details, continue reading after the video.
Android Game Development – Steps 1-3 from Matthias Gall on Vimeo.
Unidirectional 1:1 relationships with Hibernate annotations
This is mainly a note to self because I screw up every time I need to write something like that, so here’s an example for myself in the future.
@Entity
@Table( name = "master" )
public class Master {
@Id
@GeneratedValue( generator = DBConstants.MASTER_SEQ )
@SequenceGenerator( name = DBConstants.MASTER_SEQ, sequenceName = DBConstants.MASTER_SEQ )
private long id;
@OneToOne( fetch = FetchType.LAZY, optional = false, targetEntity = Detail.class, cascade = CascadeType.ALL )
@PrimaryKeyJoinColumn
private Detail detail;
// ...
}
@Entity
@Table( name = "master_detail" )
public class Detail {
@Id
@GeneratedValue( generator = DBConstants.DETAIL_SEQ )
@SequenceGenerator( name = DBConstants.DETAIL_SEQ, sequenceName = DBConstants.DETAIL_SEQ )
private long id;
// ...
}
Reference: java.sun.com, Tadtech
GWT 1.7.x + Safari 4.0.5 = Crash
Last year’s success story continues. If you consider to do GWT 1.7.x development on a 10.5.8 Leopard, you better spare the 4.0.5 update too and stick to Safari 4.0.3; it keeps crashing even though the bug was reported to be fixed in 4.0.5.
I am displeased.







Recent Comments