Tuesday Feb 03, 2015

Batch API Hands-on Lab

During last JavaOne, we held a Hands-on-Lab on JSR 352. JSR 352 is one of the new Java EE 7 APIs. The formal API is name is 'Batch Applications for the Java Platform' but it is often referred to as the 'Batch API'.

The goal of this Lab is twofold, introducing the Batch API to newcomers and then explaining some of the most advanced JSR 352 features. For that reason, the Lab has been divided in 5 exercices:
  • Exercice 1 will introduce you the main concepts of JSR 352 such as Step, Job, JSL, etc. 
  • Exercice 2 will enhance the first exercise and introduce mutli-steps jobs combining Chunk step with a Batchlet step.
  • Exercice 3 will cover checkpoint and the JobOperator interface which can be used to resume a failed job.
  • Exercice 4 will build introduce you to listeners, a mechanism that can be used to intervene within the life-cycle of a batch job (e.g. to catch errors).
  • Exercice 5 will introduce the concept of Job Partitioning, a more advanced feature of JSR 352.
This Lab has been developed and tested on GlassFish 4.1 but it should work on any Java EE 7 compatible application server (note that JSR 352 is part of the full platform). This Lab is now hosted on GitHub so to learn JSR 352, just clone the https://github.com/java-ee/BatchLab repository and check the masterLab document.

Thursday Jan 22, 2015

Java EE @ JMaghreb 2014

JMaghreb 2014 was held on November 4-6. Organized by the Morocco JUG, JMaghreb is one of the largest Java developer conferences in North Africa. This was yet another brilliant year for the conference. Speakers included Patrick Curran, Werner Keil, Johan Vos, Mohamed Taman, Hazem Saleh, Paul Bakker, Romain Manni-Bucau, Abdelmonaim Remani, Simon Ritter, Angela Caicedo and Mike Milinkovich. Topics included Java SE, Java EE, JavaFX, HTML5/JavaScript, mobile, NoSQL, OSGi, Big Data and the cloud. I am extremely grateful that the organizers invited me and very glad that I was able to accept.

I delivered talks on open standards/the JCP, aligning the JavaScript ecosystem with Java EE 7, aligning Java EE with Reactive Programming and Java EE 8. More details on the sessions and JMaghreb, including the slide decks and code, posted on my personal blog.

Wednesday Jan 21, 2015

Better CDI Alignment in JPA 2.1/Java EE 7

A long standing open debate within the Domain-Driven Design (DDD) community is whether entities should be able to access application services (roughly business facades in J2EE patterns parlance) and repositories (roughly DAOs in J2EE patterns parlance). If we think it's OK for entities to access these parts of the application, it poses a problem in JPA and other mainstream data access technologies - how do you inject objects into an entity? The answer today in JPA is that you can't do that. There are good technical reasons why it's difficult to allow CDI injection directly into JPA entities - it becomes very difficult to figure out how to manage the entity life-cycle if it is managed by both the CDI and JPA runtimes at the same time.

So is there a solution to this problem? The good news in JPA 2.1 and Java EE 7 is that there is a clever workaround. While you can't use CDI injection in entities, entity listeners now fully support injection. If needed you can then pass in an appropriately scoped injected object (probably an application scoped bean) into the entity or anything else that you need from the entity listener. This is exactly the technique demonstrated by Hantsy Bai in explaining CDI support in JPA 2.1 entity listeners. Besides entity access to services and repositories, being able to use injection in entity listeners is generally very helpful for more complex cross-cutting concern like requirements at the JPA layer. Prior to JPA 2.1 both Apache CODI and Seam 3 enabled injection into JPA entity listeners.

If you happen to need a basic introduction to JPA entity listeners, Alexandre Gama has one of the best compact write-ups I've seen so far.

For the record, I do think accessing application services and repositories in entities violates the separation of concerns principle and should be done very sparingly :-).

Please note that any views expressed here are my own only and certainly does not reflect the position of Oracle as a company.

Tuesday Jan 20, 2015

Heads Up on Java EE @ DevNexus 2015!

DevNexus 2015 will be held on March 10-12 in Atlanta. If you are a US based developer and do not know about DevNexus, you are definitely missing out. DevNexus was started a few years ago as an initiative by the Atlanta Java User Group (now one of the largest Java user groups in the world) and Burr Sutter (one of the earliest Java champions). Since then DevNexus has grown to become one of the largest Java leaning conferences in the US, perhaps second only to JavaOne. I've spoken at the conference a few times over the years. This year's roster is unsurprisingly impressive both in terms of speakers and content. Java EE has a strong showing including a few talks from me.

