Referencing a Bean in JasperReports

Thanks to this answer on StackOverflow, I know how easy it is to reference the bean itself instead of one of its properties in a text field expression in JasperReports. The trick is to declare a field whose description is set to the keyword _THIS:

Then it can be referenced in the text field expression as follows:

Installing a Tor Relay from Source on a Raspberry Pi

The other day I learned on Twitter that I should update the Tor relay software on my Raspberry Pi as the Tor project had introduced a new Bridge Authority. So I lazily ran sudo apt-get update  followed by sudo apt-get upgrade only to notice that no new version of the tor package was available via the package manager. Bummer.

Waiting for the package manager to provide a new version seemed futile so I decided to build Tor from scratch. I found a very helpful answer on StackOverflow that listed all the steps required  for my setup.

  1. Make sure to have all dependencies needed for compiling the sources:
  2. Clone Tor from
  3. Switch to the latest release branch:
  4. Run  ./
  5. Run  ./configure  or  ./configure --disable-asciidoc  if you don’t want to build the manpages.
  6. Run  make
  7. (Optional): run  make install

This last step installed the new tor binary in /usr/local/bin/ whereas the existing tor binary was still located in /usr/bin/ from where it was picked up by /etc/init.d/tor (I want to run my tor relay as a service whenever the Raspberry reboots). Luckily, this problem had been solved by someone else who shared his findings on a mailing list.

  1. If you’re using service tor {start, stop, reload, etc.}:
  2. The latter will likely point to /usr/bin/tor, which might be outdated.
    If that’s the case, change that line in /etc/init.d/tor to point to the new Tor executable /usr/local/bin/tor – that’s where it should be; if you don’t like that, change BINDIR = /usr/local/bin  in Tor’s Makefile and make install  again.
  3. The Debian Tor packages seem to like to assume torrc will be placed in /etc/tor/torrc . If that’s where your torrc resides, make a symlink to it from /usr/local/etc/tor , which is where the new Tor executable will look for it:
  4. Stop the running tor service:
  5. Reload the tor daemon:
  6. Restart the tor service:

Regex for German Zip Codes

I found the following regular expression (source) working fine for me:

I tried two alternatives that did not work because they were too general:

The first regex matches the zip code “00000” which is invalid in the German system. The second regex matches the zip code “99999” which is invalid, too.

Renewal of Let’s Encrypt Certificates Using Plesk

Note to self: If the Let’s Encrypt extension for Plesk fails to renew a certificate (when triggered manually), disable the automatic forwarding to an SSL connection in the Apache settings. This forced secure connection seems to disturb the renewal script.

The error I got was something like:

Let's Encrypt SSL certificate installation failed: Failed letsencrypt execution: 2016-01-19 13:56:07,885:WARNING:letsencrypt.cli:Root (sudo) is required to run most of letsencrypt functionality. Failed authorization procedure. (http-01): urn:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from [REMOVED IP]: 401 IMPORTANT NOTES: - The following errors were reported by the server: Domain: Type: urn:acme:error:unauthorized Detail: Invalid response from /.well-known/acme- challenge/REMOVED-ID [REMOVED IP]: 401

See also this bug report on Github.

Let’s hope the extension is going to renew all certificates automatically every month from now on, as it should.

Testing Delegate Methods

We had an interesting discussion the other day: should we write unit tests for delegate methods, that is, methods that only delegate the call to a delegate object? Here’s an example of such a method:

I said I did not see much value in a unit test for this method as all the test could do is verify whether the do()  method of the mocked delegate object was called. Instead of testing behaviour, we would test the wiring which is close to trivial in this case and should be tested implicitly as part of an integration test involving the delegate object and the main object.

Some of my colleagues disagreed with me. Their argument was that a unit test would detect changes in the delegate call and indicate the intended usage of the delegate object. They were concerned an incorrect wiring could be introduced without a unit test. And this unit test would be cheap to write.

I did not find any of these arguments very convincing – and I’m in good company: the JUnit team’s FAQ webpage has a section on Best Practices which comments on testing delegate methods. You can read it here. Thank you, J. B. Rainsberger!

Headless Testing with TestFX

Jérome Cambon wrote a nice introduction to TestFX and how to enable the headless mode using Monocle.

