Category Archives: Java / J2EE

Tips on Java & J2EE development.

JBoss 4.2.3.GA – Administration guide best practices

The JBoss AS 4.2.3 ships with the following directory structure for a given instance:

conf/     contains JBoss bootstrap configuration files
lib/      contains static libraries that are loaded on startup
deploy/   contains deployable resources (applications, xml files, jar files, ...)

When going to production, people just ships the JBoss AS as it is and deployments are operation on this directory structure directly. I think this is a bad practice and I personnaly strongly advice to separate the concerns and isolate application specific resources into separate and external folders:

  • these folders contain instance bootstrap resources and modifying or manipulating these resources can be tricky
  • Separating JBoss AS resources from application specific resources will make any deployment automation more easier
  • Isolating JBoss AS resources will make Docker-ization of a JBoss container much more easier too!

Hopefully this has been made possible by JBoss!

The deployment folder “./deploy”

The JBoss AS “deploy” folder of an instance ships with a certain number of applications (a EJB Deployer, a WEB deployer – namely Tomcat, JMX console …).
This folder is scanned on startup and is configured in the conf/jboss-service.xml file. You can add any number of external folders to the scanning component for application deployment on startup as well as for hot deployment. Locate the section below within the org.jboss.deployment.scanner.URLDeploymentScanner

    <attribute name="URLs">

and just add you (external to jboss) applications specific deployment folder as follows:

    <attribute name="URLs">

In Docker, this folder can be mapped as a Volume.

The configuration “./conf”

The ./conf folder, in addition to containing JBoss bootstrap configuration files can contain your application specific resources, these resources are added to the applications resources classpath by JBoss and can be loaded using, for example, using


You can define, through the command line an external folder to the loaders classpath as follows:

bin/ --classpath=/path_to_resources_folder

You can put in this folder all the ressources (xml files, properties, … etc) the application will access through MyClass.getResourceAsStream("/myresource");.

In Docker, this folder can be mapped as a Volume.

The static libraries folder

The ./lib folder contains static libraries (loaded on startup), these libraries are necessary for JBoss default applications deployment and startup.
For your application libraries, you can either package them within the artifact (ear or war) – I strongly advice this approach – or you can add them as static library and be loaded on JBoss startup (this is mandatory if you want to deploy a .jar artifact for example as this latter cannot contain third party libraries).

You can define a separate and external libraries folder for you application third party libraries though command line as follows

bin/ --library=path_to_libraries_folder

In Docker, this folder can be mapped as a Volume.

JBoss 4.2.3.GA command line options

Here is the list of JBoss 4.2.3.GA launch options from the MainClass of the bin/run.jar

-h, --help                    Show this help message
-V, --version                 Show version information
--                            Stop processing options
-D<name>[=<value>]            Set a system property
-d, --bootdir=<dir>           Set the boot patch directory; Must be absolute or url
-p, --patchdir=<dir>          Set the patch directory; Must be absolute or url
-n, --netboot=<url>           Boot from net with the given url as base
-c, --configuration=<name>    Set the server configuration name
-B, --bootlib=<filename>      Add an extra library to the front bootclasspath
-L, --library=<filename>      Add an extra library to the loaders classpath
-C, --classpath=<url>         Add an extra url to the loaders classpath
-P, --properties=<url>        Load system properties from the given url
-b, --host=<host or ip>       Bind address for all JBoss services
-g, --partition=<name>        HA Partition name (default=DefaultDomain)
-u, --udp=<ip>                UDP multicast address
-l, --log=<log4j|jdk>         Specify the logger plugin type

Running JBoss-4.2.3.GA on jdk 1.7 or higher

If you’ve got problems running JBoss-4.2.3 on JDK 1.7 version or higher, beacause of

java.lang.IllegalStateException: Cannot build JAXB context ... java.lang.StackTraceElement does not have a no-arg default constructor

Than this is for you!

You get in troubles running JBoss-4.2.3 on a JDK 1.7 or higher mainly because of the JaxWS API : starting from Java 1.7, the Throwable interface gets added a new method getSuppressed() and the JBoss 4.2.3 implementation (jbossws) is based on the Java 1.6 (or 1.5). The patch (that you can download here) allows to filter out that method from the ones that jbossws considers for JaxWS Exception mappings.

Patching it is very eay and strainght forward (thanks Lukasz) and concerns the single AbstractWrapperGenerator class of the jbossws-core.jar library.

You can download from the (github) repository the Java 1.6 compiled version (.class) or you can choose to recompile it by your own (the jbossws source code can be downloaded here). I strongly suggest to replace, from that source code, only the class of interest, namely the AbstractWrapperGenerator as explained in the readme file of the git repository. The recompilation requires you adding many (really many) jars to the project classpath. You can find here an exhaustive listing of the required jars (Many stand on the different JBoss 4.2.3 server folders and some can be found on Maven central repo).

