Wednesday, March 29, 2017

Testing the Java EE 8 Specifications

The Java EE 8 Platform has definitely been moving along within the past couple of months.  Specifications have been releasing early draft reviews, milestones, and even final releases.  As a matter of fact, JSR-372 has just gone final, as JSF 2.3 has been released.  For more information, please see Arjan's Post.  It had the privilege to be a part of the JSR-372 expert group, and I really appreciate the opportunity to work with these experts on a specification that I use every day.

I created a Github Project entitled the Java EE 8 Playground, and it includes a Java EE application that contains a number of the latest updates to those specifications that will be part of the Java EE 8 release.  I will make an effort to update this project often so that it includes current dependencies for the specifications.  I will also try to add demos for the specifications so that it will be easy to build upon the examples.  In the current project, some of the JSF 2.3 features are used.

It is important that as a community we test and provide feedback for the Java EE 8 specifications as they are being developed.  It is in these stages that you have a voice that can make a change to an upcoming specification.  Please test, read the latest specification documents, and provide feedback to the respective JSRs.

Java EE 8 Playground Project:

Java EE 8 JSRs:

JSR 365 (CDI 2.0):
JSR 366 (Java EE 8):
JSR 367 (JSON Binding):
JSR 369 (Servlet 4.0):
JSR 370 (JAX-RS 2.1):
JSR 372 (JSF 2.3 - FINAL):
JSR 374 (JSON  Processing 1.1):
JSR 375 (Java EE Security 1.0):
JSR 380 (Bean Validation 2.0):

JSR 371 (MVC - No longer officially part of Java EE 8):

Saturday, March 04, 2017

JSR 365 Update: Digging Into CDI 2.0

Contexts and Dependency Injection 2.0 (JSR 365), is an update to CDI 1.2, which is currently part of the Java EE 7 platform.  It is currently in Public Review stage.  For those of you who are not very familiar with CDI, it defines a powerful set of complimentary services that act as a gel that help to improve the coordination and structure of application code.  For more details, please visit the specification page.

CDI 2.0 expands the usability of the Contexts and Dependency Injection services to Java SE as well, as it will now target both the Java SE and Java EE platforms.  The CDI specification has been organized into 3 parts, Part I - Core CDI, Part II - CDI in Java SE, and Part III - CDI in Java EE.  The major changes for CDI 2.0 are as follows:

  • Better alignment with Java SE 8
  • API for booting CDI within a Java SE application
  • Ability to provide observer ordering
  • Ability to fire asynchronous events
  • New Configurators Interfaces for Service Provider Interface (SPI) elements
  • Ability to configure or veto an observer method in ProcessObserverEvent event
  • Support for inline instantiation of specific annotation types
  • Addition of the InterceptionFactory interface,  which allows to create a wrapper instance whose method invocations are intercepted by method interceptors and forwarded to a provided instance.
I encourage you to take a look at the CDI 2.0 Public Review Draft for more details on the specifics of each enhancement listed, as well as a complete listing of new features.  Read through the draft and provide feedback to the expert group.  All of the pertinent details for providing feedback can be found on the JSR 365 page.  To get started testing, create a new maven based Java EE application in your favorite IDE, and add the following dependencies:


In this post, we will dig into one of the new features to get you started working with the API.  Let's take a look at asynchronous events.  Until CDI 2.0,  events could only be fired in a synchronous manner.  They've been enhanced in this latest iteration for asynchronous processing.  Here's how it works:

Create an event of some type.  Next, fire the event in an asynchronous manner, and handle accordingly once the event is complete.  In this example, I have created a MovieEvent class, which will be utilized whenever a persist event occurs for a Movie object.  The MovieEvent class is as follows:

public class MovieEvent {
    private String message;
    private Movie movie;
    public MovieEvent(String message, Movie movie){
        this.message = message; = movie;
    public String getMessage(){
        return this.message;
    public void setMessage(String message){
        this.message = message;
    public Movie getMovie(){
    public void setMovie(Movie movie){ = movie;

In the following scenario, we are firing an event when a new Movie is persisted.  The following code resides within a MovieController CDI bean of an example JSF application:

public class MovieController implements Serializable {

    private com.mycompany.cditest.session.MovieFacade ejbFacade;
    private List items = null;
    private Movie selected;
    Event<MovieEvent> movieEvents;
. . .
   private void persist(PersistAction persistAction, String successMessage) {
        if (selected != null) {
            try {
                if (persistAction != PersistAction.DELETE) {
                    movieEvents.fireAsync(new MovieEvent("New Movie Released", selected))
                            .whenComplete((event, throwable) -> {
                                if(throwable != null){
                                    System.out.println("Error has occurred: " + throwable.getMessage());
                                } else {
                                    System.out.println("Successful Movie Processing...");
                } else {
            } catch (Exception ex) {
                Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
                JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
. . .

When the event is fired, it creates a new MovieEvent object, and if it successfully completes then a message is printed to indicate success.  In this example, a stream is used to process the "whenComplete" action.

Feel free to clone the repository located at and take CDI 2.0 test for a spin.  This example is just one simple test of CDI 2.0.  You can clone and utilize this test project as a starting point to work with other aspects of the specification.  Keep an eye on JSR 365, which is currently in the Public Review Ballot stages.

Wednesday, September 28, 2016

JavaOne 2016 Follow-Up

I had the pleasure of attending JavaOne this year, and I can sum up the experience in one word:  Brilliant.  This year was much different than in years past for me, as I had one talk to co-present on Sunday and I had the rest of the week wide open for attending sessions.  As such, I've learned that it really is nice to have a lighter schedule at JavaOne so that you can take in all of the expertise and networking...that is what JavaOne is all about...learning from the experts and growing your network.  I also had my lovely wife along with for part of this trip, which made my stay in San Francisco very nice, as I finally took a few minutes to enjoy the city this year...never had done that in the past.

My conference experience started off with the excellent NetBeans party on Saturday evening.  I am a member of the NetBeans Dream Team, so many of my colleagues were in attendance at this party.  It was the first time I had seen many old friends, and it was great to have a chance to catch up without needing to worry about rushing to the next session.  I want to thank Geertjan Wielenga and Oracle for hosting this excellent event, and I cannot wait until the next Apache NetBeans party.

On Sunday at NetBeans Day, I had the pleasure of presenting "Enterprise Modeling of MVC and Java EE Artifacts" with experts Ivar Grimstad and Gaurav Gupta.  Ivar is on the expert group for JSR 371 (MVC 1.0)...which we hope to move forward for use with Java EE 8.  Gaurav is the lead developer for the excellent JPA Modeler tool.  During our session, Ivar gave an overview of MVC 1.0, Gaurav highlighted the JPA Modeler utility, and I demonstrated how the JPA Modeler could be utilized with JSF applications, as well as MVC 1.0.  I want to thank Geertjan again for getting the three of us together for this excellent talk.

The opening keynote was amazing.  A large portion was devoted to showing how the world is using Java, including the outstanding Mars rover presentation by Dr. Anita Sengupta (@Doctor_Astro).  It was amazing to see the complexity and detail that went into ensuring the Curiosity rover landed without issues.  Of course, Java 9 was mentioned, along with a demo of modularity and the jshell by Mark Reinhold...very informative, as always.

During the opening keynote, I anxiously awaited word on the status of Java EE, and after quite a long wait, the announcement was made.  I am very excited that Java EE 8 efforts are moving forward, albeit a bit differently than previously planned.  Essentially most of the specifications for Java EE 8 is moving forward, and it is proposed that the following be removed so that resources can spend time in other areas: JSR 371 (MVC 1.0) and JSR 368 (JMS 2.1), JSR 373 (Management 2.0).  I will cover my thoughts on these proposed dropped specifications in a follow-up post.  The main focus for Java EE 8 will be to start paving the path for a more micoservices focused platform, whereby Java EE 9 will be released a year later and it will include the full microservices implementation.  The addition of Health Checking and Configuration specifications would be beneficial for providing a standard means by which to monitor services and dynamically configure our applications.  Overall, it is great to see things moving forward for Java EE, although I do have some reservations on the overall approach.  I do not believe that every industry will adopt the microservices architecture, so there needs to be a path for those who will be continuing with the standard Java EE application architecture.

Rather than going through detail on each of the sessions that I had attended, I will provide a summary of my thoughts on the conference overall.  As I have said many times before, time is not our friend...and this certainly was the case this year at JavaOne, as there were too many great tutorials, sessions, and networking events that it was difficult to see everything.  Hats off to Sharat Chander and others at Oracle for organizing such a great conference.  I also want to thank the content review committees for reviewing and choosing such great conference tutorials and sessions...the content was excellent!

The tutorials and hands-on labs dealing with Microservices were hot this year.  I attended two of them myself.  One of them was a hands on lab that enabled us to develop Microservices using JBoss Forge and WildFly Swarm.  It was a fast pace tutorial covering everything from setting up Eclipse (unfortunately not my favorite IDE), through utilizing Forge, constructing services, and deployment.  I am glad I attended, as it gave me a different perspective on development from what I am used to.  The second was a tutorial on utilizing Payara Micro and the Payara MicroProfile.  I found this tutorial very in-depth, covering these technologies from the ground-up, with lots of detailed explanation.  I learned it is quite easy to add the Payara Microprofile to a project, simply by including the dependency in the POM:


Deploying is as simple as:

java -jar payara-microprofile-1.0.jar --deploy test-app.war 

I attended many key Java EE sessions, including those given by Linda DeMichiel and others leading the specifications.  All of these were informative, covering content from previous Java EE incarnations through what to expect in Java EE 8.  Linda's presentation on Monday went into a bit more detail on the plans for Java EE 8, and it is clear to see that Oracle is "all in" on moving forward with the newly proposed plan for Java EE 8...which is great!  Each of the specification-specific talks that I attended were excellent, including CDI 2.0,  JAX-RS 2.1, and JSF 2.3.  Great to hear from the experts for these areas.  I also took in a couple of other key talks:  Java EE Extendable to Functional by David Blevins, and 50 Java EE Best Practices by Ryan Cuprak and Michael Remijan...both great!

There were a lot of sessions on Java 9 and modularity this year.  I attended a session on modularity, which was a great introduction for those hadn't yet had a chance to experiment with it.  Docker was another hot topic at the conference, and I had the opportunity to attend a couple of sessions covering this great tech.

I had the privilege to attend the JCP Party on Monday evening.  Always an excellent opportunity to network with others in the JCP, and this year's event did not let us down.  The Chicago Java Users Group (CJUG), Bob Paulin, and myself won an award at the JCP Party on Monday evening for Adopt-a-JSR participants of the year.  This was a very nice surprise!  I also attended PartyOne, hosted by Tomitribe, ZeroTurnaround, BainCapital, and Hazelcast.  This was a great opportunity to network with so many experts...and there was also a great view of the Bay Bridge off the balcony.  I want to thank Tomitribe for the invitation!  Lastly, I attended the Oracle Appreciation Event, which was very nice.  The Oracle OpenWorld and JavaOne attendees had AT&T Park to themselves, and we got to see Sting and Gwen Stefani.  Great networking opportunity with many great friends.

Overall, JavaOne 2016 was another great conference...very glad to have been a part of it.  If you have not done so already, please take the Java EE Survey and provide your thoughts on the upcoming Java EE 8 proposal:

Thursday, September 15, 2016

NetBeans Java EE 8 MVC Plugin Enhancements

A while back, Geertjan Wielenga had posted about a NetBeans plugin that had been developed for the upcoming Java EE 8 MVC framework.  The plugin was originally developed by Manfred Riem, co-spec lead for JSR 371, and Geertjan had extended it to add functionality for viewing all of the MVC controllers within an application.  This plugin is a great start to a useful MVC plugin for NetBeans.

I've since taken the plugin and extended it further, adding the following enhancements:

  • NetBeans workspace now scanned to apply plugin only to those projects that contain MVC controller classes.
  • Ability to create a new MVC application which includes a basic controller class and corresponding view.
  • Ability to add new MVC controller class to a project.

Come and check out the new plugin functionality at JavaOne.  I have the honor of presenting along with Ivar Grimstad (JSR 371 Expert Group) and Gaurav Gupta (JPA Modeler) in the presentation UGF6435 -- Enterprise Modeling of MVC and Java EE Artifacts for NetBeans Day 2016.  I'll demo the plugin during the session, alongside the powerful JPA Modeler utility.  

Hope to see you there!

Friday, July 15, 2016

NetBeans 8.2 Profiler: Colored Results

One of the new features in NetBeans 8.2 is the ability to color profiler results differently based upon filters.  This can make things visually stand out, and easier to follow in the profiler output.

To enable colored profiler results, go into the NetBeans "Preferences"->"Java"->"Profiler" menu, as seen in Figure 1.  Check the box to "Use defined filters for coloring results".

Figure 1:  NetBeans Profiler Colored Filter Results

Add any filter(s) you wish, and assign a color to the results of those filters (Figure 2).  If you wish to display the output from one of the existing filters in a different color, click the tool icon and change the colors.  As you can see in the previous figure, I updated the Java EE Frameworks filter to be a green color.

Figure 2:  Assign Colors to Filters

After applying the colors to the filters, run the profiler and see the results!

Figure 3:  Colored Results!

Saturday, June 11, 2016

Help Move Java EE Forward

If you recall my post entitled Java EE 8:  What is the Current Status, it is apparent that the progression on Java EE has certainly slowed down over the past several months.  There are definitely some JSRs under the Java EE umbrella that have more activity than others, but Java EE as a whole has seen little to no movement forward since JavaOne 2015.  This is not something to be taken lightly by anyone in the IT industry.  Java EE is a critical part of the industry, as there are thousands of web applications that have been built using the Java EE stack.  There are probably even more applications that have not been built using the full Java EE stack, but still rely upon some of the Java EE technologies..such as the Java Persistence API (JPA) or Java Message Service (JMS).

Why is it so important to move things forward?  Why not just leave things how they are and let Java EE fade away?  Plainly put, these technologies need to move forward in order to remain secure and make use of the current API technologies of today.  If one wishes to simply let Java EE stagnate, that means that all of the applications and services utilizing all or part of Java EE (much of the internet as we know it) are also stagnating, and cannot be moved forward to stay current with today's technology and security concerns.

What can we do to try and help?  Move Java EE forward via the community.  If you have a few moments to spare, help move Java EE forward by sharing your expertise and contributing to one or more of the Java EE JSRs.  This can be done by joining the JCP (Java Community Process) and beginning to work on the code.  Work can be categorized in a number of can test existing code, document, debug, repair issues, or even develop features and enhancements for a Java EE 8 JSR.  Become a part of your local JUG and give a talk on Java EE 8, or get your JUG involved via the Adopt-a-JSR program and work with the JCP to help make improvements towards the Java EE 8 effort!

What can you do right now?  Sign the petition that has been proposed by the Java EE Guardians group to try and persuade Oracle to begin working on Java EE 8, once again.  The Java EE Guardians are a group of individuals/JUGs that are actively involved in trying to vocalize the current status of Java EE 8, in an effort to get the community involved and to make Oracle hear or opinion.  In the end, if Oracle is not interested putting forth effort internally and moving Java EE forward, hopefully they will be open to working more with the community, and hand off some of the specifications to those who are interested.

Thanks for reading the post...your time and participation is certainly appreciated!

Tuesday, May 31, 2016

NetBeans Java EE Tip #9: Create JSF Application from Database

Do you need to create an database front-end very quickly?  The NetBeans IDE allows one to develop a JSF application front end for a set of database tables very quickly, and with very little coding.  Now this tutorial is an oldie, but a goodie...and it is worth mentioning again for those who are not aware of it.

First, create your application.  In this case, I create a Maven Web Application by choosing "New Project"->"Maven"->"Web Application" (Figure 1).

Figure 1:  Maven Web Application

Next, I provide the web application name of JsfCustomers since I'll be making use of the CUSTOMERS sample database tables.  Once the application project is created, create a new Java package to hold the entity classes for the database.  In this case, I right-click on the project's "Source Packages" and select "New"->"Java Package...", and then name it org.jsf.jsfcustomers.entity  (Figure 2).

Figure 2:  New Java Package

After the package is created, right-click on it and select "New"->"Entity Classes from Database", which I've covered in a previous posting.  This wizard allows me to select a set of database tables from one of my I choose my sample database and select the CUSTOMER table.  After doing so, all related database tables are automatically added to the "Selected Tables" next (Figure 3).
Figure 3:  Create Entity Classes from Database

The next wizard page (Figure 4) allows me to select various options for generating my entity classes...I'll leave the defaults and click "Finish".
Figure 4:  Entity Class Options

After doing so, the entity classes for my database have been generated.  Now it is time to put the icing on the cake.  Since the database entity classes are now available, I can generate the entire JavaServer Faces infrastructure with just a few clicks.  Right click on the project's "Web Pages" folder and select "New"->"JavaServer Pages"->"JSF Pages from Entity Classes" (Figure 5).

Figure 5:  Create JSF Pages from Entity Classes

Next, select all of the entity classes that have been created, and click "Next" (Figure 6).

Figure 6:  Select Entity Classes

Lastly, specify options for creating your JSF classes and pages.  First, I specify a good name for my EJB session bean and JSF Controller packages.  The EJBs and controllers will be automatically generated into these locations.  Next, select the web folder where the JSF pages should be generated...leave blank for the root.  Lastly, I chose to utilize the PrimeFaces pages template to make use of PrimeFaces components.  Click next and choose the JSF configuration that has been previously registered with the IDE (Figure 7). "Finish" and see the magic...the web application and all of the JavaServer Faces infrastructure is generated automatically (Figure 8).

Figure 7:  JavaServer Faces Configuration

Figure 8:  Completed JSF Application

Note that you may need to right-click on your project "Dependencies" module and add PrimeFaces (Figure 9).

Figure 9:  Add Maven Dependency

Now build and run your application...and it is ready to use!