I tried to reproduce the steps he described for running my TestFX GUI tests in headless mode from Eclipse so I can keep using my mouse while they are running. The crux is setting the VM arguments in Eclipse. First, I tried to set

in the VM arguments section of the JRE tab in my Maven run configuration:

Maven run configuration in Eclipse

This did not work. I could still see the TextFX robot move the mouse cursor on my screen.

I had to specify the VM arguments using Maven’s ‘argLine’ parameter:

Maven argLine parameter

If anyone knows why setting the VM arguments in the run configuration did not work, please let know.

A Potential Pitfall with the TextFormatter Class in JavaFX

A common use case for the TextFormatter class in JavaFX is a text field that should convert any lower-case character input into an upper-case character. This can be achieved easily by defining a filter for the text formatter as described here. A straightforward implementation could look like this:

This implementation comes with one pitfall, though. When the (German) user types the character “ß” into the text field, it will be converted into “SS” because that’s how Germans roll. So the resulting string is one character longer than the input string. Why is this a problem? Well, the cursor position will be between the two “S” characters after the conversion:


When the user types in the next character, it will be inserted between the two “S” characters, not behind them. Bummer.

Luckily, the masterminds behind JavaFX give us the tools to correct this unfortunate behaviour since the change object that the filter works on allows for setting the anchor and caret position in the text field. We need to correct them by the difference between the string lengths before and after the conversion:

This puts the cursor at the end of the string no matter how many “ß” characters the user types in or pastes into the text field.

The TextFormatter Class in JavaFX: How to Restrict User Input in a Text Field

There are a lot of code examples for restricting or modifying user input into a JavaFX text field. Most examples I have seen suggest adding a change listener to the text field’s text property. Here’s how you would allow only lower-case characters in your text field using the change listener approach:

This approach comes with one drawback: you’ll have two events being triggered by two changes of the text property. The first change is caused by the direct user input, the second change is caused by the manipulation of the user input by the change listener. The user won’t notice these two events, but somewhere in your code you have another listener for the text property, that listener will receive two events, one with the “invalid” change and a second one with the “valid” change.

Another approach was suggested by Richard Bair a long time ago. His suggestion resulted in the TextFormatter  class being added to JavaFX with version 8u40. It’s a clean way to format, filter, or restrict user input. Here’s how it works:

What’s still missing is support for the backspace key to delete a character in the text field, but that’s just my silly example implementation. [Update 2016-12-28: The implementation was improved to support the deletion and selection of characters.]

This approach intercepts the user input before it’s written into the text property and thus fires only one event. Before that happens, you can examine and modify the Change  object in the UnaryOperator  defined in getFilter()  method.

In addition to filtering, a TextFormatter  object can convert a value to a string representation and vice versa. From the Javadoc:

A value converter and value  can be used to provide a special format that represents a value of type V. If the control is editable and the text is changed by the user, the value is then updated to correspond to the text.

Sounds pretty handy.

Owncloud with Apache 2.4, PHP FPM, and Plesk

After about two weeks of fiddling around, I finally managed to get my own instance of owncloud up and running with Apache behind Plesk. Here’s how I did it:

  1. Set up a sub-domain in Plesk, e.g.
  2. Set up a database for owncloud using Plesk.
  3. Make sure to use HTTP strict transport security by adding the following Apache HTTPS directive:
  4. Create a directory for your owncloud data, e.g. /var/oc_data
  5. Give sufficient permissions to your HTTP user on the data directory:

    In my case, user1 is the the name of the Plesk user with which I had created the sub-domain. psacln is the group assigned to this user by Plesk.
  6. Update PHP to version 5.6.x. There is this bug in version 5.5.x which makes owncloud unusable if you don’t want to use mod_php (which is discouraged).
  7. Configure PHP in Plesk and Apache as follows:
    • Run PHP as an FPM application
    • Set open_basedir to {WEBSPACEROOT}{/}{:}{TMP}{/}{:}/dev/urandom{:}/var/oc_data{/}
    • Set memory_limit to 256M (or something like that)
    • Set max_execution_time to 120 (or something like that)
    • Set max_input_time to 120 (or something like that)
    • Set post_max_size to 128M (or something like that)
    • Set upload_max_filesize to 64M (or something like that)
  8. Check this owncloud documentation page for potential additional PHP settings when running in FPM mode.
  9. Download the setup-owncloud.php web installer as described here and run it from your browser.
  10. Have fun.