Friday Apr 11, 2014

Non-blocking I/Os in Servlet 3.1

With the advent of platforms and frameworks such as Node.js, Vert.x, ... and more generally the rise of the Event-driven programming paradigm, asynchronous non-blocking I/Os are becoming more and more important in today's web applications.

Prior to Servlet 3.0, Servlet were synchronous. Servlet 3.0 (part of Java EE 6) added support for asynchronous request processing but only with ‘traditional’ I/Os (i.e. blocking I/Os) but this approach can sometime limit the scalability of an application.

The support for non-blocking I/Os has been added for Asynchronous Servlet in Servlet 3.1 (JSR 340 - part of Java EE 7). The net result is that the number of connections that can simultaneously be handled by the Servlet Container is greatly increased. This improves the resources utilization and the overall Web Container scalability.

It should be mentioned that other features haven added to the Servlet 3.1 such as support for the HTTP 1.1 Upgrade Mechanism. This new capability is used, for example, by the WebSocket API (JSR 356) to upgrade an existing HTTP connection to a TCP based WebSocket connection. In Servlet 3.1, the HTTP Upgrade Mechanism can also use non-blocking I/Os.

This article and this JavaOne session explains how asynchronous non-blocking I/Os in Servlet 3.1 The JavaOne session also covers the HTTP Upgrade mechanism and the other additions to the Servlet 3.1 API (various security enhancements and other miscellaneous features).

Wednesday Apr 09, 2014

Method Validation in Bean Validation 1.1

Although it's a point release Bean Validation 1.1 brings a number of important features to Java EE 7. Easily the most important such feature is method validation. Beyond helping enforce design-by-contract in key service layer API classes (typically implemented in EJB3 or CDI) method validation plays an important role in helping ensure valid input to remote client endpoins written in JAX-RS and WebSocket. Hardy Ferentschik of the JBoss community explains the feature well. There's also the 15-minute Bean Validation 1.1 presentation by specification lead Emmanuel Bernard on the GlassFish videos YouTube channel as well the slide deck for my own lighting talk:

If you are interested in how method validation might be used in a realistic scenario with JAX-RS and WebSocket, feel free to dig into my example application on GitHub demostrating how Java EE 7 can be used with JavaScript MV* frameworks (in this case AngularJS).

Tuesday Apr 08, 2014

New book: EJB 3 in Action, Second Edition

'EJB3 in Action' is one of the reference books when it comes to this important area of Java EE. The second edition covering EJB 3.2 has just been published.

Over the years, the EJB specification has come a long way and has been greatly simplified but nevertheless EJB is still a large specification to grasp. This book is a great (and up-to-date!) introduction to the EJB Component Model. The book goes beyond just introducing EJBs in details as it also explains technologies related to EJB such as CDI and JPA (the older amongst us will remember that EJB, back in the days, used to also handle persistence). The book has also a full chapter devoted to WebSocket, a new important Java EE 7 technology. The final chapter of the book is devoted to a critical, some time over looked, topics: testing.

This is not a pure theoretical book as it really gives 2 views, it first introduce and explains EJBs but also JPA, CDI, etc. The book then explain how to use EJBs and the other technologies, how to put them in action! All in all, a great book to add to any Java EE 7 bookshelf!

Disclaimer: 'EJB 3 in Action' was co-authored by our own Reza Rahman. But to be honest, I was already praising the first edition of the book when Reza wasn't yet working for Oracle.

Wednesday Apr 02, 2014

The Java EE 7 Story Infographic + Poster

Sometimes it's easy to lose sight of just how much work is put into a Java EE release and how many people are involved - even for folks like me that have been involved with the platform for a good number of years. The numbers are staggering and awe inspiring at the same time, particularly for Java EE 7. Java EE 7 had 4 new JSRs, 14 new or updated JSRs, 16 spec leads, 32 companies contributing and 187 expert group members involved (many of them independents like most of you). 19 Java user groups worldwide worked on one or more JSRs through the Adopt-a-JSR program. About 1,100 developers participated in the survey to finalize the contents of Java EE 7. From inception to final delivery EE 7 took 42 months - a long journey (the longest for any Java EE specification). In terms of the total number of changes, EE 7 is easily the most significant release of the platform to date. The goal was to produce a Java EE version that remains the core of modern day web and enterprise applications in a sea of changes in the ecosystem while simultaneously trying to make sure it is something developers are excited about and eager to learn/use.

