Marek Potociar's Blog

22Feb/120

First milestone build of Jersey 2.0

I am excited to announce that we have just released Jersey 2.0-m01, the first milestone build of the next major release of Jersey based on a completely new code base, fresh core design and implementing the upcoming JAX-RS 2.0 API (currently in it's early draft version). Jersey Jira issue tracker contains the full Jersey 2.0-m01 release notes.

As mentioned above, the Jersey 2 is not just an update of the existing Jersey 1.x code, it is a completely new code. The main aspects of the new Jersey 2 code include:

  • Injection-enabled and injection-aware Jersey core that uses HK2 framework for dependency injection. The new Jersey code not only provides user level injection, but the code itself is written to leverage the injection capabilities. Additionally, the decision to use a dedicated dependency injection solution means we will need to spend less time on maintaining a proprietary Jersey 1.x injection framework and focus more on providing new RESTful features.
  • New asynchronous internal request processing API. The core request processing flow has been completely redesigned with asynchronous client and server-side features in mind. This will not only help us unify the processing logic on the client and server, but will let us provide a natural and very efficient support for the new JAX-RS 2.0 asynchronous features.
  • New programmatic server-side resource builder and application configuration API. Ability to programmatically define JAX-RS resources is an often-requested feature that provides a complementary API to the JAX-RS annotation-based resource definitions. In fact, with the new API in place, the Jersey 2 core server-side processing is using the API to translate annotated resource definitions into the internal Jersey runtime model. Check the latest version of the programmatic server-side API javadoc to find out more.
  • JAX-RS 2.0 Client API support. In Jersey 2 we are abandoning and deprecating the proprietary Jersey 1.x Client API in favour of the standard JAX-RS Client API. All the existing examples and tests in Jersey 2 as well as all the tests ported from Jersey 1.x code base are using the new JAX-RS API backed by the Jersey 2 client API implementation.
  • Revamped Jersey test framework and API. In Jersey 2 the goal is to bring more pluggability and flexibility into the test framework API.

For an complete overview of the new Jersey API, please have a look at the Jersey 2.0-m01 API documentation. Note that this is an early development preview release and the parts of the API are moving frequently so you can still expect significant changes in the API. You may want to bookmark the Jersey 2.0 snapshot API documentation link instead to make sure you look at the latest version of the API. Also feel free to browse Jersey 2 source code and check out the new examples that leverage JAX-RS 2.0 Client API as well as Jersey 2 server-side programmatic API.

The second early draft of JAX-RS 2.0 specification is available at the JCP web site. The latest version of JAX-RS 2.0 API documentation is also available for browsing here. This link and more information about the JAX-RS project can be found on the JAX-RS project web site.

Currently, this first early milestone release supports Grizzly 2 HTTP container as well as basic Servlet-based deployments on the server side and provides HTTPURLConnection-based client API implementation. All the 2.0-m01 milestone binaries including the source & apidocs jars are available for download under a new Jersey maven root group identifier org.glassfish.jersey from the central maven repository as well as in the java.net maven repository.

To run Jersey 2 you'll need the core artifacts:

org.glassfish.jersey.core:jersey-common
org.glassfish.jersey.core:jersey-server
org.glassfish.jersey.core:jersey-client

Additionally, you'll need a Jersey container implementation, e.g. Jersey Grizzly2 HTTP container:

org.glassfish.jersey.core:jersey-container-grizzly2-http

Have fun looking around, running examples, playing with Jersey 2. To provide feedback send us an email to our users mailing list

use...@jersey.java.net (archived here)

or log discovered bugs & new feature requests in Jersey Jira issue tracker.

And by the way, for those of you who are more conservative and prefer playing with a production-quality software, we've also released Jersey 1.12. You can find more information about the Jersey 1.12 release on Jakub's blog.

17Nov/118

On JAX-RS 2.0 from Devoxx

Yesterday I gave a talk at Devoxx on what's coming in JAX-RS 2.0 that is planned to go final in the middle of the 2012. On the stage it was hard to see the people because of the spot lights beaming at me, however I could notice that the cinema room for about 450 people was quite full, despite the hard competition from Brian Goetz who was talking about Java SE 8 next door. I did a poll and it turned out that about a third of the people have not worked with JAX-RS before. It was nice to see that JAX-RS is a technology that people care about and that attracts new developers. In fact, today in the morning I ran into a Silicon Valley JUG and GTUG lead in the tram on the way to the conference venue who told me that in his opinion JAX-RS is the technology with perhaps the biggest potential from all current Java EE technologies. Cool,  right? :)

I was little bit nervous with the talk as typically I have at most 15 slides for an hour long talk, but since I wanted to show a lot of code without the danger of spending too much time switching back and forth between slides and IDE, I have put the code into the slides and ended up with a pretty large pile of slides. Also, the night before I took part in an interesting technical discussion that ended up around midnight in a local pub :) . Not sure about the exact correlation ratio, but in the morning I woke up just to realize that I got cold and lost my voice. It got better over the day, but I still could not speak too loud before my talk. Luckily the audio technician was skilled and managed to set up the mic in a way that, although it still did hurt, I could at least speak in a low voice (the only disadvantage was that after the talk two people tweeted that the content was great just the speaker had a sleepy/dry voice). Despite these technical problems I received a very positive feedback overall and I was answering JAX-RS related questions for the next 30 minutes after the talk.

So what did I talk about? See the slides yourself.

