Blogging about Software Development focused on Java Enterprise Edition and Integration. I am also blogging about general Java topics, books and so on.


The DZone Most Valuable Blogger Program

I'm very proud to announce that I have been added to the DZone Most Valuable Blogger (MVB) Program.
The MVB Program simplifies the process of publishing selected blog articles onto DZone's network.
This means they will select among my published blog posts/articles and republish it on DZone. A list of my shared links and published articles can be found here.


Review: Instant Apache ActiveMQ Messaging Application Development How-to

After reading the ActiveMQ in Action book by Bruce Snyder, Dejan Bosanac and Rob Davies (which I really like), I wanted to read more about how to work with Apache ActeiveMQ, its features and ActiveMQ ingeneral. So I bought this one. In this review I want to share my thoughts about this book and help you with your buying decision.


Apache ActiveMQ is a powerful and popular open source messaging and Integration Patterns server. ActiveMQ is a fully JMS 1.1 compliant Message Broker and supports many advanced features beyond the JMS specification.
Instant ActiveMQ Application Development How-to shows you how to get started with the ActiveMQ Message Broker. You will learn how to develop message-based applications using ActiveMQ and the JMS specification.
In this book you will learn all the basic skills you need to start writing Java Messaging applications with a firm grounding in the more advanced features of ActiveMQ, giving you the tools to continue to master application development using ActiveMQ.
Starting by applying the messaging features of the JMS specification to write basic messaging applications, you will develop a basic JMS application using topics and queues to broadcast events as well as perform Request and Response operations over the JMS.
Once you have mastered the simple tasks you will move onto using the advanced features in ActiveMQ to supercharge your messaging applications. You will get to grips with ActiveMQ’s scheduler to delay messages. You will also learn how to leverage ActiveMQ’s fault-tolerant capabilities to create robust client applications.

Product Details

Paperback: 78 pages
Publisher: Packt Publishing (May 23, 2013)
Language: English
ISBN-10: 1782169415
ISBN-13: 978-1782169413

The Author

Timothy Bish is a senior software engineer currently working for RedHat Inc. He currently works out of his home in Alexandria, VA, actively contributing to the ActiveMQ Project. Timothy started his work in the open source world as a side project while working for a company in Syracuse NY. What started as something fun turned into a full time career and remains a passion for Timothy. Timothy started his career in software development in 1999 and has worked for several years in the private sector before moving into full time open source development. During that time Timothy earned his Masters of Computer Engineering from Syracuse University. Having worked on a number of home grown Messaging frameworks Timothy has seen firsthand how the world of open source software like ActiveMQ has transformed the development world. Besides working on new development projects Timothy also enjoys reading, skiing, scuba diving, and traveling to new and exotic places.

The Content

The book starts simple with installing and running an ActiveMQ Broker. Timothy also explains how to set up a basic application developer environment for ActiveMQ using Apache Maven. After that introducing chapters, you will write a basic JMS applications using topics and queue to broadcast events and perform Request and Response style operations over JMS.
You will also learn how to write applications that embed ActiveMQ brokers directly into their own JVM and Utilize ActiveMQ's fault tolerant features to develop robust client applications. Last but not least you will lean how to delay message sending using ActiveMQ's built in scheduler.

Writing and Style

If you are used to technical documentation you shouldn't struggle with this book. For a non native speaker it reads very easy. I didn't find very many complex sentences which were too complex for non natives.

Conclusion and Recommendation

This book is ideal for you if you are a beginner in Enterprise Messaging and want to start with Apache ActiveMQ. The reader needs a very basic understanding of Apache Maven to be able to follow the instructions in this book. Most of the chapters end with hints to further readings. This really rounds off this very beginners good book.
After reading this book the reader gets a good overview and basic understanding of ActiveMQ for a fair price (especially if you buy the ebook). I really like the hints to further readings after each chapter.

The whole book in just one sentence: ActiveMQ brought to the point!

In case you decided to buy or you already read this book, take a look the ActiveMQ in Action book. It covers more detailed and advanced knowledge and is an ideal addition to this beginners book. I also wrote a review about it:  Review ActiveMQ in Action.



Message Level Authorization in Apache ActiveMQ