The infographic below encapsulates the story of Java EE 7 (click here to download and view the actual PDF):

It appears your Web browser is not configured to display PDF files. No worries, just click here to download the PDF file.

We actually have a few copies of the infographic printed as nice high quality 20 X 10 posters to give away to you (don't worry, there's enough for at least one per person that filled out the Java EE 7 survey :-)). It makes for a nice geeky conversation piece at the office (I have one that I am looking at right now in my home office). You can pick one up from me if you come to any of my talks, especially on the venerable NFJS tours. I am very proud to have recently joined the all-star NFJS cast of characters as a way to better engage with the US Java community. In fact my first stop is very local - NFJS NY this Friday and Saturday, with a full menu of Java EE topics. Hopefully I'll see you on the tour at some point?

It's fair to say Java EE 7 was more community driven than any other release of the platform ever. We hope to top that with Java EE 8, starting with the community survey that we just published the results for - with your help and through excellent avenues like the JCP,, the GlassFish code base, Java EE Blue Prints and Adopt-a-JSR not to mention the numerous events that our team attends Worldwide throughout the year.

Friday Mar 21, 2014

Code PaLOUsa 2014 Trip Report

Code PaLOUsa 2014 took place 24-26 February in Louisville, Kentucky. Code PaLOUsa is a fairly unassuming conference with great quality farther away from the beaten paths. Topics covered included Java, .NET, JavaScript, mobile, methodology and Big Data/NoSQL. On my way to Kentucky, I was able to stop by at the Montgomery County (Maryland) JUG for a Java EE 7 session.

At Code PaLOUsa I delivered a talk on aligning Java EE with NoSQL as well as a talk on the Cargo Tracker Java EE/Domain-Driven Design Blue Prints project (this talk was recorded by InfoQ). More details, including slide decks and code, posted on my personal blog.

Monday Mar 17, 2014

The JAX-RS 2 Client API by Example

The brand new client API is one of the most significant features introduced in JAX-RS 2/Java EE 7. The API has many uses such as unit/integration testing, system-to-system/M2M communication, Java SE/AWT/Swing/JavaFX REST clients and so on. Indeed you can think of the JAX-RS 2 client API as a general purpose replacement to for any HTTP communication. In an excellent recent blog post, Micha Kop introduces the major features of the JAX-RS 2 client API in an example driven fashion. He demonstrates doing a basic POST/GET/DELETE request, JSON support, resolving path parameters, asynchronous processing, invocation callbacks, delayed invocation, filters and much more (all with running examples included!). JAX-RS 2 specification leads Santiago Pericas-Geertsen and Marek Potociar also spent a great deal of time on the client API during their JavaOne 2013 talk (video embedded below).

The official Java EE 7 tutorial also has a great section on the JAX-RS 2 client API, as does the docs for the Jersey JAX-RS 2 reference implementation.

Friday Mar 14, 2014

Jfokus 2014 Trip Report

Jfokus 2014 took place 3-5 February in Stockholm, Sweden. Jfokus slates itself as the largest developer conference in Sweden and it certainly is quite significant in terms of both content quality and attendance. The event attracted a bevy of World class speakers including quite a few of my fellow Oracle colleagues - Mark Reinhold, Georges Saab, Stephen Chin, Simon Ritter, Mark Heckler, Angela Caicedo, Geertjan Wielenga (NetBeans), Heather VanCura (JCP), Cecilia Borg (OpenJDK), Joel Borggrén-Franck (JDK) and Marcus Hirt (JDK). Notable other folks speaking included Venkat Subramaniam, David Blevins, Pratik Patel, Trisha Gee, Martijn Verburg and Anton Arhipov. Topics covered included Java SE, Java EE, embedded Java, JavaScript, cloud, mobile, DevOps, agile and Big Data/NoSQL.

I delivered a half-day Java EE 7 workshop using Cargo Tracker and a talk on aligning Java EE with the JavaScript/HTML 5 ecosystem. I also participated in a BoF on the JCP, OpenJDK, Adopt-a-JSR and Java EE 8 as well as a shootout on static vs. dynamic languages. More details, including slide decks and code, posted on my personal blog.

