Total Pageviews

Thursday, November 12, 2009

Fixing hibernation problem under Ubuntu 9.10

Recently I upgraded my Ubuntu Linux 9.04 to the latest Ubuntu 9.10 on my Acer Aspire 5652 laptop. So far so good. The upgrade went smooth and without any problems and after 40 minutes I was able to take a look at the latest Ubuntu release.

Soon I found out that neither suspend nor hibernate were working. After resuming I got a blank black screen and I was not able to fix this problem with infos from the ubuntu forums.
I decided to install a fresh Ubuntu 9.10 on my laptop because I wanted to benefit from ext4, a better startup time and the newest grub.
After installation succeeded I really was impressed by the startup time. Even after I installed all the programs I used on Ubuntu 9.04 the startup time was nearly twice as fast. But one problem was still there: Neither suspend nor hibernate did work.

One of the answers in the forum was to wait for a patch but this is no option for me because I need at least hibernation on my laptop.

So I found this link to be very useful:

It shows how to use the "Userspace Software Suspend" program to fix hibernate or suspend problems.

As root I edited the file

and changed the line

and all of a sudden hibernation is working again. I still cannot use suspend but for now I can live with it.

UPDATE: 2009-11-29
With the latest Ubuntu updates my hibernation and suspend problems are gone, so I switched back to kernel suspend mode.

Thursday, July 02, 2009

Howto change password expiration in Apache Continuum

Apache Continuum is bothering me with regularly messages that my password has expired and I need to change it. Well, there is a way to turn password expiration completely off.
Just create the file


with the following content:


No annoying password changes anymore. But keep in mind that this may be a security risk!
Another option is to extend the number of days a password needs to expire.
For a complete reference of available properties check the site:

Have fun!

Saturday, June 27, 2009

Testing your EJB3 beans in an embedded EJB container using OpenEJB with Maven as build system


I am currently working on a private project implementing a web application using GWT as frontend and EJB3 as backend technology.
Testing my EJB3 beans using JUnit4 turned out to be very complicated. I had to manually inject all the required resources like EntityManager, EntityManagerFactory and all EJB3 beans the bean under test uses.
This may work for a simple project with a few beans but this will definitely not work for a huge project.
So I was looking for a better and less complicated way to test my beans.
Embedded Glassfish came to my mind, but this project isn't final yet, so I stumbled across a blog entry of Adam Bien's blog where he talks about OpenEJB and I thought just give it a try.
I use Maven as build system for all my projects so everything below this line just fits for Maven. If you use Ant or something different you may have to do other things to set up your testing environment.

Maven configuration

Using the OpenEJB embedded container is very easy. Just add the following dependency to your POM:


In my case it turns out that the dependency activeio-core version 3.0.0-incubator is not hosted in any publicly available maven repository (well at least not in those I use). So I grabbed it from here and pushed it into my running Nexus instance.
In case you use OpenJPA as your persistence provider you have to configure the Maven surefire plugin to use the OpenEJB Java Agent. This is described in detail on this OpenEJB site.

Necessary files

My project consists of three maven modules:
  1. project-entities (contains all JPA entities and the production persistence.xml under src/main/resources/META-INF)
  2. project-api (contains all session beans and services)
  3. project-webapp (the GWT web application)
In this article I concentrate on testing my session beans and services. So I will focus on the project-api module. It is absolutely important to create the file ejb-jar.xml under src/test/resources/META-INF in the project-api module.
Because I only work with annotations this file is nearly empty in my case. It just contains the following line:


In case you have configured a persistence.xml file under src/test/resource/META-INF of your module under test (in my case project-api) using RESOURCE_LOCAL I recommend to delete this file completely. In my case this file was interfering with the OpenEJB setup and all my beans were not deployed into the embedded container. Hence, my embedded tests were not working.

Configuring the OpenEJB embedded container for testing