While the last post covered Broker Level Authentication, this blogpost is about more strict authorization on message level.
I didn't have this fine granular authorization out there in real life projects, but I want to do it myself and give readers a tutorial to widen their knowledge about security in ActiveMQ and ease their beginning with it.
Sometimes it can be useful to restrict access to brokers and on top of it to certain messages. ActiveMQ doesn't come with a plugin for it out of the box. You have to implement it more or less on your own.

Create a Java project with Maven

You have to start with creating a new Java project based on Maven.
In the next step, I recommend to add the activemq-all maven dependency (in the same version as your activemq installation to your project to be sure you use the correct imports and classes).
A list of all activemq versions and corresponding maven dependency snippets is available here.
After that it's time to add a new Java class to your formerly created project. My Message Level Policy class looks like this:
package com.schulz.bennet.activemq;

import org.apache.activemq.command.Message;

public class MyMessageAuthorizationPolicy implements MessageAuthorizationPolicy {

    public boolean isAllowedToConsume(ConnectionContext ctx, Message m) {
        return ctx.getUserName().equals("admin");
Note: Your class has to implement the MessageAuthorizationPolicy interface and you have to add the public boolean isAllowedToConsume(...) method to your class as well. Within this method you can implement your logic to decide who is allowed to consume your messages. In my example admins are allowed to consume, only.

Add the Policy to ActiveMQ

Open a console, cd into your project folder and build your maven application by calling mvn clean install command.
Now it's time to copy the jar file from the target project folder to the lib folder of your ActiveMQ installation to make it available for ActiveMQ. In the last configuration step you have to add the following snippet into broker tag of the activemq.xml:

    <bean class="com.schulz.bennet.MyMessageMessageAuthorizationPolicy"
        xmlns="" />

 Hint: Don't forget to change it to your fully qualified classname, not mine ;-)

Test the Policy by consuming messages

    First you have to start the broker via the following command on your console:
    ./bin/activemq start
      Check if your policy is working by using the activemq script to consume sample messages:
      ./bin/activemq consumer --user admin --password password

      This should work, because the formerly created policy class allowes user admin to consume the messages. In addition to that it should not be possible to consume messages with other users than user admin. You can test it by using another user:
      ./bin/activemq consumer --user consumer --password password

      This consumer should not consume any single message.

      If you have questions, want my source code, a youtube video or something like that, just leave a comment or get in contact with me via twitter. Have fun with ActiveMQ!



      How to secure Message Queues in Apache ActiveMQ

      Securing Apache ActiveMQ is not that hard as it looks at first glance. Luckily it comes with lots of powerful tools especially for security configurations.
      This time I didn't want to write lots of text, therefore there is a youtube video embedded, which shows how I secured the Message Queues of a vanilla ActiveMQ.

      If you have questions, just leave a comment or get in contact with me at twitter.



      Running Apache ActiveMQ and hawtio in Standalone Mode

      Apache ActiveMQ is my first choice every time a Message Queue is needed to solve my integration problems.
      Unfortunately the ActiveMQ Web Console is not that comfortable, so I decided to add the Red Hat JBoss project hawtio to my standalone ActiveMQ environment.
      Hawtio is a modular web console for managing Java stuff. It has nice dashboards, wiki and lots of plugins for logs, health, JMX, OSGi, Apache ActiveMQ, Apache Camel, Apache OpenEJB, Apache Tomcat, Jetty, JBoss and Fuse Fabric.

      Currently there are just a few tutorials out there which explain how to add hawtio to a standalone ActiveMQ installation. Unfortunately these tutorials are outdated and misleading. Therefore I am writing this tutorial. You can see it as an update of existing tutorials.
      There are two ways to get your standalone ActiveMQ up and running with hawtio. You can either follow the following steps or take a look at my GitHub repository which contains a running version of ActiveMQ and hawtio. You can find it here.

      Getting Started
      1. Download the latest version of ActiveMQ (download)
      2. Download hawtio offline .war file (download)
      3. Unzip the formerly downloaded activemq folder
      4. Unzip the .war file
      5. Rename the folder to just "hawtio"
      6. Copy it in the unzipped activemq/webapps folder
      7. To override the hawtio auth defaults, open the env script which is located in the bin folder in your activemq folder.
      8. Search for "ACTIVEMQ_OPTS" and add these three properties: -Dhawtio.realm=activemq -Dhawtio.role=admins -Dhawtio.rolePrincipalClasses=org.apache.activemq.jaas.GroupPrincipal
      After these steps, you can access the hawtio web console via http://localhost:8161/hawtio and login with admin/admin. The hawtio web console looks like:
      As you can see, the hawtio is a really nice addon and much more comfortable than the standard ActiveMQ console. Give it a try! Have fun with ActiveMQ and hawtio!



      Review: ActiveMQ in Action

      Some days ago I got in contact with IoT and MQTT with the great MQTT.fx tool developed by Jens Deters (@jerady) and I wanted to deepen my knowledge about Message Brokers/Message-oriented Middleware, so I bought this book about Apache ActiveMQ.


      Applications in enterprises need to communicate, most commonly done by messaging.
      Apache ActiveMQ is an open-source implementation of the Java Message Service (JMS), which provides messaging in Java applications.
      ActiveMQ in Action is a thorough, practical guide to implementing message-oriented systems using ActiveMQ and Java. Co-authored by one of the leading ActiveMQ developers, Bruce Snyder, the book starts with the anatomy of a core Java message, then moves quickly through fundamentals including data persistence, authentication and authorization. Later chapters cover advanced features such as configuration and performance tuning, illustrating each concept with a running real-world stock portfolio application.
      Readers will learn to integrate ActiveMQ with Apache Geronimo and JBoss, and tie into both Java and non-Java technologies including AJAX, .NET, C++, Ruby, and the Spring framework.

      Product Details

      Paperback: 375 pages
      Publisher: Manning Publications; 1 edition (March 28, 2011)
      Language: English
      ISBN-10: 9781933988948
      ISBN-13: 978-1933988948

      The Authors

      Bruce Snyder (@brucesnyder) is a veteran of enterprise software development and a recognizedleader in open source software. Bruce has experience in a wide range of technolo-gies including Java EE, Enterprise Messaging and Service Oriented Integration. In addition to his role as a software consultant, Bruce is also an Apache Member, a co-founder of Apache Geronimo and a developer for Apache ActiveMQ, Camel, and ServiceMix.
      Dejan Bosanac (@dejanb) is a software developer, technology consultant and author with deep expertise in integration and interoperability of Java and web technologies. Dejan spent a number of years in development of complex software projects, ranging from highly-trafficked web sites through enterprise applications.
      Rob Davies (@rajdavies) has over 20 years experience of developing high performance distributed enterprise systems and products for telcos and finance. He is a founder of theApache ActiveMQ, Apache ServiceMix, and Apache Camel projects. CurrentlyDirector of Open Source Development at IONA, Rob was also a founder and CTO of SpiritSoft and founder and VP Product Development at LogicBlaze.

      The Content

      This books covers all you need to know about ActiveMQ in different scenarios. It starts with introductions to Apache ActiveMQ and gives an understanding of message-oriented middleware and JMS.
      After that this book shows basic topics like how to connect to ActiveMQ, Storing messages, securing ActiveMQ and integrations to Java and Java EE applications. In the advanced parts it is about deployments, performance tuning, administration and so on.

      Writing and Style

      If you are used to technical documentation you shouldn't struggle with this book. For a non native speaker it reads very easy. I didn't find very many complex sentences which were too complex for non natives.

      Conclusion and Recommendation

      If you have some knowledge of Java, this book offers all you need to master ActiveMQ from the beginning to advanced topics.
      I really enjoyed reading this book and it will take a place as reference book on my desk.

      If you are interested in Message Brokers and Message oriented Middleware solutions and want a book which covers everything from configuration over performance tuning to administration and monitoring of ActiveMQ, this is a must read!


      JavaFX - Upgrading from TestFX 3 to TestFX 4

      With TestFX 4 there are some things in comparison to release 3.1.2 which need to be changed when migrating to release 4.0.
      I had some problems with the migration because I didn't find enough examples and my IDE suggested either no or the completely wrong imports for the methods like e.g. Matchers. I also found some erroneous examples of using TestFX 4. Some examples are using hamcrest matchers like assertThat("#loginButton", ...) which erroneously could result in lots of green bars, because these Matchers won't search the component with fx:id #loginButton. They are treating the first argument as String instead. Therefore: Take care of your imports in TestFX!
      This post shows this parts and gives an overview of what has to be changed when planning a migration to the newest version. 

      First the dependency has changed from:


      to two dependencies. The single TestFX dependency has been splitted in the core part of TestFX and the JUnit AddOn:


      After that your test won't compile. You have to search and replace the Test class:
      extends GuiTest becomes: extends ApplicationTest which is in package: org.testfx.framework.junit.
      The overridden getRootNode() method has to be removed and its contained code has to be moved to the new start() method.

      The last step is to change the methods used in the test. In comparison to the TestFX releases of 3.x there areother methods to interact with JavaFX components like Buttons, TextFields etc.
      In the former releases all these methods like find() and verifyThat() where part of the extended GuiTest method. In release 4 this has changed.

      Operations on Components like clickOn() or drag() are in class: org.testfx.api.FxRobot
      Matchers like isNotNull() or isDisabled() can be found in: org.testfx.matcher.base
      Asserts can be found in class: org.testfx.api.FxAssert

       Take care of your imports and have fun with the newest version of TestFX :-)