Below are the talks that might interest you if you are a Java EE fan (the schedule is not quite final yet so do stay tuned to the conference agenda for changes):

  • Down and Dirty with Java EE 7: This is essentially our flagship lab/workshop at the moment covering Java EE 7. It has always proven popular so far and it is a great way to get some hands-on experience with Java EE 7. The materials for the lab is always available here. The lab is largely intended to be self-guided so you should be able to take advantage of the material even if you can't attend the lab in person. This will be my first talk at the conference.
  • JMS.Next(): JMS 2.0 and Beyond: This is essentially an overview of JMS 2 (already in Java EE 7), with a bit of an early preview of JMS 2.1 (to be included in Java EE 8). The slides for the talk are available here. This will be my second talk at the conference.
  • Java Persistence API: This session is a good mix of the basics, best practices and real world adoption stories for JPA. It's a talk by Jason Porter. Jason is a good speaker, a long time Java EE advocate and a Red Hat engineer.
  • HTTP 2.0 comes to Java. What Servlet 4.0 means to you: This session will discuss what's in HTTP 2 and what that means for the next major revision of the foundational Servlet specification. I would say this is a must-attend for all server-side Java developers. My friend, colleague and Servlet specification lead Ed Burns is giving this talk. Ed is a brilliant speaker that's always a pleasure to listen to.
  • Java EE 8: A Community Update: This is essentially a high level overview of what's coming in Java EE 8. This should be my last talk at the conference. Besides covering the current state of Java EE 8 I will also talk about how you can get involved in the process including through highly inclusive programs like Adopt-a-JSR. The slides for the talk are here.

Hope to see you at the conference? Besides giving my talks I will be attending a few talks myself as time allows. As always never hesitate to stop me if there is something I can help with. I'll also bring along some Java/Java EE goodies you are welcome to.

Friday Jan 16, 2015

File Uploads Using JSF 2.2 and Java EE 7

File uploads have long been possible in JSF, usually using third party plugins like PrimeFaces or RichFaces. JSF 2.2 finally adds support for file uploads out of the box. The practical reason for this lag is that the JSF specification has always chosen to support a Servlet version one behind the latest. This is what often makes it possible to use newer versions of JSF on older runtimes, particularly on Servlet containers like Tomcat. Consequently JSF 2.2 can depend on Servlet 3.0 which adds support for multi-part file handling - making the new file upload feature possible. In a pretty well written code driven post, Hantsy Bai explains the file upload support in JSF 2.2/Java EE 7. You can also check out Rama Krishnnan's YouTube video below on the file upload feature:

Interestingly Rama uses Tomcat and an older version of NetBeans but is still able to demo the feature well (he also chooses to do manual header parsing himself). Things are obviously a lot easier with a Java EE 7 server like GlassFish, which is what Hantsy Bai uses instead.

Monday Jan 05, 2015

Vasilis Souvatzis's Java EE 7 Thesis Using GlassFish

Hoping all of our readers happiness, health and wealth in this first post of the year! It's an awesome stroke of good luck to be able to start the year off by sharing a pretty cool Java EE 7/GlassFish 4.1 adoption/learning story. Vasilis Souvatzis, a computer science student at the Alexander Technological Educational Institute of Thessaloniki (ATEITHE) in Greece, decided to do his thesis project on Java EE 7. He basically taught himself Java EE 7, Java SE 8, GlassFish, NetBeans and PrimeFaces with little more than what is freely available online. He is now proudly a fan of the technology stack, particularly Java EE 7.