References & links

CXF Configuration to produce JSON Snake-Case (underscore-case) formatted data using Jackson JSON library

Snake-Case JSON format

It consists of writing JSON data in Snake Case.

Configure JacksonJsonProvider to produce Snake-Case / underscore-case formatted data

JacksonJsonProvider from the jackson-jaxrs library (maven) is configured to produce Camel Case JSON formatted data. In order to produce JSON Snake Case formatted data, you have to set the mapping strategy of the JSON ObjectMapper to this way:

ObjectMapper mapper = new ObjectMapper();

Configure a JSON Snake Case Provider in Apache CXF

In order to configure the JacksonJsonProvider (Message Body Writer and Reader) into CXF using Spring based configuration, proceed this way:

  1. Retrieve the (static) Snake/Underscore strategy
  2. <bean id="snakeStrategy" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
       <property name="staticField" value="" />
  3. Declare the Jackson ObjectMapper
  4. <bean id="objMapper" class="" />
  5. Set the Strategy to the ObjectMapper
  6. <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
       <property name="targetObject" ref="objMapper" />
       <property name="targetMethod" value="setPropertyNamingStrategy" />
       <property name="arguments" ref="snakeStrategy" />
  7. Declare the JaksonJsonProvider
  8. <bean id="snakeJsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
  9. Set the ObjectMapper to the Jackson Provider
  10. <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
       <property name="targetObject" ref="snakeJsonProvider" />
       <property name="targetMethod" value="setMapper" />
       <property name="arguments" ref="objMapper" />
  11. Finally use your Provider in your JAXRS Resource
  12. <jaxrs:server address="/resource">
          <ref bean="resource" />
          <ref bean="snakeJsonProvider" />

Enjoy and hope this may help!

Devoxx fr 2015 Edition – A few weeks later (Part 1)

Attend Devoxx!

Devoxx fr 2015 Edition was awesome this year in Paris! I am ashamed to say that it’s the first time I attend to Devoxx fr especially that I live in the suburbs of Paris!

Attend to Devoxx with Oxiane (to the french dev community)

Oxiane is a French company that offers training in new technologies. It is involved in the Devoxx since 2 years now. They can help you attend Devoxx (French editions) and afford the conference fees using your CPF – Compte Personnel de Formation – (Formerly the DIF). Contact them around November, when the conference registration opens. They took more than 700 registrations in this edition.

MyVoxx 2015

I could not attend all the conferences … so what I present hereinafter are my notes, keywords and all what I could humanely hear and pick-up around me, it is my devoxx 2015 360° – MyVoxx and clearly not the Devoxx 2015!

Functional programming – Java 8 & Scala

Scala seems to be largely adopted by the Java community! If you don’t Scala you should! Indeed it’s syntax is very sexy and the need to Functional Programming syntax-like languages was a must largely covered by Scala since! I Personally I am wondering what is the future of Java … the Java community will it become a Scala Community in the near future?

Java 8 came to offer such a functional programming syntax with the Streams API and associated Lambda expressions and to reduce that gap it had! Personally I am beginning to practice the Streams API and Lambda expressions and I found it awesome! We find in the net lots of blogs and introductory articles introducing the Lambda expressions, I personally like the concept that resumes the thing

No more loops with Lambdas!

Java CDI & Metrics

The new CDI specification was, as it seems to me, one of the stars of the meeting! A talk, say a show, on CDI was held by A. Goncalves … it is really a valuable plus for the JEE platform.

I am personally using CDI since few months (JEE 7 on Wildfly 8) but the talks I attended allowed me discover some concepts and tips I didn’t know before!

Metrics CDI I avow that I am completely a newbie on the project .. It seemingly offers interesting things on CDI as completion to JEE CDI … I think you should give it a try!

Apache Spark

I attended a Hands on Lab that introduces Apache Spark (Scala again!) that I found quite interesting! Apache Spark is a framework that aims to lighten and speed up large-scale data based programming over clusters. It offers a MapReduce implementation that compares (seems to be faster) to Hadoop and related frameworks.

It extensively relies on Scala & Java 8 syntax … doing it with Scala is straightforward as it is natively written in Scala!


RxJava (or Reactive Extension for the JVM) is THE framework that retained my curiosity in this Devoxx. I saw RxJava in 2 or 3 talks and it seems really interesting as it offers a high abstraction layer for performing asynchronous operations on the JVM.

Architectural Concerns

There ware many talks about architectural concepts and all that I attended were really interesting and valuable (Uncle Bob is by far amongst the references for – good – Architects).

The talks where about Hexagonal Architecture, Reactive Applications (Reactive Manifesto) and Micro Services Architecture. These talks where awesome and I especially appreciated a conference where people came with there 5-clustered Rasberry PI’s to highlight the concepts of a Reactive application along with the Micro Services Architecture on a Web application (developed with Play framework over Cassandra).

