Wednesday Feb 04, 2015

Java EE MVC to be Based on JAX-RS

One of the key Java EE 8 APIs, MVC 1.0 (JSR 371) is solidly moving forward. A key decision for the expert group to consider was whether to base the specification on Servlet or JAX-RS. MVC clearly has many semantic commonalities with both specifications such as HTTP method mapping, mime-type handling, session/request/cookie manipulation and so on. Specifications like JSF and JAX-RS are based on Servlet so it is not unnatural to base MVC on the foundational Java EE specification too. However basing MVC on the lower level Servlet specification would likely mean introducing many APIs that are potential duplicates of what is already available in the higher level JAX-RS API. On the other hand basing MVC on JAX-RS would mean significantly minimizing the possibility of API duplication. It would also mean the programming model between JAX-RS and MVC would be very similar, reducing the learning curve for both newcomers and experienced Java EE developers.

For these reasons it is not too surprising that the expert group has decided to move ahead by basing MVC on JAX-RS. MVC expert group member Ivar Grimstad shares the details including an early view on how the API may wind up looking like in a recent post. Do you have an opinion to share on this?

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.

Monday Feb 02, 2015

CDI and DeltaSpike Overview by CDI Specification Lead

For those of us that have been using CDI for a while it's easy to forget that basic refreshers are extremely valuable for newcomers. Fortunately this point is not lost on current CDI specification lead Antoine Sabot-Durand. He recently finished presenting a three-part webinar covering CDI and DeltaSpike.

In the first of these webinars Antoine covered the very basics of CDI (along with some advanced features). The slides are here and the video is below:

In the second webinar in the sequence Antoine covered a few more advanced features, most notably CDI portable extensions. The slides are here and the video is below:

In the third webinar installment Antoine gave a basic overview of DeltaSpike. DeltaSpike is a very handy set of CDI plugins that all Java EE developers should we aware of. DeltaSpike very deservedly won the Duke's Choice Award for 2014. The slides are here and the video is below:

You should also check out Antoine's more forward looking JavaOne 2014 talk on CDI 2 posted here.

Friday Jan 30, 2015

GlassFish 4 Command Line 101

At it's heart Java EE is a standard API and SPI for developing applications that are deployed to an application server runtime. Though some people miss this point most application servers like WebLogic and GlassFish are far more than vessels for applications. Application servers also typically provide a rich set of features geared towards scalability, security, systems integration, optimization, diagnostics, management and monitoring. The GlassFish command line interface (CLI) is a great example of just such a feature. Though many people prefer to administer GlassFish though the graphical admin console, the CLI is extremely useful for scripting administration tasks as well as potentially getting things done faster.

If you haven't explored the GlassFish CLI you should definitely take a look to get a sense of it's power and utility. Andy Pielage of C2B2 consulting has one of the best write-ups that I have seen for the GlassFish CLI. He explains the basics, offers useful insights and explores some of the most useful commands using great examples. It's a fantastic resource for getting started with the CLI.

Thursday Jan 29, 2015

Using Jersey Client with Netflix Hystrix

There are lot of discussions about Microservice architecture. Lot of them are focused mostly on the benefits of Microservices; sometime some of the drawbacks are overlooked. I am not going to start another discussion on this but one thing is clear: as soon as you have multiple services, you should expect that some of them will fail at some point. Failure is almost inevitable!

Your infrastructure has to be designed with service failure (and degradation) in mind because you don't want all your services to be unavailable just because one of the underlying service is down (or just very slow). Your application needs to be able to isolate any potential failure and offers, at any time, some sort of graceful degradation. The overall idea is to introduce intelligence at the end point level to cope with such issue. You need a circuit breaker to avoid cascading failure. 

Netflix Hystrix is one of the popular solutions for introducing those circuit breaking capabilities. Hystrix is a latency and fault tolerance library designed to isolate points of access to remote services. In case of failure, Hystrix can stop cascading failure and enable resilience in distributed systems. Libor Kramolis from the Jersey Team has just published an article showing how to use the new Jersey Client Reactive API with Netflix Hystrix (and RxJava Observable).

