Wednesday Apr 16, 2014

JSON Schema

We often tends to compare JSON against XML, i.e. JSON is simple, XML is not so simple. JSON is light, XML is heavyweight, etc. But there are still reasons to prefer, in certain cases, XML over JSON : e.g. transformation capability, XML extensibility, validation, ...

A question I sometime get when I talk about JSON-P support in Java EE is what about Schema? The works around JSON Schema standardisation is progressing but right now, this is still a draft specification. Nevertheless, this is something that you can already start to use. For example, this post shows how-to generate JSON Schema with Eclipse Link MOXy today.

As said earlier, the JSON Schema space is evolving, there are works that needs to be done at various levels but we can expect, over-time, an improved support for JSON Schema in the Java ecosystem. 

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!

Tuesday Jan 28, 2014

Using updated release of Jersey, Tyrus, Weld, ... in GlassFish 4

The Java EE specification is an umbrella specification that refers to different components specifications, aka components JSRs (e.g. Servlet, JMS, JAX-RS, ...). And as the Java EE 7 Reference Implementation, GlassFish 4 is made of those different components JSRs Reference Implementations. 

In addition to the specification, most of those implementations (eg. Jersey) also offers additional features (and fixes). And clearly, the different implementations that make GlassFish are evolving each at a different pace. Jersey (JAX-RS RI), Tyrus (WebSocket RI), Weld (CDI RI), Mojarra (JSF RI) are examples of implementations that evolves rapidly. GlassFish 4.0 embeds Tyrus 1.0, Jersey 2.0, Mojarra 2.2.0 and Weld 2.0.0.SP1 but since that time, those implementations have evolved quite a lot. As of today, the current release of Tyrus is 1.4, the current release of Jersey is 2.5.1, the current release of Weld is 2.0.5 and the current release of release of Mojarra is 2.2.5.

So what to do if you want to use one of the new features provided by one of those implementations in GlassFish 4? One way is to wait that the specific version of that implementation, say Jersey for example, is integrated in a nightly build of the GF 4.0.1 branch. Another solution is to upgrade the specific implementation (e.g. Jersey) in an existing GlassFish 4 setup. The following posts explains how to update Tyrus, how to update Jersey, how to update Weld and how to update Mojarra in a GF4 setup. 

It should be mentioned that no extra testing has been done, so clearly do not do this in any critical environments. And if the updated setup is not stable, it is always easy to come back to the initial configuration. Most of the time, it's just a matter of putting back the original implementation Jar and restarting GlassFish. For Jersey, the provided update script is able to restore the initial configuration if needed. 
Also, since Jersey has dependencies on HK2 and since HK2 has been updated between GF 4.0 and the 4.0.1 branch, it is only possible to update Jersey in a GlassFish 4.0.1 build.

In any cases, if you are using GF 4 with an updated version of Tyrus, Jersey, Mojarra or Weld, we would like to hear your feedback!

Friday Dec 20, 2013

Server Sent Events (SSE) in Glassfish/Jersey

As you know, HTTP is a stateless protocol. For most use cases in the enterprise, the statelessness of HTTP is a huge boon for scalability - a benefit that is also extended to REST. However, there is a certain class of arguably emerging use cases for which the stateless nature of HTTP is actually a scalability challenge. These use cases require the bidirectional, full-duplex, asynchronous characteristics of stateful protocols such as TCP. Examples include chat-like online collaboration, stock-ticker like command-control/monitoring, online gaming and the like. WebSocket (and the Java API for WebSocket newly included in Java EE 7 :-)) is ideal for these cases. Between the seemingly diametric opposites of plain HTTP and WebSocket, there's also Server Sent Events (SSE). SSE is aimed at yet another scenario - a steam of events generated by the server and consumed passively by the client. Although not standardized in JAX-RS 2/Java EE 7, Jersey/GlassFish includes support for SSE.

In an very detailed blog post, Rahman Usta of the Istanbul JUG explains SSE and demonstrates a non-trivial use of the Jersey/GlassFish support for SSE.

Thursday Nov 21, 2013

Jersey 2.x Tracing support

"Rest is the sweet sauce of labor." (Plutarch – a long time ago!)

Jersey is JAX-RS 2.0 Reference Implementation and as such it's fully compliant to JSR 339. The Jersey Team goes beyond the specification by adding features and functionalities to their JAX-RS implementation. Overtime, some of those features might be good candidates for standardization.  The Client API is a good example of that. In JAX-RS 1.x, Jersey and some other implementations has their own proprietary Client API. In JAX-RS 2.0, the Client API has been standardized and is now part of the specification. So it is not uncommon to have, in an implementation, features that are (not yet?) part of the specification. Those extra capabilities are also a way for an implementation to differentiate itself from the other implementations.

Tracing is a feature that was available in Jersey 1.x, this feature has now been ported to Jersey 2.x (2.3 and above). The Jersey Tracing capabilities allows to easily diagnose server-side request processing pipelines.  Libor Kramoliš, a member of the Jersey Team, has written a detailed post on how to use the Jersey's Tracing capability.

Friday Jul 06, 2012

Jersey 2 Integrated in GlassFish 4

JAX-RS 2.0 has released Early Draft 3 and Jersey 2 (the implementation of JAX-RS 2.0) released Milestone 5.

Jakub reported that this milestone is now integrated in GlassFish 4 builds. The first integration has basic functionality working and leaves EJB, CDI, and Validation for the coming months.

Jersey 2.0 in GlassFish 4

TOTD #182 explains how to get started with creating a simple Maven-based application, deploying on GlassFish 4, and using the newly introduced Client API to test the REST endpoint.

