Testing secured EJBs with Arquillian

Testing secured EJBs has been historically hard to get right. Up until now, I have been using proprietary techniques like JBossLoginContextFactory described in the article Testing secured EJBs on WildFly 8.1.x with Arquillian to test secured EJBs.

During this year Devoxx, David Blevins, founder of the Apache TomEE project – a lightweight Java EE Application Server, brought to my knowledge a little trick we can use to deal with Java EE security in a standard way that works across all Java EE compliant servers.

The example used in this post is available at javaee-testing/security on GitHub.

Continue reading Testing secured EJBs with Arquillian

Minify Maven Plugin with support for JavaScript Source Maps

The new version (1.7.3) of Minify Maven Plugin has just been released.

The list of enhancements include:

  • Support for JavaScript Source Maps
  • Better docs
  • Update to the last version of Google Closure Compiler
  • Add support for Google Closure Compiler angular_pass option to support AngularJS @ngInject annotations

Get it while it’s still hot!

Validating JAX-RS resource data with Bean Validation in Java EE 7 and WildFly

I have already approached this subject twice in the past. First, on my post Integrating Bean Validation with JAX-RS in Java EE 6, describing how to use Bean Validation with JAX-RS in JBoss AS 7, even before this was defined in the Java EE Platform Specification. And later, on an article written for JAX Magazine and posteriorly posted on JAXenter, using the new standard way defined in Java EE 7 with Glassfish 4 server (the first Java EE 7 certified server).
Now that WildFly 8, previously know as JBoss Application Server, has finally reached the final version and has joined the Java EE 7 certified servers club, it’s time for a new post highlighting the specificities and differences between these two application servers, GlassFish 4 and WildFly 8.

Specs and APIs

Java EE 7 is the long-awaited major overhaul of Java EE 6. With each release of Java EE, new features are added and existing specifications are enhanced. Java EE 7 builds on top of the success of Java EE 6 and continues to focus on increasing developer productivity.

JAX-RS, the Java API for RESTful Web Services, is one of the fastest-evolving APIs in the Java EE landscape. This is, of course, due to the massive adoption of REST-based Web services and the increasing number of applications that consume those services.

This post will go through the steps required to configure REST endpoints to support a JavaScript client and to handle validation exceptions to send localized error messages to the client in addition to HTTP error status codes.

Source code

The source code accompanying this article is available on GitHub.

Continue reading Validating JAX-RS resource data with Bean Validation in Java EE 7 and WildFly

Migrating from a Subversion repository to GitHub

One of greatest attractions of GitHub is the community and the tooling that allows this community to share code. Each contributor can clone the repository, make their changes and then send you a pull request. As the project maintainer your job is now a whole lot easier and more manageable. No more patch files to worry about.

Follow the recipe bellow to move your SVN repo to Git.
Best of all, you get to keep the entire commit history of your project.

Continue reading Migrating from a Subversion repository to GitHub

Minify Maven Plugin adds support for Google Closure Compiler

I’ve recently implemented some new improvements to Minify Maven Plugin.
Version 1.6 added support for Google Closure Compiler and version 1.7 offers several performance improvements and more detailed logs (e.g. compression benefits from minification).

A complete list of changes can be found in the changelog file.
For next releases I’m planning to add Source Maps support and improve the documentation.

Integrating Bean Validation with JAX-RS in Java EE 6

This article was first published on Java Advent Calendar.

Introduction to Bean Validation

JavaBeans Validation (Bean Validation) is a new validation model available as part of Java EE 6 platform. The Bean Validation model is supported by constraints in the form of annotations placed on a field, method, or class of a JavaBeans component, such as a managed bean.

Several built-in constraints are available in the javax.validation.constraints package. The Java EE 6 Tutorial lists all the built-in constraints.

Constraints in Bean Validation are expressed via Java annotations:

public class Person {
    @Size(min = 2, max = 50)
    private String name;
    // ...

Bean Validation and RESTful web services

JAX-RS 1.0 provides great support for extracting request values and binding them into Java fields, properties and parameters using annotations such as @HeaderParam, @QueryParam, etc. It also supports binding of request entity bodies into Java objects via non-annotated parameters (i.e., parameters that are not annotated with any of the JAX-RS annotations). Currently, any additional validation on these values in a resource class must be performed programmatically.

The next release, JAX-RS 2.0, includes a proposal to enable validation annotations to be combined with JAX-RS annotations. For example, given the validation annotation @Pattern, the following example shows how form parameters could be validated.

Continue reading Integrating Bean Validation with JAX-RS in Java EE 6

Running Drools 5.4.0 Final as a JBoss AS 7 module

Drools 5 introduces the Business Logic integration Platform which provides a unified and integrated platform for Rules, Workflow and Event Processing. It’s been designed from the ground up so that each aspect is a first class citizen, with no compromises.

Drools 5 has splitted up into 4 main sub projects:

  • Drools Guvnor (BRMS/BPMS)
  • Drools Expert (rule engine)
  • Drools Flow (process/workflow)
  • Drools Fusion (cep/temporal reasoning)

In this example we will focus on how we can use Drools Expert inside JBoss Application Server 7.

Continue reading Running Drools 5.4.0 Final as a JBoss AS 7 module

Comparing Device Description Repositories

Update: OpenDDR and 51Degrees.mobi dependencies have been updated on 2014-01-20.

Web content delivered to mobile devices can benefit from being tailored to take into account a range of factors such as screen size, markup language support and image format support. Such information is stored in “Device Description Repositories” (DDRs).

Until recently WURFL was the de facto DDR standard for mobile capabilities, but its license changed to AGPL (Affero GPL) v3, meaning it is not free to be used commercially anymore. Consequently some free open source alternatives to WURFL have recently started to show up and are improving quickly.

OpenDDR and 51Degrees.mobi are candidate substitutes to WURFL that also provide an API to access DDRs.

These tools ease and promote the development of Web content that adapts to its delivery context. This post summarizes the installation and configuration of these tools and analyzes how they compare in terms of image adaptation.

The source code used for this post is also available on GitHub.

Continue reading Comparing Device Description Repositories

Java EE 6 Testing Part II – Introduction to Arquillian and ShrinkWrap

In Java EE 6 Testing Part I I briefly introduced the EJB 3.1 Embeddable API using Glassfish embedded container to demonstrate how to start the container, lookup a bean in the project classpath and run a very simple integration test.

This post focus on Arquillian and ShrinkWrap and why they are awesome tools for integration testing of enterprise Java applications.

The source code used for this post is available on GitHub under the folder arquillian-shrinkwrap.

The tools


Arquillian brings test execution to the target runtime, alleviating the burden on the developer of managing the runtime from within the test or project build. To invert this control, Arquillian wraps a lifecycle around test execution that does the following:

  • Manages the lifecycle of one or more containers
  • Bundles the test case, dependent classes and resources as ShrinkWrap archives
  • Deploys the archives to the containers
  • Enriches the test case with dependency injection and other declarative services
  • Executes the tests inside (or against) the containers
  • Returns the results to the test runner for reporting

ShrinkWrap, a central component of Arquillian, provides a simple mechanism to assemble archives like JARs, WARs, and EARs with a friendly, fluent API.

One of the major benefits of using Arquillian is that you run the tests in a remote container (i.e. application server). That means you’ll be testing the real deal. No mocks. Not even embedded runtimes!


The following topics will be covered on this post:

  • Configure the Arquillian infrastructure in a Maven-based Java project
  • Inject EJBs and Managed Beans (CDI) directly in test instances
  • Test Java Persistence API (JPA) layer
  • Run Arquillian in client mode
  • Run and debug Arquillian tests inside your IDE

Continue reading Java EE 6 Testing Part II – Introduction to Arquillian and ShrinkWrap