Wicket CDI integration on Jboss AS 7

I have recently begun experimenting with the Apache Wicket web framework. But when I launched the Wicket's examples, I have encountered "java.lang.IllegalArgumentException: Argument 'beanManager' may not be null" expeption.

Even though the solution is quite simple, I don't think that it is as documented as it should be. And the fact that it is the only problem preventing the Wicket's example application from running on Jboss AS 7 is fairly grim.

 

My setup:

  • Jboss AS 7.1.1 Final
  • Oracle Java SE JDK 7u13
  • Wicket 6.6.0
  • EJB 3.1
My goal was to have a working skeleton of a JEE application with Wicket web framework and EJB 3.1 directly injected. All that running on Jboss AS 7.


The project's configuration for Jboss AS is simpler, than the configuration needed for Jetty or Tomcat. Thanks to all the advantages of the Jboss's container.

I have created my project using Jboss's Maven archetype:
  • Group Id - org.jboss.spec.archetypes
  • Artifact Id - jboss-javaee6-webapp-ear-blank-archetype
  • Version - 7.1.1.Beta1
The sample code presented below is based on Wicket's HelloWorld application.

 

Dependencies

Than I added dependencies ... wicket core, cdi and seam conversation (spi and weld). You don't need to add weld-core and stuff libraries like in Wicket's examples, because those are already in Jboss AS.
My pom.xml for web module contains these dependencies:
 
  org.apache.wicket
  wicket-core
  6.6.0
 
 
  org.apache.wicket
  wicket-cdi
  6.6.0
 
 
  org.jboss.seam.conversation
  seam-conversation-spi
  3.0.0.Final
 
 
  org.jboss.seam.conversation
  seam-conversation-weld
  3.0.0.Final
 
If you were to omit also the seam-conversation-weld library, you will run into
"javax.enterprise.context.ContextNotActiveException: Conversation Context not active when method called on conversation Transient conversation" exception. Therefore it is highly discouraged.

 

Web.xml

Web.xml is also easier on Jboss. Because you don't need to deal with weld's activation, since it is managed by server. Therefore web.xml looks exactly the same as in any other wicket application with or without CDI.


 Omega task manager V1.
 Omega

 
  OmegaFilter
  org.apache.wicket.protocol.http.WicketFilter
  
   applicationClassName
   cz.effy.main.omega.web.HelloWorldApplication
  
 
 
  OmegaFilter
  /*
 

 

CDI init

And now the final and the most important step. The CDI's initialization in the application. The Devil lies in the details. The problem is in acquiring the BeanManager, because it is provided by the application server. Thus the only change of the code is done in the main WebApplication class.
package cz.effy.main.omega.web;

import javax.enterprise.inject.spi.BeanManager;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.apache.wicket.Page;
import org.apache.wicket.cdi.CdiConfiguration;

public class HelloWorldApplication extends WicketExampleApplication {
 
 @Override
 public void init() {
  super.init();
  BeanManager manager = null;
  try {
   manager = (BeanManager) new InitialContext()
     .lookup("java:comp/BeanManager");
  } catch (NamingException e) {
  }
  new CdiConfiguration(manager).configure(this);
 }

 @Override
 public Class getHomePage() {
  return HelloWorld.class;
 }
}
This is all you need to do to be able @Inject EJBs into your pages.

 

Conclusion

Wicket's CDI integration on Jboss AS 7 is nothing complicated, but it can prove to be a bit tricky. Just remember to add all dependencies needed and modify the way the BeanManager is acquired.

Comments

  1. Video slots may be 슬롯 an thrilling and profitable various to conventional slot machines, particularly for those who|for many who|for people who} know the proper wagering strategies. In this up to date guide, nationally renowned playing columnist and casino insider Victor H. Royer presents excellent advice for enhancing your odds at video slots. He explains the way to|tips on how to} play the most typical video slot video games within the casino and precisely the way to|tips on how to} maximize your probabilities of success with every. Ignition Casino – Our present favourite for players from the USA or Australia. Ignition casino presents 100s of various slot machines together with classic 3-reel slots and more advanced video slots.

    ReplyDelete

Post a Comment

Popular posts from this blog

Automatic jsp recompile on Jboss AS 7

Running scripts written in Clojure as an executable using Inlein

How to update XML file without reformatting it