GlassFish 4 contains Jersey 2 as the JAX-RS implementation. If you want to use Jersey 1.1 functionality, then Martin's blog provide more details on that. All JAX-RS 1.x functionality will be supported using standard APIs anyway. This workaround is only required if Jersey 1.x functionality needs to be accessed.

Here are some pointers to follow

Provide feedback on Jersey 2 to users@jersey.java.net and JAX-RS specification to users@jax-rs-spec.java.net.

Wednesday Mar 28, 2012

Jersey 2.0 Milestone 2 Now Available

Jersey 2.0 milestone 2 is now available. It builds upon the first milestone and adds several new features such as server-side asynchronous processing, server-side content negotiation, improved JAX-RS parameter injection, and several others.

ALT_DESCR

The REST endpoints can be published on Java SE HTTP Server, Grizzly 2 HTTP container, and some basic Servlet-based deployments. It also provides HTTPURLConnection-based client API implementation. Read about these and more about what's new in Marek's detailed post. Of course this is also the future reference implementation for JAX-RS 2.0.

Feel like trying it out? Simply go to Maven Central (of course none of this is production quality at this point). The latest JAX-RS Javadocs and Jersey 2.0 API docs are good starting points to explore. And provide them feedback at users@jersey.java.net.

Sunday Mar 18, 2012

RESTful Java on Steroids (Parleys, Podcast, ...)

As reported previously here, the JAX-RS 2.0 (JSR 339) expert group is making good progress.

If you're interested in what the future holds for RESTful Java web services, you can now watch Marek's Devoxx presentation or listen to him in the latest Java Spotlight Podcast (#74).

ALT_DESCR

Marek discusses the new client API, filters/handlers, BeanValidation integration, Hypermedia support (HATEOAS), server-side async processing and more.

With JSR 339's Early Draft Review 2 currently out, another draft review is planned for April, the public review should be available in June while the final draft is currently scheduled for the end of the summer. In short, expect completion sometime before the end of 2012.

Monday Mar 05, 2012

GlassFish 3.1.2 Updated Components (Final)

Now that GlassFish 3.1.2 has been released, it's time to check on the exact list of updated components (one of the important themes in pretty much every release).

• JSF/Mojarra 2.1.6
• Grizzly 1.9.46
• Metro 2.2
• Jersey 1.11
• Shoal 1.6.17
• EclipseLink 2.3.2
• Message Queue 4.5U2
• OSGi Core 4.3.0
• Update Center 2.3.5
• Hibernate Validator 4.2.0-FCS
• JavaDB 10.8.1.2
• Weld 1.1.4.Final

ALT_DESCR

About half of the bugs squashed in this GlassFish 3.1.2 release were through the integration of those recent components.

Wednesday Feb 22, 2012

JAX-RS 2.0 - Jersey Code Rulez

What's better than the JAX-RS 2.0 Early Draft? Well, code of course! As spec lead Marek Potociar just announced, the first Jersey 2.0 milestone build is out.

ALT_DESCR

This is an entirely new code base which uses HK2 for dependency injection (a core technology for GlassFish), offers a new asynchronous internal design as well as an API to programmatically define JAX-RS resources. Read about these and more about what's new in Marek's detailed post. Of course this is also the future reference implementation for JAX-RS 2.0.

Feel like trying it out? Simply go to Maven Central (of course none of this is production quality at this point).

Thursday Feb 09, 2012

A status on JAX-RS 2.0. Early Draft.

With the Early Draft of JAX-RS 2.0 review period closed for a little while now, here's Arun's walk through the technology's new and improved features.

ALT_DESCR

The Client API seems to be a very popular feature and one that seems pretty stable at this point. Filters and Handlers is another set of new features enabling interception of requests and responses while Hypermedia, a founding principle for REST, is better supported. JAX-RS 2.0 also offers the ability to validation parameters with BeanValidation, introduces asynchronous processing (returning Future objects on the client side) and finally better connection negotiation. Read all about it here.

JAX-RS has become an important component of the Java EE platform and the cloud theme going forward is only making it even more relevant. Check out this earlier post for Marek's (co Spec Lead on JAX-RS 2.0) take on where the JSR stands.

Sunday Feb 05, 2012

POJOMapping in Jersey for type-safe clients

Over on his blog, Jason Lee has a detailed post on the new POJOMapping feature in Jersey/GlassFish which offers strongly-typed client API's and illustrates this with a GlassFish Cluster administration sample.

ALT_DESCR

The post shows how to enable POJOMapping with a Jersey servlet initialization parameter and goes on to show the Cluster domain model. An archive with the entire sample is available there.

Sunday Jan 08, 2012

RESTful JAX-RS Roundup

Note: if you're reading this using a feedreader, please make sure you've updated to the updated TheAquarium feed.

While most parameter handling examples with JAX-RS focus on @PathParam, there are other JAX-RS 1.x annotations that are worth knowing.

Mkyong has a short and simple example for how to use @MatrixParam (and for many more here) while John Yeary covers @CookieParam. The JavaDoc for both annotations can be found here and here.

ALT_DESCR

Meanwhile, François explores Jersey's support for MVC where the Controller is a resource class, the model is returned by a resource method, and the view is a template which operates on the model (this is inspired by the stapler project and is also used by Hudson). Note that this is not part of the JAX-RS standard.

To close this quick roundup, I'd like to point you to a month-old JAX-RS blog entry by Adobe's Christophe Coenraets combining jQuery and JAX-RS/Jersey as probably the one with the best taste to date (IMO, etc...) !

Update: John Yeary has (a lot) more JAX-RS resources for you.

.