If you are using MySQL and Hibernate, maybe you are familar with an exception like this one:


com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was79095 seconds ago.The last packet sent successfully to the server was 79095 seconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.

To me, this problem occurred whenever my web application was not used for a certain amount of time. For some reason, Hibernate (?) does not close the connection properly, but the database system does after the wait_timeout has passed. Now Hibernate wants to use a connection that is not valid any more.

It took me some effort to overcome this problem, but I figured out a clean solution (setting the ‘wait_timeout’ setting of mysqld to days or weeks is NOT a good approach ;)).

The trick is to use connection pooling with c3p0. This way, you can make sure that a connection is revalidated after being idle for a long time. Configuration is quite easy. Just add the following properties to your Hibernate configuration (persistence.xml or hibernate.cfg.xml):

<property name="hibernate.c3p0.min_size" value="3" />
<property name="hibernate.c3p0.max_size" value="50" />
<property name="hibernate.c3p0.timeout" value="1800" />
<property name="hibernate.c3p0.max_statements" value="50" />
<!– this property forces the revalidation of a connection after the given amount of time (in secs) –>
<!– it must be set to LESS than the wait_timout setting for the mysql server (this setting defaults to 28800 secs (8 hours)) –>
<property name="hibernate.c3p0.idle_test_period" value="28680" />

Furthermore, you have to add the c3p0 jar to the classpath of your application.

There are a lot of commercial stress and load testing tools available, but in general they are really expensive, so buying one is probably not the best idea if you just want to stress-test a single web application for one time, like I did.

Instead, I checked out some Open Source tools and found Webload, an Open Source variant of a more comprehensive tool developed by Radview. The download can be found here (it’s not available on the official website any more).

The tool comes with a graphical user interface both for creating test scripts (Webload IDE) and for launching and monitoring tests (Webload console).

Scripts can be recorded by simply clicking links in your browser. Afterwards, the script can be used to create the actual test, consisting of an arbitrary number of virtual users that follow the actions defined in the script. Webload allows monitoring of any values you can think of, ranging from the number of executed requests to throughput in bytes per second.

Because of all those features that seem unique for an Open Source stress test tool, Webload is really worth a tip here at codingclues :)

Well, the following post does not cover a typical programming topic, but maybe even as a software engineer you might have to deal with (web) design from time to time. At least I did when developing a new website for a customer (http://heilmann-software.de).

While creating shiny and glossy effects seems to be a trivial task for the experts using Photoshop, I tried a lot until I got some good results with Gimp, the Open Source image editor.

My goal was to develop a “shiny table” effect from a screenshot that was rotated into the view. Below you can see an example (of the result, of course ;))

Read more…

If you have ever wondered what the nice color names from the .NET Color structure in namespace System.Drawing.Color actually mean, you will find this page very useful.
They present a listing of the named colors in .NET, show how they look like and also specify the corresponding hexadecimal values.

There are many scenarios where a web application must serve a file instead of a response containing HTML output to be rendered by the browser.

This little tip illustrates how to cause the browser to display a file download dialog instead of trying to display the data directly (which fails in most cases, especially with binary data).

As you will see, the whole magic concentrates on a special HTTP header, so this tip can be used with any technology and framework, ranging from Java Server Faces (JSF) and the Seam framework to PHP and even ASP or ASP.NET.

A common way to realize file download is to simply write the file data into the HTTP response.

However, if you have to handle arbitrary files, you are not able to set a specific Content-Type header like text/plain or something else.

So the client (namely the browser) has no idea what kind of data it actually receives and what to do with it.

Here is where the HTTP header Content-Disposition comes into play. Setting this header tells the client that an attachment is received and therefore causes the browser to display a file download dialog.
Now it’s the user’s responsibility to save the file and to open it with a corresponding application.

The Content-Disposition header consists of two values: the string “attachment” indicating an attachment and a “filename” property specifying a filename for the attachment. Usually, the browser takes this value as proposed filename in the download dialog.

The following line is an example extract from an HTTP response containing a Content-Disposition header:

Content-Disposition: attachment; filename="myFile.exe"

Maybe you know the situation: you are developing a web application using the Maven build system along with an application server like Tomcat or Jetty and a corresponding plugin (e.g. the all famous jetty-maven-plugin).

One of the coolest features of these containers is the hot-deployment.

However, every second time a hot deployment is executed, it crashes due to a PermGen space Exception or a similar OutOfMemoryException.

Read more…

Recently I stumbled across a problem with the rich:modalPanel component of the JBoss RichFaces component library, which didn’t want to show the data of a backing been.

Let’s assume the following scenario:
You have a DataTable with several rows. Each row contains a “See details…” button. This button will popup a modal panel using rich:componentControl and the panel is populated with data of a backing bean. This backing bean is filled with actual data by clicking our “See details…” button using a4j:actionparam

Read more…

There are a lot of tips and hints out there on the internet, which describe how you could add support for Java Server Faces and Facelets to the Eclipse environment.
Mostly, they deal with adding code completion for JSF/Facelets tags and so on. There are some possibilities to achieve this, ranging from creating TLD files to using the JSP editor in Eclipse for the XHTML code of the Facelets pages.

But the “trick” I prefer is much more simple :D

You want to see it? Well, just download and install the JBoss Tools and you have it all!

Usually, when you enter standard <!-- ... --> html comments in your XHTML definition for a Facelets view, these comments are rendered by Facelets, so they are included in the resulting HTML. Even EL contained in these comments is executed!

In most cases, this is not what you hope to see, because if you want to make real comments, you have to use the <ui:remove> tag, which is not really comfortable.

Read more…

Recently I visited Jazoon, an international conference for Java developers at Zurich, Switzerland.

Having heard a lot of interesting talks, I want to sum up my impressions and try to figure out some of the latest trends in the world of Java as well as interesting facts for software architects.

This is part 3 of my series of blog posts and deals with

Ajax Push

Having worked with ICEfaces (but suspended work for now due to a lot of bugs), I was curious to hear a talk of one of the guys of ICEfaces, Ted Goddard.

The topic was Ajax Push. Surely, Ajax is a buzzword of today and everybody wants to have some Ajax functionality in his application, maybe just to be cool.

Read more…