Wednesday Mar 12, 2014

JPA 2.1 Entity Graphs

Entity Graphs are a very important but somewhat underrated enhancement in JPA 2.1/Java EE 7. The feature significantly improves the ability to load/fetch JPA data beyond the very coarse grained mechanism of traditional ORM lazy and eager loading. Applied correctly, entity graphs could significantly improve application performance in still a fairly elegant way. Hantsy Bai does an excellent job explaining the basics of JPA 2.1 entity graphs in a recent blog post. He demonstrates how to define an entity graph using annotations or programatically, using the entity graph in a simple query and the basic value proposition for entity graphs. Linda DeMichiel dedicated a good amount of time explaining entity graphs during her JavaOne 2013 talk on JPA 2.1 (video below).

The official Java EE 7 tutorial also has a pretty decent section on entity graphs. It is definitely worth your time to understand the feature well and apply it in your JPA applications.

Thursday Feb 13, 2014

CodeMash 2014 Trip Report

CodeMash 2014 took place 7-10 January in Sandusky, Ohio. With another sold-out year, CodeMash is quickly becoming one of the largest developer conferences state-side. This year it attracted a decent section of the Java crowd including me (Java EE) and my fellow Oracle colleagues Jim Weaver (JavaFX) and Scott Seighman (Java SE 8). I also stopped by at the nascent Penn State University/Happy Valley JUG in State College, PA - kicking off a highly successful and well-attended very first meetup consisting of a whole day Java EE 7 hand-on workshop!

At CodeMash I delivered talks on Java EE 7 and using NoSQL with Java EE, both of which went well. More details, including the slide deck and code, posted on my personal blog.

Friday Jan 31, 2014

JAX-RS Managed Clients in Jersey

As you probably know, JAX-RS 2/Java EE 7 now includes a brand new standard client API. If you don't know about it yet, you should check out this excellent blog entry by Mohamed Sanaulla now :-). The standard client API uses the factory/builder patterns and not injection. This makes it very well suited for Java SE based environments such as JUnit tests and JavaFX UIs. However Jersey, the JAX-RS 2 reference implemention included in GlassFish 4 goes much further by providing a managed JAX-RS client that makes full use of injection. This is ideal for server-side mash-ups and system-to-system/machine-to-machine communication.

Michal Gajdos of the Jersey team does an excellent job of explaining the API details in this code-driven blog entry. You can also check out the code on GitHub and running example on Heroku!

Wednesday Jan 29, 2014

Survey Sez: Java EE 7 Adoption Looking Pretty Good! editor Kevin Farnham is at it again - he posed yet another pretty bold opinion survey on Java EE and got some pretty surprising answers. The question this time was simple but profound - How much impact has Java EE 7 had on your work thus far?. Surprisingly, a majority of responders (55%) are already seeing Java EE 7 adoption or expect to see it soon. Keep in perspective, Java EE 7 was released June of last year - all but about half-a-year ago! Below is a rough graph representation of the results as well as the actual breakdown:

How much impact has Java EE 7 had on your work thus far?

  • 17% - Significant: I'm working with Java EE 7 on a regular basis
  • 19% - Some: I'm starting to work with Java EE 7 increasingly
  • 2% - Slight: I don't use it myself, but I work with developers who do
  • 17% - None yet, but I expect Java EE 7 will impact some of my work soon
  • 19% - None: all of my Java EE work will remain on earlier versions long into the future
  • 20% - None, because all of my work is completely unrelated to Java EE
  • 6% - Other

It's of course hard not to think this is good news. As such, I suspect most readers probably have a slight tilt towards EE or at least are pretty well informed about EE. The overall sample size is also pretty small - 149. Having spent a few years working in the enterprise, my own gut reaction on this is that folks like us, the JBoss/WildFly/TomEE communities, and so many others are doing a much better job at getting the Java EE word out there than we collectively perhaps have in the past. I think it's fairly self-evident that we still have a lot of work ahead of us, particularly with things like the WebLogic and WebSphere communities.

