wicket and tomee

Two weeks of holiday means time to finally play with some things I had on my list for quite some time now. One of them was Tomee. I have always been interested in JEE applications. Coming from the old old EJB 1 I remember the pain of working with it and I switched quite fast to Spring.

A lot has changed in the years and EJB 3 and 3.1 are a delight to work with. Tomee is a apache project where they have upgraded Tomcat with other apache projects to make a complete TCK passing EE server. Go to tomee.apache.org and especially watch David talk about it. I saw him give a talk in Devoxx and he is very enthousiastic.

While playing with it I noticed not even the examples worked from within Wicket. The problem was the way the wicketstuff javaee-inject does the naming lookup:

 public String calculateName(String ejbName, Class<?> ejbType)  
     return "java:comp/env/" + (ejbName == null ? ejbType.getName() : ejbName);  

The name will not be found that way. Tomee is built on EJB 3.1 and it standardized they lookup to: java:global[/<application-name>]/<module-name>/<bean-name>#<interface-name>

So again the way wicket is setup comes to the rescue. Make your namingstrategy:

 public class TomeeJndiNamingStrategy implements IJndiNamingStrategy {  
   private static final long serialVersionUID = 4496498533970047379L;  
   public String calculateName(String ejbName, Class<?> ejbType) {  
     String nameToUse = ejbName != null ? ejbName : ejbType.getSimpleName();  
     return "java:global/tomee/" + nameToUse + "!" + ejbType.getName();  

I use tomee here as it is the name of the project. YOu could of course make it generic by using java:global/module/. Install it like this:

   protected void init() {  
     getComponentInstantiationListeners().add(new JavaEEComponentInjector(this,new TomeeJndiNamingStrategy()));  

done. You can now get EJB’s from tomee in your wicket application. Will it be much use this way? According to the wicketstuff wiki:

Beware! Due to classloading limitations for entities, you cannot mix the usage of @PersistenceUnit and @EJB to persist your entities. So you have to choose only one of these approaches in your application.

So either you can use a persistenceUnit or an EJB. Hmmmz but I wanted EJB’s that have persistence units. You know the way netbeans does facade’s………

Well another thing solved.

comments powered by Disqus
comments powered by Disqus