Wednesday Jan 28, 2015

Enterprise Java Newscast: A Good Resource to Stay Up-to-Date

There's so much going on in the Java EE ecosystem that it's very hard to stay up-to-date without getting overwhelmed. As one of the curators of this humble blog I know that all too well. For those very short of time one of the resources that can help you is the JSFCentral Enterprise Java Newscast. It is led by Kito Mann - well respected enterprise consultant, author, blogger and JSF community member. Kito has been a long time supporter of JSF with a long track record of contributing as a JCP standards group expert. The newscast is in fact part of the JSFCentral portal. In the newscast Kito and company discuss interesting recent releases, news items and upcoming events. They also tend to have fairly lively discussion on the newscast on hot topics.

Kito very kindly invited me to join the latest newscast (episode 24). We covered a wide variety of topics including Java EE 8 JSRs, Jersey, RichFaces, Infinispan, Hibernate OGM, WebLogic, Adopt-a-JSR, JavaOne videos and some of my upcoming conferences. The MP3 audio for the episode is available on the linked page. The following are some of the items I contributed (most from this blog):

Tuesday Jan 27, 2015

JMS 2.0 Errata - Public Review has now started!

As announced a few weeks ago, the JMS 2.0 specification (JSR 343) is going through a simple update process, i.e. an errata update. An errata is a simple kind of maintenance release intended purely to correct errors in the specification. The draft of this effort has just been published by the JCP (see Change Log and Issue List here) for a formal maintenance review period that will close on February 21st. That means that you have a little bit more than 3 weeks to submit your comments (see here). After that, the JMS 2.0 errata will go the JCP executive committee for ballot approval. Once 'JMS 2.0 Rev. A' is approved, the actual (and technical) work on JMS 2.1 (JSR 386) will start.

Monday Jan 26, 2015

DDD (Domain-Driven Design) + Java EE "Hanginar" on Thursday

My former colleague at Oracle and fellow Java EE advocate Arun Gupta has been up to something pretty cool - what he calls "Java EE Hanginars". The idea is essentially to have a series of webinars on various Java EE topics using Google Hangout. The format is also a bit different - the idea is to be more code and Q & A centric rather than lecture centric. He gathers a set of questions from the community on the topic before the webinar for live discussion. Thus far he has had good success covering a number of topics including Hibernate OGM, OSGi, jOOQ and CI/CD using Java EE. You can find all of the webinars thus far here. For the fifth webinar in the series, it's now my turn :-).

I'll be talking about a topic that's been near and dear to me as a former Java EE architect/consultant for a while - Java EE and DDD (Domain-Driven Design). The Java EE part is probably obvious to most of you, but the DDD part may or may not be. DDD is an architectural style that strongly emphasizes reflecting the business domain in software development. Though there are some superficial similarities with the classical J2EE design patterns, in my view DDD is a cleaner, more modern and more OO centric design paradigm. Interestingly DDD concepts like the bounded context are becoming increasing important in determining sensible application partitioning amongst the microservices hype of the day. I think Java EE is actually an excellent fit for DDD (and vice versa). To demonstrate how marrying Java EE and DDD is done, I started a small side project a few years ago at Oracle named Cargo Tracker. As a nice (somewhat intended) side-effect the project is actually a good non-trivial example of a working Java EE (7) application. Do feel free to check out the linked site if this intrigues you.

During the webinar, I hope to go over a little bit of the very basics of DDD, demo cargo tracker, show some key code and answer questions. If so inclined, you could add your own questions here. The webinar will start a few minutes before 10 AM Pacific Time (PT) on Thursday January 29th. You should join live here. Hope to see you there?

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

Friday Jan 23, 2015

Vaadin, CDI and Java EE