Circuit Broker Pattern

There are many explanatory articles on the web talking about the Circuit Breaker Pattern. It is not part the GoF’s design patterns but, as a relatively not so new pattern in software engineering, you should know it and more importantly be conscious of the use cases it addresses!

Docker containers

Docker appears to be more and more a standard on virtualization and container building. The Dockerfile syntax, though simple, make it very powerful to build and manage containers – pluggable on github and bitbucket for your Dockerfile’s projects, the container updates or building/construction on the top of others follows the same git philosophy (pull, push, fork). You can either share your container to the community on Dockerhub or just keep it running on your server.

Devoxx people talked about it!

Gradle (build automation), Asciidoctor (Markdown like syntax text processor), Eclipse Che & Codenvy (develop, build and run on the cloud), JSonPath (XPath for JSon data), Ratpack, JBoss Forge, JEUS Application server, Kubernetes, CoreOS, Ethereum, Akka Stream, IAAS (Infrastructure as a Service), Cloud Monkey … and much more

SpringSecurity – RememberMe Authentication & Basic Authentication


In Spring Security, you can enable RememberMe Authentication for persistent login. This is achieved via the exchange of a RememberMe cookie between server and client. The configuration presented here shows how this can be accomplished using the Spring Security “form-login” (or equivalent). Shortly, in order to ask for the RememberMe cookie/mechanism from the server, the client must post the parameter “_spring_security_remember_me” along with the login credentials; the RememberMe authentication mechanism is thus tightly related to that parameter and thus to a login form.

In a recent project (a webservices project), I had to establish a persistent login along with a Basic authentication across multiple platforms using the Remember Me cookie approach using Spring Security. The difficulty is to configure Spring Security to send back to client the Remember Me cookie on successful authentication with Basic Authentication credentials (no login form and thus no request parameter “_spring_security_remember_me”).

Here the configuration that allows you to achieved this.

The Basic Authentication entry point configuration

You have to (re-)declare the Basic Authentication entry point and filter:

<http auto-config="false" entry-point-ref="basicAuthenticationEntryPoint">
   <intercept-url pattern="/**" access="ROLE_USER" />
   <remember-me key="mykey" services-ref="rememberMeServices" />
   <custom-filter position="BASIC_AUTH_FILTER" ref="basicAuthenticationFilter" />

<beans:bean id="basicAuthenticationFilter"
	<beans:property name="rememberMeServices" ref="rememberMeServices" />
	<beans:property name="authenticationManager" ref="authenticationManager" />
	<beans:property name="authenticationEntryPoint" ref="basicAuthenticationEntryPoint" />

<beans:bean id="basicAuthenticationEntryPoint"
	<beans:property name="realmName" value="Webservices" />

This XML configuration comes in replacement to the following classical configuration:

<http auto-config="true">
   <intercept-url pattern="/**" access="ROLE_USER" />
   <remember-me key="mykey" services-ref="rememberMeServices" />
   <basic-auth />

In the first configuration above, we disabled the form login (remember that it is a webservices project where authentication is done via Basic Authentication). In order to enable the Remember Me authentication along with that Basic authentication on successful login, we had to:

  1. Disable any default login form and http-basic configuration through the “http” attribute
  2. Define an entry point (there must be at least one) through the “http” attribute

    This is the entry point Spring loads when using “http-basic”

  3. Define the Basic Authentication filter
    <custom-filter position="BASIC_AUTH_FILTER" ref="basicAuthenticationFilter" />

    This again is the default filter Spring loads when using “http-basic” with the difference here that we are referencing the Remember me service bean to support remember on successful authentication

The rest of the configuration file (download file here) is no more that classical Spring Security Remember Me authentication configuration.

This was tested with Spring Security 3.0.x and 4.x.

The Reactive Manifesto

I recently read an article about “Reactive Applications” on the Reactive Manifesto website and I wanted to share this small paragraph with you. I found this part particulary interesting and give the main direction architects and developers should emphasize on when developing new applications:

“New requirements demand new technologies. Previous solutions have emphasized managed servers and containers. Scaling was achieved through buying larger servers and concurrent processing via multi-threading. Additional servers were added through complex, inefficient and expensive proprietary solutions.

But now a new architecture has evolved to let developers conceptualize and build applications that satisfy today’s demands. We call these Reactive Applications. This architecture allows developers to build systems that are event-driven, scalable, resilient and responsive: delivering highly responsive user experiences with a real-time feel, backed by a scalable and resilient application stack, ready to be deployed on multicore and cloud computing architectures. The Reactive Manifesto describes these critical traits which are needed for going reactive.”

Visit the original website of the Reactive Manifesto.