Archive for the ‘Computer’ Category

Introducing XmlField : Java xml/object mapping framework

November 28th, 2011

We have recently released XmlField, a new Java xml/object mapping framework.

XmlField logo

There are already a lot of tools for this, but none seemed to fit our requirements :

  • A (very) simple API : we wanted to write as few code/configuration as possible, and keep code meaningful.
  • The ability to process and update XML documents without altering additional, unsupported data. This means that the XML model can be updated without requiring to update and deploy existing applications in most cases. (for more information see the “Behavior” page on the projet’s site.
  • No need to have a 1:1 mapping between the object XML structure, ability to flatten an XML document into a single object

If you’re writing a standalone application and use XML for storing configuration, XmlField will not be a major improvement (you may still like its simple API).

But if you are working in a corporate environment, with multiple applications sharing data using web or REST services, you may already see the benefits of these points.

A typical use case could be a system where user related data is stored in a central repository as xml documents and where this data is exposed through web services and used by several applications (both for reading and writing).

A some point, a new application requires additional data, which is not currently part of the xml model. This usually requires to update the central repository, adding support for this data through a new version of the web services, then maintain 2 versions of these services or move all existing applications to the new model to get rid of the previous one.

With XmlField-based applications, you just have to create your new app which stores additionnal tags in xml doduments. No need to update the central repository nor other applications. They will continue to process and update Xml objects, ignoring the new data but keeping it safe.

On the technical side, XmlField uses annotated interfaces to map xml data to objects. An interface can be written this way :

public interface IModel {
String getVersion();

boolean getFlag();

IEntry getEntries();

void setVersion(String version);

void setFlag(boolean flag);

IEntry addToEntries();

Then XmlField can be used this way :
// Source Xml
String xml ="";

// Read doc
XmlField xf = new XmlField();
IModel model = xf.xmlToObject(xmlRessource, IModel.class);

// Play with XML
model.setVersion( "1.0" );
String firstEntryName = model.getEntries()[0].getName();

//Add entry
IEntry newEntry = model.addToEntries();
newEntry.setName( "entry4" );
newEntry.setValue( "value4" );

// Back to XML.
xml = xf.objectToXml( model);

For more detailed examples, I just added a quickstart tutorial and a step-by-step example to the project’s website.

Even if the version number is only 0.6 yet, XmlField is stable enough for most uses and is currently used in production by several projects in different companies. We plan to reach 1.0 after the addition of a new document repository module, providing a lightweight xml document store with search and data validation.

Feedback is welcome. Feel free to test, use and report bugs or patchs using the project bugtracker and mailing lists.

XmlField released under the Apache Licence V2.0

(Related keywords : xml, java, serialization, marshalling, mapping, binding)

Solve webapp random startup errors (connection time out) and slowness

February 16th, 2011

When developping Java web apps, you may sometime see random startup errors like this one :

java.lang.IllegalStateException: Unable to instantiate container.
at org.apache.tiles.web.startup.TilesListener.contextInitialized(
at org.mortbay.jetty.handler.ContextHandler.startContext(
at org.mortbay.jetty.servlet.Context.startContext(
at org.mortbay.jetty.webapp.WebAppContext.startContext(
at org.mortbay.jetty.handler.ContextHandler.doStart(
at org.mortbay.jetty.webapp.WebAppContext.doStart(

Most of the time your application works, but sometimes it just does not start.

This is because of the dtd resolution mecanism: if you use the reference of a dtd which is not in the webapp classpath, the container will try to get it from internet.

If the remote site is down (in this case, your app will no longer start.

Sadly, it’s easy to get in this situation.

  • Upgrade a library without updating xml headers
  • Copy/Paste a snippet from the elsewhere

… and the container will start to fetch dtds from the internet.

In my case, the previous error was caused by :

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"


instead of :

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"


With tiles 2.0.6 in the classpath.

Be sure to use the exact version of the dtd in your classpath. Don’t pickup examples from the internet without double-checking the dtd.
This will prevent longer startup times and potential random errors.

Note: this post dedicated to Olivier and Jimmy :-)

ESIGate Tutorial – Partie 2

December 16th, 2010

Après une première partie technique, nous allons étudier une partie plus théorique sur les différents usages d’ESIGate dans des projets Web.

Attention: Article en cours de rédaction, les concepts étant relativement complexes à comprendre (mais simples à mettre en oeuvre), vous êtes invités à commenter ce post pour aider à l’améliorer.

Le coeur d’ESIGate est une implémentation Java d’un moteur d’ESI :

  • a partir d’un document HTML, le framework va parser le flux à la recherche de directives référençant des contenus à intégrer depuis des URL externes.
  • Ces contenus sont récupérés et mis en cache automatiquement, puis insérés dans le flux HTML original.
  • Les directives peuvent soit suivre la norme ESI, soit utiliser le format ESIGate, plus riche en terme de fonctionnalités.

ESI, à quoi ça sert ?
Les usages sont multiples, mais à l’origine la norme ESI permet d’étendre les possibilités de mise en cache des pages produites par des applications web et donc d’améliorer grandement leurs performances.


ESIGate Tutorial – Part 1

November 28th, 2010

(Ce tutorial est aussi disponible en Français : ESIGate Tutorial – Partie 1)

In this series, I will present the various uses of ESIGate framework (former Assembly Web Tool – WAT).

In Part 1, we will integrate a very simple application in a remote template, only via http. The typical use is a corporate intranet: multiple different applications (content management, HR management, time reporting, etc …) can use the same theme, based on a master application.

This has the following benefits:

  • almost no need to work on styling (html/css) in slave applications.
  • When the theme changes in the master application, the changes are immediately reflected on all slave applications without restart
  • the master application can be replaced with no impact if the new theme is compatible
  • If the new master application is incompatible with the previous theme, the synchronization can be ‘broken’ by pointing slave applications on a static html file


Git : set committer name and email

November 28th, 2010

git config --global "<your-name>"
git config --global "<your-email>"