While some people miss this point, one of the key goals of introducing CDI into Java EE was to easily enable integrating solutions outside the standard into the platform. I was recently reminded of this myself when I saw the announcement that Vaadin now officially supports CDI and Java EE.

Vaadin has long been a very compelling GWT based Java web framework. Although it lags behind the likes of JSF and Spring MVC in terms of adoption, it is extremely polished, it is very much aligned with the Java EE design philosophy and it has a very strong following that hasn't dissipated even with the rise of HTML 5 and JavaScript frameworks. Some folks have been using Vaadin with Java EE for a while using CDI as glue. I am glad both CDI and Java EE (including Java EE 7) is now officially supported by the Vaadin team itself. Like everything else Vaadin, the Java EE/CDI integration is extremely polished with a very nice tutorial explaining the features (see the link above). Another very good resource to get started with Java EE 7, CDI and Vaadin is the YouTube video below featuring Geertjan Wielenga of the NetBeans team and Matti Tahvonen of Vaadin. They use GlassFish and NetBeans for the demo.

Another great GWT based Java web framework worth checking out that works with CDI and Java EE is Errai.

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.

Thursday Jan 15, 2015

JavaOne Replay: 'JMS 2.0 Best Practices in 50 Minutes'

'50 xxx Best Practices (or Tricks) in 50 minutes' is a trendy thing in conferences (*). As the title suggest, the idea is simple: cover a lot of technical tips in a given timeframe. This is an interesting format for attendees as if you are new to the presented subject; you will high likely learn a lot of things.  And if you are already familiar with the topic, chances are high that you will also learn a few tricks here and there.  It is however a difficult exercise for the person delivering the session as there is a lot of technical content to deliver in a well-defined (and relatively short) time frame. And if the speaker got distracted by anything (e.g. beamer issue, long question), it will be very difficult to recoup the lost time.

Anyway, Nigel Deakin (JMS Specification Lead) did this challenging exercise during last JavaOne. By having attended Nigel's 'JMS 2.0 Best Practices in 50 Minutes' session, I can say that this was a very good (and technical) session on JMS! The content should be useful for JMS newcomer but also for people with good JMS knowledge. You can watch the replay below and download the slides here.

(*) That also work with '45' and '55' but nobody ever dared to try with '42'! 

Wednesday Jan 14, 2015

Calling All JSON Enthusiasts: Join JSON-P 1.1!

As many of you know the initial wave of Java EE 8 JSRs are now fully launched for a little while now, including the platform JSR itself, CDI 2, JSON-B, JMS 2.1, Servlet 4, JAX-RS 2.1, MVC and JSF 2.3. More recently three other Java EE 8 JSRs have been launched - Java EE Security, Java EE management and JSON-P 1.1 (more specifically the Java API for JSON Processing 1.1, launched as JSR 374). All three are now in the process of forming their initial expert groups. JSON-P 1.1 lead Kin-man Chung is specifically looking out for folks to join his expert group - go to the JSR page linked above to nominate yourself!

Although it's currently slated to be a point release, there is some very interesting work that may happen in JSON-P 1.1. Here is a very high level summary of the items currently under consideration:

  • Adding support for JSON Pointer.
  • Adding support for JSON Patch.
  • For those unaware, JSON Pointer and JSON Patch are both recently finalized IETF specifications. To go along with the JSON Pointer and JSON Patch work JSON-P 1.1 will also add support for editing/transformation operations to the JSON object model API, quite possibly using the builder pattern.
  • You can actually already use Java SE 8 streams and lambdas with JSON-P. JSON-P 1.1 will explore if Java SE 8 support may be improved across the API further.

Kin-man did an excellent job overviewing the possibilities in his JavaOne 2014 talk that you can see for yourself below.

Note that you can always participate in a JSR without officially being part of the expert group by simply subscribing to the JSR user alias. In case of JSON-P that alias is users at json-processing-spec dot java dot net - go to the JSON-P java.net project page to subscribe. Also remember that you can contribute on an even more lightweight format through Adopt-a-JSR.