Java Tomcat

Undocumented Java WebStart Features

Many of you might use Oracle’s JNLP Download Servlet, delivered with JDK in jnlp-servlet.jar. One of the nice features of this servlet is the automatic replacement of variables at runtime, e.g. codebase and context. However, the existing documentation does not reveal all of these replacements. While searching for a solution where I need to put the server name into the JNLP file, I also examined the source code of JnlpDownloadServlet. And voilá: the feature is already there but not documented.

Here is the complete list of replacements that the servlet does for you while delivering a JNLP:

  • $$name: will be replaced by the name of the URL file requested (without path, e.g. myfile.jnlp)
  • $$hostname: will be replaced by the servername as given in the HTTP(S) request
  • $$codebase: will be replaced by the codebase (request without URL file: http://my.server/appname/somedir/)
  • $$site: will be replaced by the protocol, server and port, e.g. http://my.server:8080

I hope you’ll find that useful next time you look for a solution to deliver WAR files to individual servers with the specific servername in its JNLP file.

CSV Java

CSV/Excel Utility Package V2.0.2 released

The package has undergone some minor bugfixing andJUnit Test was introduced for CSV files. Thanks to eldn for his help making this release.

You can download it here or visit the Homepage of the utility where you will find some examples on how to use it.


Log4j Configuration Problem

It seems that some documentation that is hanging around the net contains incorrect information about correct configuration of the log4j system.

Take care that you specify the properties filename as an URL rather than simple plain path location, e.g

java -Dlog4j.configuration=file:///my/path/to/ ...

Log4j should find your configuration then. So make sure you include file:// there… 😉

CSV Java

CSV Utility Package 2.0 Beta

Some work has been spent over the last weeks to upgrade the stable CSV Utility Package. Of course, the new version contains all the useful existing functionality. The most beneficial improvement is the introduction of ExcelReader and ExcelWriter classes that behave like the CSV pendants. This means that you do not have to care about the underlying output format when you want to read or write table-structured data. The most important changes are:

  • Introduction of a TableReader and TableWriter interface
  • Introduction of Excel implementation
  • Aligning CSV and Excel implementations to these interfaces
  • Introduction of a Factory class in order to select correct implementation (CSV or Excel)

The Beta version still requires some work in terms of documentation and code beautifying. However, the CSV part is already frozen and you can use it to upgrade your existing projects to the new utility version. The Excel part still faces some changes while improving usability.

Please be aware also that Java package structure needed to be changed to integrate the new classes and interfaces. Additionally, new 3rd party libraries were integrated (Apache POI and JavaBeans Activation).

Download the Beta Version or browse the existing API Documentation. Bugs and/or enhancements can be requested via Bugzilla.

Miscellaneous Perl

Regular Expression for Email Addresses


Apache Perl

Installing Bugzilla

This was weird. I lately tried to install Bugzilla on one of my virtual hosts but it’s script failed with:

Use of uninitialized value in pattern match (m//) at ./ line 110.
Use of uninitialized value in pattern match (m//) at ./ line 110.
TEST-FAILED Webserver is not executing CGI files.

The Apache error log told nothing more than

Premature end of script headers: testagent.cgi

All Google lookups failed to solve my problem. Although I had the impression that my CGI setup was somehow wrong, I couldn’t find the reason. Then I intensively checked the VirtualHost directive. The server uses a Plesk 8.0 installation for setting up hosts. The default configuration for virtual hosts with CGI there is to include a “SuexecUserGroup” directive. After removing it, the Bugzilla installation succeeded.

So you might wanna give it a try 😉

Update May 6, 2012: You might also want to try these commands when experiencing “Access Denied” problems in a virtual host environment:

find . -type f -exec chmod o+r {} \;
find . -type d -exec chmod o+rx {} \;

Do not forget to revert this change for localconfig file!!!

Java Templating

Templating Java Package 1.0.1 released

A new minor release of Templating Java Package has just been released. It fixes a major bug when replacing markers with values that itself contain strings looking like regular expressions. All such expressions are masked now to prevent an exception.

Download the release here.

Java Templating

Templating Java Package

You might remember my Templating post describing a Java class that implements a Typo3-like technique for a templating machine. I made a Java package out of it and you can use it right away. Just download it here. The API documentation is available, too.

CSV Java

CSV Utility Package Released

I decided recently to publish my very simple utility classes for reading and writing CSV files. The main project page is now available. The package, published under the GNU Lesser General Public License, allows you to easily integrate CSV functionality into your application. The utilities can be configured to use different column delimiter and separator characters in case you need to adopt some other versions of CSV. The default configuration conforms to the Excel style of CSV.

Since this CSV package uses streams, you are able to read from any stream. And, of course, you can write to any stream. You could even synchronize in your application by applying the reader/writer synchronization described in one of my artices.

You can download the latest stable release at the main project page.

Here is a short example on reading a CSV file using the CSVReader class: f = new"csv-test.csv");
csv.CSVReader in = new csv.CSVReader(new;
while (in.hasNext()) {
    String columns[] =;
    // Do something here

Please note that the CSVReader class actually implements the Iterator interface.

Writing a CSV file is even easier. Just create an instance of the CSVWriter class and pass it your rows: f = new"csv-test.csv");
CSVWriter out = new CSVWriter(new;
out.printRow(new String[] { "0:0", "0:1", "0:2" });
out.printRow(new String[] { "1:0", "1:1", "1:2" });


The API documentation tells you all details and configuration parameters that you can use to control the behaviour of the reader and writer classes.


Synchronizing Reader and Writer Threads

Here are two functions that you should use when you want two threads, producer and consumer, to be synchronized. I used these functions mainly to ensure that the reader will stop until an object is ready to read. An advantage is that you can control how many objects are in memory at the same time.

protected List<Object> availableObjects = new ArrayList<Object>();
 * Delivers the next object.
 * Used by the reader/consumer thread.
public synchronized Object next() {
	Object rc;
	while (availableObjects.isEmpty()) {
		try {
		} catch (InterruptedException e) { }
	rc = availableObjects.remove(0);
	return rc;
 * Adds a new object to the list of available objects.
 * Used by the writer/producer thread.
public synchronized void addObject(Object o) {
	while (availableObjects.size() >= 20) {
		try {
		} catch (InterruptedException e) {}

The main idea was taken from Silberschatz’ book about Operating Systems. You have to make sure that you never call the next() method when the last object was read. So be careful when your number of objects produced is limited.