25 May 2011

Eclipse Helios with Firefox 4 on Ubuntu Natty

I've just finished installing Kubuntu 11.04 on a spare partition, and I'm rather pleased with it, there were absolutely no problems with the usual suspects like X driver, sound or fake RAID.

The only regression I noted is that Eclipse 3.6.2 no longer supports an internal web browser. Ubuntu 11.04 comes with Firefox 4.x, and this is not currently supported by Eclipse SWT.

This thread gave me the hint how to fix it:
  • Install package libwebkitgtk-1.0-0 (do not use the newer version libwebkitgtk-3.0-0)
  • Add the following to eclipse.ini: -Dorg.eclipse.swt.browser.UseWebKitGTK=true
  • Create a symlink in /usr/lib to satisfy the SWT dependencies:
    ln -sf libwebkitgtk-1.0.so.0.6.0 libwebkit-1.0.so.2
Restart Eclipse and check Window | Preferences | General | Web Browser. The radio button Use internal web browser should now be enabled.

Update 2 Jul 2001: After upgrading to Eclipse Indigo 3.7.0, the internal browser works out of the box. I did not have to modify eclipse.ini. But it seems Eclipse now uses WebKit by default, so you still need to install the WebKit library and create the symlink if you haven't done so before.

03 April 2011

reFit Plugin for Jenkins

After working with Hudson (now Jenkins) as a user for almost three years, I've now created my first plugin for publishing Fit test reports for Jenkins projects.

The plugin works with reFit 1.7.0 or higher. It is published on the Jenkins Community infrastructure, separate from the reFit project on Google Code. You can install the plugin from the Jenkins update centre.

For more details, see the reFit Plugin page in the Jenkins Wiki.

20 March 2011

JAXB Marshalling with Custom Namespace Prefixes

The Problem


  • You have an XML schema with multiple XML namespaces.
  • You generate a JAXB model with xjc.
  • You build a JAXB document model and use the JAXB Marshaller to create XML from the model.
  • You want to override the default namespace prefixes ns1, ns2, ... created by the Marshaller.

13 March 2011

Transparent Asynchronous Remoting via JMS

The Scenario


A client needs to invoke a service interface with the following restrictions:
  • The service implementation is running on a remote machine.
  • This fact is transparent to the client, i.e. any service method invocation is just like a local method invocation.
  • The service methods are executed asychronously on the server, method invocations on the client return immediately (fire-and-forget).
  • All service methods have void return types.
  • The service invocations shall be transported via JMS.

20 February 2011

Hamburg Elections Powered by MySQL

Following a link on Google to the intermediate results of today's elections in Hamburg on the official website of Statistikamt Nord (Hamburg and Schleswig-Holstein Statistics Office), I found this:


Ok, the good news is that our taxes don't get wasted on expensive Oracle licenses...

Building a Web Application with Wicket, Spring and JPA

This is a tutorial on setting up a web application stack with Wicket, Spring and JPA, with a special focus on avoiding Spring XML configuration in favour of Java configuration, and on using the JSR-330 @Inject annotation both in the web and service layers.

Martijn Dashorst's blog on Wicket/Spring/Hibernate configurationwas the starting point for my setup, and as I hate "oodles of XML"  as much as he does, I replaced all the XML bean declarations by a @Configuration class, a new feature in Spring 3.0.x.

07 February 2011

Maven Snapshot Repositories with Nexus

When you have a Maven build which depends on more than one external repository, it is usually a good idea to work with a repository manager. A repository manager also enables you to share your artifacts with other team members.

Nexus Open Source is probably the most popular Maven repository manager. Once it's set up correctly, it requires little or no maintenance, at least that's my experience after using it in different projects over the last three years.

I've just finished setting up Nexus for my current project, but this time, I spent almost a day chasing a problem related to snapshot repositories.

I had set up the Public Repositories group of Nexus as a mirror for Maven central and configured the Nexus Snapshots repository as an additional snapshot-enabled repository for the snapshots from my own project:

22 January 2011

Transparent Asynchronous Remoting

The Scenario


A client needs to invoke a service interface with the following restrictions:
  • The service implementation is running on a remote machine.
  • This fact is transparent to the client, i.e. any service method invocation is just like a local method invocation.
  • The service methods are executed asychronously on the server, method invocations on the client return immediately (fire-and-forget).
  • All service methods have void return types.

The Solution with Java EE 6


With Java EE 6, the solution is quite simple, thanks to the @Asynchronous annotation introduced in EJB 3.1. You simply create a remote session bean and add this annotation to any business method or to the entire class. The container will then execute the given methods asynchronously.

Patrick Champion has a complete example in his blog, so there's no need for me to provide any sample code.

When your client is also a Java EE 6 application, you can simply @Inject the service interface and use a @Produces annotation on an @EJB reference somewhere else to direct the client to the appropriate implementation.

In addition, to avoid hardcoding the service URL in your client, you should define a local JNDI alias in your Java EE 6 container for the address of the remote service implementation, so you can move the remote implementation to another host without recompiling your client.

The Solution with Spring 3.0


Spring does not have an out-of-the box solution for this scenario. Spring Remoting provides transparent proxies for remote services, but these proxies are always synchronous. Since Spring 3.0, there annotation support for asynchronous execution, but this only applies to local beans.

However, it is not hard to combine these two features with some glue code to implement a solution for our scenario.

18 January 2011

reFit: Acceptance Testing for Java EE 6, Spring and OSGi

Even if you don't practice test-driven development, you are certainly familiar with the JUnit family of testing frameworks (including ports to other languages like cppunit, NUnit, or independent but similar approaches like TestNG).

This post is about the Fit framework family, which has a somewhat different focus and is not just another JUnit clone. In a nutshell, Fit represents expected and actual test results in tables, and you do not have to be a programmer to read or write them.

The following table has one column of inputs and two columns of outputs:

Each row of this table can be regarded as an acceptance test case. You can feed this table to a given system and compare the outputs:

It's only a couple of weeks ago I was introduced to Fit in my current project, and I must admit my first thought was "Why don't you just write a @Parameterized JUnit test?"

The answer is, JUnit is for developers, and developers only; Fit is for customers and developers.

You still need a developer to implement the skeleton logic of a test (called fixture in Fit), but anyone can write new test cases by adding rows or columns to a given Fit table.

The Fit method and the original Java implementation were created by Ward Cunningham in or around 2002, the project is hosted on Sourceforge and has been inactive since 2008.

The Fitnesse project integrates Fit with a Wiki, it includes a modified version of the original Fit implementation and is under active development. However, Fit and Fitnesse are incompatible, Fit lets you write your test tables in plain old HTML, whereas Fitnesse supports its own Wiki syntax only.

Our project has a fair amount of plain old HTML Fit tests, and our production code uses Spring, so it was a fairly natural idea to inject Spring beans from the system under test into our Fit test code.

Spring is just one (and not really my favourite) framework for dependency injection (and lots of others things). so I inevitably started thinking about how to use Fit together with Java EE or OSGi.

Thinking was followed by coding (yeah, it can be the other way round sometimes...), and this led to a project called reFit hosted on Google Code.

reFit is based on the latest Fit sources from SourceForge, it provides up-to-date Maven artifacts on Maven Central and integrations with Java EE 6, Spring and OSGi Declarative Services. The Java EE integration reuses parts of my jeeunit project.

In addition, reFit lets you run Fit tests under a JUnit wrapper or from a Maven plugin, both with or without Spring integration. reFit includes ready-to-run example code for Glassfish 3.1, Spring 3, Equinox and Weld SE.

There's more to come, I'm currently experimenting with a Web frontend and a WYSIWYG HTML editor.

For more details, check out the reFit Wiki.

04 January 2011

Eclipse Meta-Error