Perhaps the most wanted addition to the JAX-RS is the Client API, that would complete the JAX-RS story, that is currently server-side only. In JAX-RS 2.0 we are adding a completely interface-based and fluent client API that blends nicely in with the existing fluent response builder pattern on the server-side. When we started with the client API, the first proposal contained around 30 classes. Thanks to the feedback from our Expert Group we managed to reduce the number of API classes to 14 (2 of them being exceptions)! The resulting is compact while at the same time we still managed to create an API that reflects the method invocation context flow (e.g. once you decide on the target URI and start setting headers on the request, your IDE will not try to offer you a URI setter in the code completion). This is a subtle but very important usability aspect of an API. And if you ever tried to create a (real) fluent API you surely know how hard it is to achieve the result without an explosion of API class/interface numbers. At present the client API is in a draft phase. You can still expect some minor changes in method signatures here and there as we make progress with the underlying API implementation, but the main parts of the client API can be generally considered stable.

The next big feature addition that you can expect from JAX-RS are Filters an Handlers. Filters are essentially reusable providers for Request pre-processing and Response post-processing. The filters are non-wrapping, which means that the filter chain is completely managed by the JAX-RS runtime, including the execution of the filters in the chain. Filters have the way to influence the the chain execution by returning the "next action value", but they do not directly invoke the next filter in the chain (which is where the term non-wrapping comes from). Handlers on the other hand are wrapping (directly invoking the next handler as part of their handle method) interceptors of the message data marshalling and un-marshaling. Whenever a message entity is read or written the request always goes through the handler chain. By default both filters an handlers are applied globally when registered as providers, but JAX-RS 2.0 is going to provide a mechanisms for static as well as dynamic binding of a filter or handler to a particular resource or resource method as well as for specifying a relative order in the filter/handler chain. Dynamic binding is enable via implementing an interface. Static "named" binding is provided via designated named binding annotations.

Since JAX-RS 1.0 came out, many JAX-RS users have requested support for data validation. If you are one of these users, we have a good news for you: JAX-RS 2.0 will provide data validation support by integrating with the standard Bean Validation API. I won't go into too much details here, as the Bean Validation API would itself easily make several blog entries on it's own. The important for us is that by integrating Bean Validation API support into JAX-RS we are providing the JAX-RS users with a very powerful and standard Java API for data validation instead of re-inventing the wheel in JAX-RS spec.

Another notable update in JAX-RS 2.0 is the improved support for working with hyper-links. Current proposal is focused on improved support HTTP link headers. We are extending the existing API as well as making sure the new API additions (client, filters...) are designed with link support in mind. That said, I had two interesting discussions earlier this week with a couple of web client developers who independently pointed out that for them accessing links in HTTP headers is quite difficult and their preferred model is to include all the links in the HTTP entity, typically represented as JSON. I have to admit that we have completely missed this fact in our considerations within JAX-RS EG and this area is something we may still want to look at an revisit the current proposal.

I concluded my talk by a short update on plan to integrate the Java Dependency Injection API (JSR-330) into the JAX-RS. The idea is to slowly move away from the JAX-RS specific @Context injection annotation towards the standard JSR-330 Dependency Injection API. In the first phase we would like to make sure we support @Context and @Inject interchangeably. We would also like to add support for qualified injection (see @Qualifier in DI) as well as think about how to support dependency injection Providers and scopes. The proposal for this area is not finalized yet so I cannot provide more details on the final solution for JAX-RS 2.0 at the moment. We expect to close this task in a month or so.

There are few requested features that are most likely not going to make into JAX-RS 2.0, namely MVC support an high-level client API. In both cases the reasons behind include the lack of consensus in the EG caused primarily by the fact that these areas are still not explored well enough in the proprietary API space to make us feel confident about doing any standardisation work there.

In case you are interested in more details, you can check out the early draft of the specification that was made available for a public review couple of weeks back. You can also check out our JAX-RS Specification Project site on java.net that contains wiki with API proposals as well as (yet to be completed) API javadoc draft. Feel free also to brows through the expert group mailing list archives. Don't forget to subscribe to the users mailing list where all the EG communication is replicated if you want to keep yourself up-to-date with the most recent work in the spec. And most importantly, if you have any feedback, please don't hesitate and send it to the JAX-RS users mailing list.

27May/111

Oracle Java Developer Conference 2011 in Brno, Czech Republic

Yesterday I took part at local Oracle Java Developer Conference 2011 in Brno, Czech Republic. The conference was a great success and the attendance highly surpassed our expectations, most of the attendees being professional developers. The agenda was impressive, focused on latest development in Java SE, EE and tools.

Together with my colleague Jakub Podlesak, we had a talk on REST and JAX-RS API. This was actually my first ever talk on REST and JAX-RS since I took over leading the JAX-RS 2.0 specification project (officially filed in JCP as JSR-339). At the beginning of the presentation I did a short introduction into REST and JAX-RS and then Jakub did a few practical demonstrations showing how things work in practice. In the end I gave a short overview on what are the future plans in JAX-RS. The audience was great and very interested in the topic. With Jakub we stayed for another 40 minutes to answer the constant stream of questions. I have to say that seeing such interest in our work is both refreshing and encouraging. I would like to thank everyone who attended the conference and our session for creating such a wonderful atmosphere. If you are interested, Jakub has published the slides as well as demos from our presentation.

See you next year!