      Dependency Injection in JavaFX with Gluon Ignite and Dagger

      The Dependency Injection abstraction framework Gluon Ignite creates a common abstraction over several popular dependency injection frameworks like: Spring, Dagger and Guice.
      Currently the Gluon page only contains an example which uses Gluon Ignite with Google Guice as Dependency Injection Framework and I wanted to try Dagger instead of it, because it aims to be more minimalistic and faster than other Dependency Injection Frameworks which is very interesting for less powerful devices like mobile and embedded. In addition to that it's invented by the developers of Google Guice, but with less ways of doing injection stuff.

      In the first step you have to add the dagger dependency to your maven pom (or gradle build file):

      After that perform a mvn clean and install or do a rightclick and choose: "reload pom" and "clean and build". Now you can start with integrating it into your JavaFX main application by creating a new field:

      The DaggerContext classes comes with the form previously added maven dependency. Its instantiation takes the JavaFX Main class (this) as first argument and a DaggerModule as the second one. This Module has to be created by hand:

      When creating DaggerModules the Module class has to be annotated with the @Module annotation and it also has to inject the JavaFX Main class which is MainApp.class in this example.
      In case you want to inject FXMLLoader object as well, you have to create a method annotated with @Provices which returns the FXMLLoader instance.
      In case of injecting other objects there are two ways to inject them. Either you can add additional provides methods to the dagger module like for example:

      Or you can create a standard no-argument Constructor in the SampleController class which is annotated with @Inject like:

      If you don't implement one of this steps, the JavaFX Main class won't compile, because Dagger uses generated code to inject the respective classes instead of a heavily usage of reflection like other Dependency Frameworks do.

      Links and Further Reading
      Gluon Ignite offers a really nice way to integrate different Dependency Frameworks in JavaFX applications. In addition to that it's really easy to change the respective DI by using Gluon Ignite. Give it a try!



      MVC 1.0 in Java EE 8 - Redirects and Forwards

      This blogpost of my MVC 1.0 series is about Redirects and Forwards. Since the 2nd early draft redirects became a new feature in MVC.
      This post starts with the popular Post-Redirect-Get Pattern, handles redirets with JAX-RS and MVC and compares Redirects with Forwards briefly.

      The Post-Redirect-Get Pattern

      The Post-Redirect-Post pattern is a popular pattern in web applications. It splits one request into two. Instead of returning a result page immediately in response to POST request, the server responds with redirect to result page. After that the browser loads the result page as if it were an separate resource. After all, there are two different tasks to be done. First is to POST input data to the server. Second is to GET output to the client.

      When using MVC there are two different different ways to handle the Post-Redirect-Get Pattern. Redirects can be handled either with JAX-RS or even with MVC, which comes with an own mechanism for redirects.

      Redirects with JAX-RS

      Because of the integration with JAX-RS it is possible to redirect to URLs the JAX-RS way. This means a redirect can be done by using a JAX-RS Response object as return value of the controller method which redirects. Behind the scenes it's a HTTP 303 "See Other".

