November 27, 2013 1 minutes and 3 seconds read

Bookreview : Instant Vert.x

For those who have not yet got into contact with Vert.x, the book Instant Vert.x (54 pages in total of which 40 pages are “real” content) is a nice introduction to the underlying concepts.

As the name suggests, you can read the book in “an instant” and takes the reader through all high level concepts. The information in the book mostly stays at the concept level and provides some basic usage examples.

For those who have not yet had the opportunity to learn about Vert.x, I would not immediately recommend this book. The online documentation section on Vertx.io contains the same information. But if you like a book with information nicely put into digestible chapters then this book is a good fit.

Personally i hoped to get some more technical information and how-to information from this book but it is really targeted towards people that are just starting or have a beginning interest in Vert.x.

Overall, I really liked the compactness and pace of the book. It is an easy read and you quickly gain knowledge on the high level concepts of Vert.x. While noted earlier you can get the information also on Vertx.io website or other places, it’s is nice to have all information aggregated in one place. This book is a good start in your journey to learn about Vert.x.


May 28, 2013 0 minutes and 13 seconds read

Automount NTFS volume under Linux (Mint)

When automounting an NTFS volume under Linux (Mint) you can do this using the /etc/fstab file. dummy dummy dummy

$ sudo pico /etc/fstab

Add a line in the /etc/fstab file:

# custom mount point
/dev/sdb1 /media/windows-c ntfs-3g defaults 0 0

And take the mount into effect.

$ mount -a

May 24, 2013 0 minutes and 11 seconds read

Google Chrome not synchronizing extensions

When installing a fresh version of Chrome it may occur that all Bookmarks sync ok but the extensions not. The following solution worked for my system.

  • Open Google Chrome
  • Goto “Settings”
  • Open “Advanced Settings”
  • Check “Developer mode”
  • Press “Update extensions now”

May 16, 2013 0 minutes and 10 seconds read

Simple Helloworld verticle

Sourcecode:

package helloworld;

import org.vertx.java.core.Handler;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.deploy.Verticle;

public class Server extends Verticle {

    public void start() {
        vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {
            public void handle(HttpServerRequest req) {
            req.response.headers().put("Content-Type", "text/html; charset-UTF-8");
            req.response.end("<html><body><h1>Hello from vert.x!</h1></body></html>");
            }
        }).listen(8080);
    }

}

February 28, 2013 0 minutes and 37 seconds read

Grails migrations and 'Waiting for changelog lock'

Sometimes it may happen that the automatic migrations in a Grails project may come to a hold due to the fact that Liquibase keeps waiting for a changelog lock. At the end this will result in a application that is not going to be deployed.

...
Waiting for changelog lock....
Waiting for changelog lock....
Waiting for changelog lock....
...

To solve this take the following steps:

  • Stop the application container (example: Tomcat)
  • In the database look for a table called DATABASECHANGELOGLOCK
  • In the table there is a record with id=1, change the following values:
locked -> 0
lockgranted -> null
lockedby -> null
  • After updating this record start the application container

Notes:
To see who has locked the database (normally the local machine):

select * from DATABASECHANGELOGLOCK;
To update the record
update DATABASECHANGELOGLOCK
set locked=0, lockgranted=null, lockedby=null
where id=1

January 13, 2013 0 minutes and 38 seconds read

Testing constraints with Build Test Data

The Spock & Build Test Data plugins both are wonderful additions to your toolkit if you are creating tests without getting into the hassle of constantly building up your object graph. You can focus on what you want to test!

When testing constraints on an object it can be used as follows:

class Foo {
    String name   // name of foo
    Integer age   // age of foo

    static constraints = {
        name nullable: false, blank: false // name may never be nullable or blank
        age nullable: true
    }
}

And the Spock test

@Build(Foo)
@TestFor(Foo)
class FooSpec extends Specification {

    def "Name of Foo must exist"() {
        given: "setting up the constraints"
        mockForConstraintsTests(Foo)

        when: "creating a Foo"
        Foo foo = Foo.buildWithoutSave()

        then: "validation should trigger"
        assertFalse foo.validate()

        and: "validation error should be on the value field"
        assert foo.errors.allErrors.first().field == "name"
    }

}

September 18, 2012 0 minutes and 39 seconds read

Troubles getting vsftpd user logged in?

Recently i had the pleasure of installing and using vsftp on a Ubuntu Linux 12.04 system. I closely followed the instructions but keeped getting my head banging against a wall with an error message: 500 OOPS: vsftpd: refusing to run with writable root inside chroot()

After some googling around i found the following fix.. chmod the folder that the ftp user comes in to as he first login (root folder) by using in terminal:

sudo chmod a-w /home/user

Create a subfolder within the folder, either by the use of GUI or if you only have terminal it’s:

sudo mkdir /home/user/newfolder

Now you should be able to log in and read write within the “newfolder”.