Regardless of the ultimate time lines, the vectors seem to be pointing in the right direction even from a quick look at Google trends. Java EE fans should take a moment to rejoice, look to getting EE 7 adopted in their organization, start thinking about what they want from EE 8 and let us know their thoughts :-).

For folks interested, Kevin detailed the poll with a pretty good write-up.

Monday Jan 27, 2014

Tyrus/WebSocket Client on Android

At JavaOne San Francisco 2013 Ryan Cuprak, Bala Muthuvarathan and I presented a full-house session titled Android and iOS Development with Java EE 7. Ryan is the leader of the Connecticut JUG, a close friend and my co-author on the upcoming second edition of EJB 3 in Action. Bala is a friend and former colleague from CapTech Consulting. We picked the topic as we thought there was surprisingly little content on the topic despite the fact that many people use JAX-RS/Java EE as a mobile back-end platform today and Java EE 7 is an even stronger candidate for this development model. You can check out video for the event below. The demo code for the session is available on GitHub and the slide deck is available on SlideShare. One of the surprising things we came across is that Android still has very weak support for WebSocket development. As a result, I thought it would be great if the WebSocket client APIs standardized in Java EE 7 would work on Android, so I entered a JIRA issue against Tyrus asking for such support.

Some of you might be very pleasantly surprised that the Tyrus team actually addressed the issue! You can read the details of the initial work on Pavel Bucek's blog, including a sample application. If you find the feature useful, I would encourage you to explore the work further, share your thoughts on the Tyrus mailing list or via JIRA. You could even contribute to the sample code for the JavaOne talk :-) (currently the code uses the Autobahn Android library).

Friday Jan 24, 2014

"Come and Play! with Java EE 7" by Antonio Goncalves

Command-line based code generators are one of the most significant selling points of frameworks like Play! and Ruby on Rails. Spring Boot and Spring Roo are efforts along the same lines. Most seem to assume such solutions do not exist for Java EE. In reality, Forge has provided pretty nice command -line Java EE code generation capabilities for a little while now. seam-gen, Forge's predecessor did the same.

Java Champion, Paris JUG founder, JCP expert, author and key Java EE advocate Antonio Goncalves has been trying hard to build awareness of Forge and Java EE through his very cool "Come and Play! with Java EE 7" talk. On January 9th, Antonio was kind enough to deliver the talk at the London GlassFish User Group. Check out the cool video of the talk below:

In the first part of the session, Antonio also delivered a truncated version of his other cool talk - 50 New Features of Java EE 7 in 50 Minutes. The extensive slide deck for the talk is posted on SlideShare. All the details of the event are posted here.

Note while Forge is great, it is by far not the only option for Java EE code generation. NetBeans wizards and include some other options.

Wednesday Jan 22, 2014

JSF 2.2 View Actions

View parameters and pre-render view event listeners were two of the key features added in the JSF 2.0/2.1/Java EE 6 time frame to improve bookmarkability and HTTP GET support. However, the problem with the pre-render view event is that it is triggered both when the view initially loads as well as on all subsequent JSF post backs. This makes it harder to use for the common pattern of looking at passed-in page parameters (usually in the URL query string) and doing some page initialization only once. You could get around this by putting in an explicit post back check in your listener, which is often hard to miss and somewhat hard to understand. As a result, the Seam 3 Faces module added a more focused and powerful view action component.

The good news is that JSF 2.2 standardizes the popular Seam 3 view action feature all but as-is. Hantsy Bai explains the very useful new feature well, including a good bit of technical detail.

Friday Jan 17, 2014

Java EE 7 Event at the Nanjing Software Valley, China

On January 11th, a large Java EE 7 event was held in the Nanjing Software Valley China jointly organized by the China (Nanjing) Software Valley Joint Management Committee and the Nanjing Java User Group. About 80 people from 15 different IT enterprises attended the highly successful event. Speakers included Nanjing JUG founder Tang Yong, Oracle China's Jim King and GlassFish committer Zhou Rong Hui.

Tang Yong blogged about the event in detail. Besides founding the Nanjing JUG Tang Yong is a key GlassFish committer outside Oracle and avid Java EE advocate in China. We can all expect to see great things from the Nanjing JUG and Tang Yong in the new year :-).