The end result of his project is a pretty sophisticated, non-trivial working code base simulating a web-based tutorial (there aren't too many students that I know of that has those bragging rights :-)). He actually made the project available on GitHub for all to see. He demos the project in the video below he took the time to create:

The GitHub project has instructions on how to setup and explore the project yourself. He would also welcome any contributions if you are so inclined. Enjoy and don't forget to spread the word on Vasilis's hard work useful to the Java EE community if you think it is cool!

Thursday Dec 11, 2014

Named and Dynamic Binding in JAX-RS 2

Providers, interceptors and filters are excellent mechanisms to bring pluggability and cross-cutting concerns to JAX-RS. By default these artifacts are applied globally to all available JAX-RS resource methods. This is probably fine for the most part but in some cases it's useful to have a bit more control over where filters and interceptors are applied. Fortunately, JAX-RS 2 has two mechanisms to facilitate this - named and dynamic bindings. Named bindings are much like binding CDI interceptors in that it is declarative and static - you get to choose in a loosely coupled, type-safe fashion where you want a binding to occur but you can't change bindings at runtime. Dynamic bindings as the name implies gives you a much greater degree of flexibility. You can choose at runtime in a completely programmatic fashion where bindings should occur. The trade-off is that dynamic bindings are a bit more complex and verbose. Michal Gajdos explains both named and dynamic JAX-RS 2 provider bindings in a fairly brief but excellent blog post.

Towards the bottom of the post, Michal has links to the Jersey docs that is a great resource for understanding the concepts of providers, interceptors and filters in a general sense.

Thursday Dec 04, 2014

The Java 7 EE Tutorial - free eBook!

The Java EE 7 Documentation page has been recently refreshed with an improved and cleaner layout.   It should now be easier to locate, browse and read the Java EE API documentation, the Java EE SDK documentation and the Java EE Tutorials.

It is sometime useful to remind about the availability of useful resources such the "Java EE Tutorial"… even more when those resources a free!  The Java EE Tutorial is one of those gems that is sometime overlooked.  It covers Java EE 7 and is an invaluable set of resources for anyone wanting to learn Java EE but also for people already familiar with Java EE as it also covers some of the less known part of the Java EE platform such as JCA.

For new comers, there is "Your First Cup: An Introduction to the Java EE Platform", a crisp introduction to the Java EE platform.

The "Java EE 7 Tutorial" is available for free (online and PDF format).  In addition, the Java EE Tutorial is now also available in ePub and Mobi formats (hint: check the top right corner) so you can download and read it on your preferred eBook reader (tablets, iBook, Kindle, etc.).  Just check the top right corner.  And again, those great resources are free!

Finally if you are more old school, the "Java EE 7 Tutorial" is also available, for a fee, as a dead-tree version.

Tuesday Dec 02, 2014

JMS 2.0 Errata release

There is a clear plan to enhance the JMS specification and that is JMS 2.1 (JSR 368), slated for inclusion in Java EE 8.  The JMS 2.1 Expert Group is still in formation phase and once this is done, the EG will start the actual works on the next revision of JMS.  This work is expected to take time, Q3 2016 is the current ETA for the Java EE 8 final release. 

But let's not forget the current version of JMS, i.e. JMS 2.0 (JSR 343).  An errata is needed to correct a few errors in JMS 2.0 which can't wait for JMS 2.1 because they affect the ability of implementers to correctly implement JMS 2.0 today.  An 'errata' is a simple kind of maintenance release intended purely to correct errors in the specification, so clearly the intention is not define any new features (any new features should be discussed within the JMS 2.1 scope).

For that reason, Nigel Deakin (JMS 2.0 and JMS 2.1 Specification Lead) has proposed and started an errata for JMS 2.0.  An Errata release (and maintenance releases in general) don’t have an Expert Group.  Nevertheless Nigel is soliciting feedback on the various small issues that he plans to have addressed in the JMS 2.0 Errata.  You can check the changes proposed for the JMS 2.0 errata on this Wiki page, the jms-spec users mailing list is a good channel to provide feedback.

Monday Dec 01, 2014

Bulk Update/Delete using the Criteria API in JPA 2.1/Java EE 7

It has long been possible to do bulk updates and deletes using JPQL in JPA. Since JPQL is closely modeled after SQL, it has the key advantages that SQL does - namely that it is a very compact and powerful DSL for relational data manipulation. JPQL is also a natural transition mechanism to JPA for folks that have worked with SQL for a while (such as myself).

The big drawback for JPQL is that it is decoupled from the Java compiler and thus less type-safe/more error-prone. This weakness becomes particularly salient while needing to dynamically construct queries at runtime (with JPQL this basically turns into a lot of hard-to-read string manipulation) or with folks coming from a Java/OO background without much preexisting experience with SQL/RDBMS. For these reasons, the type-safe, Java centric Criteria Query API was added to JPA 2.0/Java EE 6.

In JPA 2.1/Java EE 7 the Criteria API has been moved even closer to JPQL with the addition of bulk update and delete capabilities (the Criteria API in JPA 2.0 supported queries which is by far still the primary use case for the API). Hantsy Bai has a very nice post demonstrating how bulk updates/deletes look like using the JPA 2.1 Criteria API.

For a more basic overview of the Criteria API itself, you should check out the official Java EE 7 tutorial.

Tuesday Nov 18, 2014

JavaOne Replay: "Into the Wild with Servlet Async IO"

Greg Wilkins has an impressive 'Web pedigree’; he is the founder and lead developer of Jetty.  Greg is a long-time member of the Servlet Expert Group; he is also a member of the IETF HTTP/2 working group member, etc.!

During his JavaOne session, Greg gave a deep technical overview on Asynchronous IO using the Servlet API.  Greg starts by explaining what asynchronous means in the context of a Servlet. He then goes and explains the Servlet 3.0 asynchronicity support.  The rest of the talk is then spent on the Servlet 3.1 API and how to write effective asynchronous servlets (and how the inner-working of the API).  Greg also shares some of the motivations behind the Servlet 3.1 API and the technical choices behind it. Not only that, Greg is also talking about some 'potential more obvious technical options' and why those options were not selected at the end.

This technical session provides different angles (e.g. Servlet API explanations, some deep technical points such as some of the Jetty implementation details but also best practices advices, etc.).  Overall this session is highly recommended for anyone who want to understand asynchronicity in the context of the Servlet API.


You can find Greg's slides here.

Wednesday Nov 12, 2014

Java EE @ NFJS Pacific Northwest Software Symposium Seattle

As some of you may be aware I recently joined the well-respected US based No Fluff Just Stuff (NFJS) Tour. The NFJS Pacific Northwest Software Symposium was held October 17 - 19 in Seattle, Washington.

I had five talks total over two days, more or less back-to-back. I did talks on Java EE 7/Java EE 8, the Cargo Tracker Java EE Blue Prints, JavaScript + Java EE, Java EE + NoSQL as well as WebSocket. More details, including slide decks and code as well as my NFJS tour schedule, posted on my personal blog.

Monday Nov 03, 2014

Java EE @ NFJS New England Software Symposium Boston

As some of you may be aware I recently joined the well-respected US based No Fluff Just Stuff (NFJS) Tour. The NFJS New England Software Symposium was held September 19 - 21 in Boston. This is one of the larger NFJS shows and attendance at the show and my sessions was pretty good. It is always encouraging to see the same folks attend more than one talk. On my way to the show I also stopped by at the Connecticut Java User Group. The JUG is led by my friend and co-author for EJB 3 in Action Ryan Cuprak. I've spoken at the JUG a number of times over the years and it was good to be back.

I had five talks total over two days, more or less back-to-back. I did talks on Java EE 7/Java EE 8, the Cargo Tracker Java EE Blue Prints, JavaScript + Java EE, Java EE + NoSQL as well as JMS 2. More details, including slide decks and code as well as my NFJS tour schedule, posted on my personal blog.

Wednesday Oct 29, 2014

Java EE @ NFJS Greater Atlanta Software Symposium

As some of you may be aware I recently joined the well-respected US based No Fluff Just Stuff (NFJS) Tour. The NFJS Greater Atlanta Software Symposium was held September 12 - 14.

I had four talks total over two days, more or less back-to-back. I did talks on Java EE 7/Java EE 8, WebSocket, the Cargo Tracker Java EE Blue Prints and JavaScript + Java EE. More details, including slide decks and code as well as my NFJS tour schedule, posted on my personal blog.

Wednesday Oct 22, 2014

Themes/Resource Library Contracts in JSF 2.2/Java EE 7

Resource Library Contracts are one of the big ticket features in JSF 2.2. There's actually quite a bit to the feature - it allows for logical organization and packaging of the theme/look-and-feel/template for JSF pages. Beyond enabling better modularity, the feature makes it possible to switch page themes at runtime (much like PrimeFaces, RichFaces, etc did in the past). Huseyin Akdogan explains the details of resource library contracts in a code-intensive post. You should also checkout the video below from the GlassFish Videos YouTube channel in which specification lead Ed Burns covers the feature along with JSF 2.2 generally (the video is pretty short - just about fifteen minutes).

The official Java EE 7 Tutorial has a decent section on the basics of  resource library contracts as well.