      This is the first way to handle redirects. Like it is visible, it is not very concise. A more compact way for handling redirects comes with MVC which is described in the following section.

      Redirects with MVC

      Since the 2nd early draft of MVC there is a new way to handle redirects. This way is more concise in comparison to the JAX-RS redirect.
      When using the MVC redirect way, view paths have to be prefixed with "redirect:" to trigger a client redirect. This means the Post method needs a return type of String to perform a redirect.

      In the previous illustration there is a post method which will be called first. This post method has a String return type and return a path to another url prefixed with "redirect:" to signalize a redirect.
      In addition to that with MVC there is a new annotation. It's named @RedirectScoped and fits between the RequestScoped and the ApplicationScoped one. A RedirectScoped annotated bean spans at most two requests.
      The following illustration shows the bean used in the previous post and get methods:

      Like described before the bean has to be annotated with @RedirectScoped to span more than one and at least two requests. In addition to that it has to be Serializable. That's all.

      Currently redirects have to be implemented with new CDI beans. The javax.mvc.Models map is RequestScoped, so it can not be used to store data over two requests. In the mailing list there is a discussion about the scope of the Models map.

      Redirects vs. Forwards

      With the 3rd early draft there will be a forward prefix. In comparison to redirects, forwards don't result in a response to the client. Forwards are "server internal". The forward routes to another controller url within the server with just a single request instead of two. Another difference is that the browser won't show the redirected url when using forwards. With forwards the url stays the same from the beginning post request till the end of the get request.


      With MVC 1.0 there will be two different ways to support the Post-Redirect-Get pattern. Redirects can either be handled with JAX-RS Response objects or even with the new MVC 1.0 "redirect:" prefix for controller methods.
      There will also be a way to forward to other urls. In comparison to redirects forwards stay on the server and only need a single request instead of two like redirects do. When using redirects the url changes from post to get an with forwards the url stays the same.

      I hope you are enyoing my blog series about MVC 1.0 in Java EE 8. If there are some topics which would like to see, please leave a comment :-)



      MVC 1.0 in Java EE 8 - Handling Form Validation Errors

      This blogpost of my MVC 1.0 series is a about Handling Form Validation Errors. It uses the snippets from the last post where handling form inputs in general is explained. In addition to that, this post adds form validation and its handling on top of the handling form inputs post.

      Handling Form Input 

      There are two ways to handle form inputs in MVC controllers. The simplest way is to use @FormParam annotation map the form input to MVC controller method parameters. The second one is to aggregate multiple with @FormParam annotated parameters as a single object.
      This case is shown in the following snippet:
      The Person parameter of this addOwner method is a simple Java Pojo with two @FormParam annotations. The Strings within these annotations have to match with the HTML input form.

       Adding Validations

      Because of the Bean Validation integration in MVC, adding form validations to input fields is pretty easy. In this concrete example the Person class has to be annotated with the prefered validation. In the following snippet a check for non-empty input fields is added.

      Validation annotations like @Size, @NotNull and so on can either be added to the respective properties or even parameters.
      In case you need validations different from the standard javax.validation ones you should take a look at Hibernate Validator by Red Hat which is available here.

      Note: Empty input fields result in empty String parameters and not in nullvalued parameters.

      After adding validation annotations to the Person input class, the controller and the addOwner() controller method have to be changed.
      The first step is to inject the javax.mvc.binding.BindingResult class as a property in the controller class.
      The second step is to add error handling to the controller method. This can be done by using the injected BindingResult reference.

      Handling validation errors has to be done with an if-condition which checks if the BindingResult contains errors by calling the isFailed() method. If a property (for example the firstname) is empty the BindingResult reference contains the corresponding errors, messages and so on. These properties can be used to fill an error bean and redirect to an error page for example.


      Handling form validations in MVC 1.0 is pretty simple. The respective properties have to be annotated with validation annotations. In addition to that the controller which handles the form input and the possible errors needs to contain an injected BindingResult reference which has to be used to handle validation errors.


      About Me

      My photo

      Bennet is working as a Software Developer with focus on Java Enterprise Edition. In his free time he is involved in different Java User Group activities, member of JavaLand commitees and blogging about different Java topics.

      Popular Posts

      Proud to be member of

      JUG Hamburg

      Powered by Blogger.