You will NOT be able to write in the root folder itself from the ftp with the chmod a-w, so that is the reason for the subfolder, there you can.

http://askubuntu.com/questions/128180/vsftpd-stopped-working-after-update


September 17, 2012 2 minutes and 4 seconds read

Loading Grails configuration files update!

We recently changed the way how we load configuration files in a Grails project. Normally we to use the .properties file format, but this has some serious disadvantages.

  • You cannot deal with all Grails Mail settings in the configuration file
  • You cannot use the log4j DSL to extract the logging configuration outside your application
  • etc..

In our hunt for a good way to load configuration files we asked question on the mailinglist and also found this blogpost which was the start for our implementation of loading the external configuration files.

We modified some small things and added a way of loading a configuration file that is resident in the root of a Grails project. So when developing with IntelliJ for example the config file is at your fingertips in the root of the application project structure. We must also note that we are very happy with the fact that the Grails community was more then helpfull in helping us out here!

// -------------------------------------------------------------------------------- //
// - START: CONFIGURATION FILE LOADING -------------------------------------------- //
// -------------------------------------------------------------------------------- //
// locations to search for config files that get merged into the main config
// config files can either be Java properties files or ConfigSlurper scripts
def ENV_NAME = "${appName}.config.location"
if(!grails.config.locations || !(grails.config.locations instanceof List)) {
    grails.config.locations = []
}
println "--------------------------------------------------------------------------------"
println "- Loading configuration file                                                   -"
println "--------------------------------------------------------------------------------"
// 1: check for environment variable that has been set! This variable must point to the
// configuration file that must be used. Can be a .groovy or .properties file!
if(System.getenv(ENV_NAME) && new File(System.getenv(ENV_NAME)).exists()) {
    println("Including System Environment configuration file: " + System.getenv(ENV_NAME))
    grails.config.locations << "file:" + System.getenv(ENV_NAME)

// 2: check for commandline properties!
// Use it like (examples):
//      grails -D[name of app].config.location=/tmp/[name of config file].groovy run-app
// or
//      grails -D[name of app].config.location=/tmp/[name of config file].properties run-app
//
} else if(System.getProperty(ENV_NAME) && new File(System.getProperty(ENV_NAME)).exists()) {
    println "Including configuration file specified on command line: " + System.getProperty(ENV_NAME)
    grails.config.locations << "file:" + System.getProperty(ENV_NAME)

// 3: check on local project config file in the project root directory
} else if (new File("./${appName}-config.groovy").exists()) {
    println "*** User defined config: file:./${appName}-config.groovy ***"
    grails.config.locations = ["file:./${appName}-config.groovy"]
} else if (new File("./${appName}-config.properties").exists()) {
    println "*** User defined config: file:./${appName}-config.properties ***"
    grails.config.locations = ["file:./${appName}-config.groovy"]

// 4: check on local project config file in ${userHome}/.grails/...
} else if (new File("${userHome}/.grails/${appName}-config.groovy").exists()) {
    println "*** User defined config: file:${userHome}/.grails/${appName}-config.groovy ***"
    grails.config.locations = ["file:${userHome}/.grails/${appName}-config.groovy"]
} else if (new File("${userHome}/.grails/${appName}-config.properties").exists()) {
    println "*** User defined config: file:${userHome}/.grails/${appName}-config.properties ***"
    grails.config.locations = ["file:${userHome}/.grails/${appName}-config.properties"]

// 5: we have problem!!
} else {
    println "********************************************************************************"
    println "* No external configuration file defined                                       *"
    println "********************************************************************************"
}
println "(*) grails.config.locations = ${grails.config.locations}"
println "--------------------------------------------------------------------------------"
// -------------------------------------------------------------------------------- //
// - END: CONFIGURATION FILE LOADING ---------------------------------------------- //
// -------------------------------------------------------------------------------- //

September 16, 2012 0 minutes and 51 seconds read

Loading external Configuration files in a Grails application

The use of ‘Config.groovy’ as a placeholder for configuration settings is nice, but not always sufficient. The ‘Config.groovy’ file will get compiled and packaged inside the WAR file you are creating. If you want to externalize the configuration and have a need to configure settings outside the deployed (WAR file) application you can use property files (.properties) to achieve that.

A simple mechanism to load these property files is to place a short snippet of code in the ‘Config.groovy’ that will load a specific configuration file from the filesystem, depending on the availability.

grails.config.locations = ["classpath:application-config.properties", "file:./application-config.properties"]

This snippet will first try to load the property file from the classpath and if that fails you have a backup on the filesystem. This opens opportunities to load a different property file during development! When you deploy the application you can place the ‘application-config.properties’ file inside a folder which is available in the classpath. For Apache Tomcat this would be the ’lib’ folder!

This gives the opportunity to configure the application outside the ‘Config.groovy’ file so any changes made the the property file will be reflected in your environment.