Eskatos’s thoughts on JEE development

Customer i18n overlays with GWT

Posted in HOWTOs by eskatos on July 19th, 2008

I’m building a web backoffice for an IT product with GWT for several month now. I had to internationalize all the UI. GWT provides several mechanisms for i18n. I use Constants and Messages because I love the compile time check and the fact that deferred binding permutations provide a download as small as possible to the users.

All this worked well until we wanted to provide customers the ability to change how things are named in our product. In the UI layer of course !

Like said above, GWT is using deferred binding to provide a Constant/Message implementation per locale. I extended this mechanism to provide a Constant/message implementation per locale and a given GWT property.

Enough talk, lets see how this is done.
(more…)

Tagged with:

A simple^W dumb Map wrapper to use with JAXB

Posted in HOWTOs by eskatos on March 14th, 2008

I sometimes need to use java.util.Map objects in WebServices. As I’m building all my WebServices with the JAX-WS RI (using the Metro bundle). The block responsible for XML (un)marshalling of POJO, named JAXB, does not allows to directly use Maps as a soap operation parameter. For this purpose I’ve written the following simple class that allows me to wrap Maps in a POJO that JAXB is able to (un)marshall :

public class JAXBMapWrapper<KT, VT> {

    private Map<KT, VT> wrappedMap;

    public JAXBMapWrapper() {
        wrappedMap = new HashMap<KT, VT>();
    }

    public Map<KT, VT> getWrappedMap() {
        return wrappedMap;
    }

    public void setWrappedMap(final Map<KT, VT> givenMap) {
        wrappedMap = givenMap;
    }

}

ATTENTION : I posted this some days ago and removed the post after understanding that this is simpler on the service side but that the client side gets cumbersome generated classes.. but google cache indexed the post in less than half a day.

Just don’t use this ! :) If you need to transmit Maps over JAX-WS webservices, do it the XmlAdapter way as advertised in the official Unofficial JAXB Guide instead.

Tagged with: , ,

Glassfish, Hibernate and WebServices - WSGEN Classpath

Posted in HOWTOs by eskatos on October 16th, 2007

Following my quick and dirty how-to about using hibernate in glassfish I came across a small pitfall when dealing with metro webservices.

The glassfish’s wsgen classpath on Glassfish is not by domain, ie. the wsgen tool is not run in the domain class-loader.

When trying to deploy a webservice that returns an entity with a hibernate annotation, I got this following error :

Deploy error

Server logs showed the following trace :

/home/paul/Programs/glassfish-v2-b58g/domains/domain1/applications/j2ee-apps/ear-0.1-SNAPSHOT/lib/entities-0.1-SNAPSHOT.jar(app/model/entities/User.class):
        warning: Cannot find annotation method 'value()' in type 'org.hibernate.annotations.Fetch':
        class file for org.hibernate.annotations.Fetch not found
Problem encountered during annotation processing;
see stacktrace below for more information.
java.lang.NullPointerException
        at com.sun.tools.ws.processor.modeler.annotation.WebServiceAP.isSubtype(WebServiceAP.java:360)
        ...... SNIP ......
        at com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:223)
error: compilation failed, errors should have been reported
Exception occured in J2EEC Phase
com.sun.enterprise.deployment.backend.IASDeploymentException: WSGEN FAILED
        at com.sun.enterprise.webservice.WsUtil.genWSInfo(WsUtil.java:2

Adding the hibernate-annotations.jar file in the glassfish main lib/ directory added the necessary classes to the wsgen classpath.

Tagged with: , , ,

Unit test JPA Entities with in-memory database

Posted in HOWTOs by eskatos on October 15th, 2007

Still about Hibernate, I have several JPA Entities grouped in a Persistence Unit that I need to test. So here is another quick and dirty howto titled “Unit test JPA Entities with in-memory database”.

Here I assume you already have written your entities java classes with correct annotations.

As I’m working with embedded Derby for a year, I first tried with it but procton (thank you procton) pointed me to another lightweight RDBMS.

So, in this how-to we will set up a unit-tests dedicated persistence unit and use HSQLDB as in-memory database for unit tests.
(more…)

Tagged with: , , ,

Quick and dirty howto : Use Hibernate in Glassfish V2

Posted in HOWTOs by eskatos on October 9th, 2007

For my first post here I’ll write a quick and dirty howto for using Hibernate inside the Glassfish V2 container.

  1. Download Hibernate projects
  2. Put’em in the domain’s lib dir
  3. Change your persistence.xml file
  4. Enjoy :)

Details are following :
(more…)

Tagged with: , , ,