Now it's time to configure the OpenEJB embedded container. This can be done in two ways. I will only explain the configuration in a JUnit base test class, so this can be used by all unit tests deriving from this class. There is another way in configuring the container using an XML file. Please consult the OpenEJB website for further details.
Like I said before, I am using Hibernate as persistence provider. The setup of the embedded container is done in a method annotated with the JUnit annotation @Before, so it get's called before a test is executed. You may wish to change this in a way it better fits into your environment (using @BeforeClass, etc ...)

  public void initializeEmbeddedContainer() throws Exception {
    Properties properties = new Properties();

    context = new InitialContext(properties);

In the above code snippet the bold lines are important. They are responsible for starting the embedded container. There are a few more properties you have to set to get the embedded tests running. Now you have to override the settings you made in your persistence.xml for running in OpenEJB.
The following lines will do that for you:

   properties.put("puName", "new://Resource?type=DataSource");
    properties.put("puName.JdbcDriver", "org.hsqldb.jdbcDriver");
        .put("puName.JdbcUrl", "jdbc:hsqldb:mem:testdatabase");
    properties.put("", "update");

    properties.put("puName.hibernate.show_sql", "true");
    properties.put("puName.hibernate.format_sql", "true");

puName stands for persistence unitname. Please replace this with the real name of your persistence unit. The lines in bold are necessary. I am using HSQL DB, but this should work with any JDBC database. Don't forget to let Hibernate create the DB schema for you, otherwise your tests will fail because of non existent tables.
There is just another configuration property you may want to use: Restarting the OpenEJB embedded container between tests to avoid strange side effects in your tests. This is done by setting the property:

properties.put("openejb.embedded.initialcontext.close", "destroy");

But be aware that this property is an undocumented feature and may change in further versions of OpenEJB. This Jira entry recommends to achieve the same effect in configuring the maven surefire plugin.
So the complete method to initialize your in-container tests will look like this:

  public void initializeEmbeddedContainer() throws Exception {
    Properties properties = new Properties();

    properties.put("puName", "new://Resource?type=DataSource");
    properties.put("puName.JdbcDriver", "org.hsqldb.jdbcDriver");
        .put("puName.JdbcUrl", "jdbc:hsqldb:mem:testdatabase");
    properties.put("", "update");

    context = new InitialContext(properties);

Setting up a unit test

The last thing to do now is getting your beans from the embedded container. This can be done in two ways. One way is to use a special OpenEJB annotation to inject the bean into your test class. As this is an elegant way I prefer to code this with plain old Java method calls using JNDI lookup, because the first solution will make your code depend on OpenEJB API.
This is how it works with local EJBs:

IServiceLocal localService = (IServiceLocal) getContext().lookup(ServiceImplLocal);

where IServiceLocal is the local interface of the session bean and ServiceImplLocal is the JNDI name of the bean implementation. The OpenEJB standard JNDI name for beans is {deploymentId}{interfaceType.annotationName}.
The deploymentId is the name of the EJB implementation (in our case ServiceImpl) and the interfaceType is Local, because the EJB under test is a local EJB.

Running your tests

Simply call
mvn clean test

Monday, June 01, 2009

Switching my home Linux server from Knoppix to Ubuntu

My Linux box at home crashed during a distribution upgrade of my Knoppix version. I always had troubles in doing a distribution upgrade of my Knoppix server. So I decided to switch to Ubuntu 9.04.
The server is back since yesterday but not all the services are running.
I hope I will not regret this decision.

Monday, April 27, 2009

Encoding mp3 under Ubuntu Linux

I recently ran into a problem encoding some audio files under my Ubuntu Linux 8.10. There was no way I could bring the "Audio CD Extractor" or "Rhythmbox Music Player" to encode my CDs to mp3.
It took me some time to figure out what the problem was. There should be at least three packages installed, to be able to encode audio files to mp3:


My Ubuntu 8.10 did not have the last one installed. So I did a quick

"apt-get install gstreamer0.10-plugins-ugly-multiverse"

and the problem was solved.
The last thing I did was to create and activate an mp3 profile in the preferences dialog of the "Audio CD Creator"

Wednesday, February 18, 2009

Open Source Webmailer RoundCube

RoundCube Webmail is an open source browser-based multilingual IMAP client with an application-like user interface. It is developed in PHP and comes with a very comfortable installer interface.
The configuration took me just about 5 minutes and the webmailer was up and running on my Knoppix Linux box at home.
In the past I tried different webmailers on my local linux box (including AtMail and Claros Intouch). None of them were able to cope with nested folders on my dovecot imap server. RoundCube has no problems with that.
The web interface is very intuitive and uses a lot of AJAX (e.g. drag and drop). So if you would like to have a good looking, modern webmailer try RoundCube Webmail.