January 9, 2015

The Java EE 6 Interceptors


The AOP Interceptor was in EE 6 introduced and was before only supported with additional libraries such as aspectj and jboss-aop.

Before using Interceptor one should first really consider if this is the right tool for solving ones problem. Because using AOP Interceptor is not a holy grail, BUT for certain problem it is. Those are:

  • Logging
  • Caching
  • Security
  • And similiar

The above examples are so called cross cutting concern, that are well suited to be solved with AOP Interceptor.

Java EE 6 Interceptors

To create a Java EE Interceptor you create a POJO with:

  • A public, no-argument constructor.
  • One around-invoke interceptor method with syntax @javax.interceptor.AroundInvoke visibility Object method-name(javax.interceptor.InvocationContext) throws Exception { ... }


To use it, add @javax.interceptor.Interceptors(AuditInterceptor.class) to any bean that supports injection, e.g. Servlet, JSF ManagedBean, EJB.


NOTE: You can either annotate the class (Interceptor will be called whenever every public method is called) or a specific method.

The final piece to make it work is to add the beans.xml in:

  • META-INF/ for ejb jar.
  • WEB-INF/ for web war.


Oracle EE 6 Tutorial Chapter 50: Using Java EE Interceptors

December 22, 2014


Supported styling.


Java EE 7 Maven Dependency

In my previous blog about Java EE 6 Maven Dependency a wrote about the crippled javaee-api maven dependency in maven central.

That is finally fixed in EE 7.

See also Essential Maven POM For JavaEE 7

December 21, 2014

Java EE 6 Maven Dependency

The EE 6 classes are available in maven central.

But when running unit test against them you receive the below error. Thats because they do not contain implementation classes, only api class.

So in practice, the dependecy is in real life unusable. Instead you must use api classes from specific vendors like JBoss.

Java EE 7 Deployment Descriptors

Deployment descriptors are like configuration files.

The below sites summaries all xml schemas defintions for all EE 7 deployment descriptors.


Java EE 6 Interceptors 1.0 (JSR318)


Interceptor was in EE 5 introduced in EJB 3.0, see EJB3 Interceptors javax.ejb.AroundInvoke. In EE 6 that was taken out and made generic into Interceptors (JSR318), package javax.interceptor.*.

You can call Interceptor in EE 6 in two way:

  • By annotating method or class with @javax.interceptor.Interceptors(MyInterceptor.class)
  • Create custom Annotation with Annotation @javax.interceptor.InterceptorBinding and annotate with that you method or class.


Your custom Interceptor.

Interception in a POJO.

Interception in a Stateless Session Bean.

beans.xml located for war in WEB-INF/.

To use the Interceptor you must let weld create the intercepted class, otherwise will weld never knew about the interceptor and hence will the interceptor never work.

Example usage from a Servlet.


You cannot use Interceptor directly in servlets, see https://java.net/projects/servlet-spec/lists/jsr340-experts/archive/2012-02/message/0.

Taking Snapshot in Ubuntu

When taking snapshot in Ubuntu you could always use the predefined keyboard shortcuts, see https://help.ubuntu.com/community/KeyboardShortcuts#Desktop_shortcuts

A better tool is to use the gnome-screenshot tool.

You can install via `sudo apt-get install gnome-screenshot`