swh:1:cnt:383f2d7e0a29f06a88cfe97229b7e45bc1e53527;origin=https://github.com/OpenLiberty/blogs;anchor=swh:1:rev:aed17e0f31e7d98a23a95852b5a75250775d2c2d;path=/posts/2018-06-29-full_java_ee_8_liberty_18002.adoc
Show source
---
layout: post
title: Get full Java EE 8 in Open Liberty 18.0.0.2
date: 2018-06-29 08:00:00 -0000
categories: blog
author_picture: https://avatars3.githubusercontent.com/u/3322532
author_github: https://github.com/lauracowen
seo-title: Get the full Java EE 8 implementation in Open Liberty 18.0.0.2 - OpenLiberty.io
seo-description: Full Java EE 8 support, including JAX-RS 2.1 reactive client and server-sent events, CDI event-ordering and asynchonous events, HTTP/2 support in servlets, JSF 2.3, JPA 2.2, JWT cookies (yum!), security improvements,...oh, and you can now deploy Spring Boot applications to Liberty.
blog_description: "Full Java EE 8 support, including JAX-RS 2.1 reactive client and server-sent events, CDI event-ordering and asynchonous events, HTTP/2 support in servlets, JSF 2.3, JPA 2.2, JWT cookies (yum!), security improvements,...oh, and you can now deploy Spring Boot applications to Liberty."
---
= Get full Java EE 8 in Open Liberty 18.0.0.2
Laura Cowen <https://github.com/lauracowen>
:imagesdir: /
:url-prefix:
:url-about: /
Yes, it's here! Open Liberty is the first app server (to our knowledge) with full Java EE 8 support. What does that mean? Well, we've got the goodness of JAX-RS 2.1 reactive client and server-sent events, CDI event-ordering and asynchonous events, HTTP/2 support in servlets, JSF 2.3 (for the JSF fans, you know who you are), JPA 2.2, JWT cookies (yum!), security improvements,...oh, and you can now deploy Spring Boot applications to Liberty #justsayin'
What are you waiting for? Download Open Liberty 18.0.0.2:
[link=https://openliberty.io/downloads/]
image::img/blog/blog_btn_download-ol.svg[Download Open Liberty, align="center", role="download-ol-button"]
[link=https://stackoverflow.com/tags/open-liberty]
image::img/blog/blog_btn_stack.svg[Ask a question on Stack Overflow, align="center"]
Alternatively, if you're using https://www.openliberty.io/guides/maven-intro.html[Maven], here are the coordinates:
[source,xml]
----
<dependency>
<groupId>io.openliberty</groupId>
<artifactId>openliberty-runtime</artifactId>
<version>18.0.0.2</version>
<type>zip</type>
</dependency>
----
Or for https://openliberty.io/guides/gradle-intro.html[Gradle]:
[source,json]
----
dependencies {
libertyRuntime group: 'io.openliberty', name: 'openliberty-runtime', version: '[18.0.0.2,)'
}
----
Or if you're using Docker:
[source]
----
docker pull open-liberty
----
In Open Liberty 18.0.0.2, you'll find:
* <<javaee8,Full support for Java EE 8:>>
** <<jaxrs,Reactive client and server-sent events with JAX-RS 2.1>>
** <<cdi,Asynchronous events, event ordering, and more with CDI 2.0>>
** <<servlet40,Write dynamic web applications with Servlet 4.0>>
** <<http2,HTTP/2 protocol support>>
** <<jsf,Build user interfaces for web applications with JavaServer Faces (JSF) 2.3>>
** <<jpa,Interact with databases with Java Persistence API (JPA) 2.2>>
** <<jwtsso,Emit and consume JWT cookies with JWT Single Sign-on 1.0>>
** <<appsecurity,Secure your applications using Security API 1.0 specification>>
** <<jsonb,Store JSON with JSON-B 1.0>>
** <<beanval,Validate objects, parameters, and more with Bean Validation 2.0>>
* And:
** <<spring,Deploy Spring Boot applications to Liberty>>
** <<certmapper,Control how custom X.509 certificates map to users in Liberty's LDAP and basic user registries>>
As we don't have a full set of documentation implemented for Open Liberty yet, the items below point to the https://www.ibm.com/support/knowledgecenter/SSEQTP_liberty/as_ditamaps/was900_welcome_liberty.html[official documentation for WebSphere Liberty] so you can find out more about them (WebSphere Liberty is built on Open Liberty).
[#javaee8]
== Full support for Java EE 8
https://openliberty.io/downloads/[Download Liberty] with either the Java EE 8 Web Profile runtime or the Java EE 8 Full Platform runtime.
You can enable all of the Java EE 8 features (or the more lightweight set of Web Profile features) with a single feature in your `server.xml`.
=== Java EE 8 Web Profile
The features included when you enable the `webProfile-8.0` feature (Java EE 8 Web Profile) and are new in Java EE 8 are:
* `appSecurity-3.0`
* `beanValidation-2.0`
* `cdi-2.0`
* `jaxrs-2.1`
* `jaxrsClient-2.1`
* `jpa-2.2`
* `jpaContainer-2.2`
* `jsf-2.3`
* `jsonb-1.0`
* `jsonp-1.1`
* `servlet-4.0`
The `webProfile-8.0` feature also contains the following features which are unchanged from Java EE 7: `distributedMap01.0`, `ejbLite-3.2`, `el-3.0`, `jaspic-1.1`, `jdbc-4.2`, `jndi-1.0`, `jsp-2.3`, `managedBeans-1.0`, `ssl-1.0`, `websocket-1.1`.
To enable the whole of the `webProfile-8.0` feature, add the feature definition to your `server.xml`:
[source,xml]
----
<featureManager>
<feature>webProfile-8.0</feature>
</featureManager>
----
=== Java EE 8 Full Profile
The features included when you enable the `javaee-8.0` feature (Java EE 8 Full Platform) and are new in Java EE 8 are:
* `webProfile-8.0` (see above)
* `javaMail-1.6`
The `javaee-8.0` feature also contains the following features which are unchanged from Java EE 7: `appClientSupport-1.0`, `batch-1.0`, `concurrent-1.0`, `ejb-3.2`, `ejbHome-3.2`, `ejbPersistentTimer-3.2`, `jacc-1.5`, `jaspic-1.1`, `jaxws-2.2`, `jca-1.7`, `jcaInboundSecurity-1.0`, `jms-2.0`, `mdb-3.2`, `wasJmsClient-2.0`, `wasJmsSecurity-1.0`, `wasJmsServer-1.0`.
To enable the whole of the `javaee-8.0`, add the feature definition to your `server.xml`:
[source,xml]
----
<featureManager>
<feature>javaee-8.0</feature>
</featureManager>
----
For more info:
* http://www.oracle.com/technetwork/java/javaee/tech/java-ee-8-3890673.html[Java EE 8 technologies list (Oracle)]
[#jaxrs]
== Reactive client and server-sent events with JAX-RS 2.1
JAX-RS 2.1 enables two exciting new technologies: reactive client and server-sent events. The reactive client takes full advantage of Java 8 lambda expressions to enable highly scalable multi-threaded clients. Server-sent events allow developers to send data asynchronously to multiple clients, either individually or by broadcasting to all in an efficient manner.
Coding an asynchronous JAX-RS client was possible in JAX-RS 2.0 but the reactive client in 2.1 enables much more parallelism with much less code. Users can now kick off multiple client requests having each one react to the response from the server, potentially by making new asynchronous requests.
Server-sent events was not possible using JAX-RS APIs prior to 2.1. Users wishing to send updates to remote clients using JAX-RS would need to rely on polling which is inefficient. Otherwise, they would need to rely on third-party implementations to provide SSE or SSE-like functionality. Now a JAX-RS resource can allow multiple clients to register for events - then send them on a schedule, randomly, at the request of other clients, with very little code.
To enable JAX-RS 2.1, add the definition to your `server.xml`:
[source,xml]
----
<featureManager>
<feature>jaxrs-2.1</feature>
</featureManager>
----
For more info:
* https://www.linkedin.com/pulse/my-favorite-part-jax-rs-21-implementers-view-j-andrew-mccright/[My favourite part of JAX-RS 2.1: An implementer's view]
* https://www.ibm.com/support/knowledgecenter/SSEQTP_liberty/com.ibm.websphere.wlp.doc/ae/twlp_dep_jaxrs21.html[JAX-RS 2.1 (Knowledge Center)]
* https://www.ibm.com/support/knowledgecenter/SSEQTP_liberty/com.ibm.websphere.wlp.doc/ae/cwlp_jaxrs21_behavior.html[Changes between JAX-RS 2.0 and JAX-RS 2.1 (Knowledge Center)]
* https://jcp.org/en/jsr/detail?id=370[JAX-RS 2.1 spec]
* https://jax-rs.github.io/apidocs/2.1/[JAX-RS 2.1 Javadoc]
[#cdi]
== Asynchronous events, event ordering, and more with CDI 2.0
CDI 2.0 provides the following support:
* Activate Request Context - Some third-party framework developers might want to have their own request lifecycle and have a tight control of it without creating a custom context. Previously, it was not possible for application developers to activate Request Context. CDI 2.0 added this support so that some unnecessary custom Request Scoped creation can be avoided.
* Event ordering and asynchronous events - Prior to CDI 2.0, it was not possible to order the event notification. In CDI 2.0, use `@Priority` to order the synchronous event notifications. In CDI 2.0, you can fire and observe asynchronous events.
* Add Interceptor support to produced beans - CDI 2.0 adds interceptor support on a producer using InterceptionFactory so that the produced beans have interceptors applied.
* Provide a number of annotation literals - CDI uses annotation literals in various places. Previously, you needed to create annotation literal classes for some built-in scopes or qualifiers. In CDI 2.0, the APIs have the annotation literal provided so that the annotation literal for some useful scopes or qualifiers are provided by the CDI APIs.
For example, in order to find a Foo bean with the `Default` qualifier, before CDI 2.0 you needed to do the following:
[source,java]
----
@Inject Instance<Foo> foo;
public Foo getFoo() {
return instance.select(DefaultLiteral.INSTANCE).get();
}
public class DefaultLiteral extends AnnotationLiteral<Default> implements Default {
public static final DefaultLiteral INSTANCE = new DefaultLiteral();
private DefaultLiteral() {}
}
----
In CDI 2.0, you can do the following:
[source,java]
----
@Inject Instance<Foo> foo;
public Foo getFoo() {
return instance.select(Default.Literal.INSTANCE).get();
}
----
As you can see, in CDI 2.0, you can use `Default.Literal.INSTANCE`` to get the annotation of `Default`, which is a lot simpler.
* CDI SPI configurators - In CDI 1.x, using SPI is used to generate verbose and less elegant code. In CDI 2.0, the configurators solve this. These configurators are accessible in lifecycle container event when writing extensions.
To enable the CDI 2.0 feature, add the feature definition to your `server.xml`:
[source,xml]
----
<featureManager>
<feature>cdi-2.0</feature>
</featureManager>
----
[#servlet40]
== Write dynamic web applications with Servlet 4.0
Servlet 4.0 is the latest Java EE 8 version of the Servlet specification.
The `servlet-4.0` feature includes the new Servlet 4.0 features and functions, for example:
* Support for HTTP/2 push/promise.
* Support for HTTP trailers.
* `HttpServletRequest.getServletMapping()`
* `ServletContext.getSessionTimeout() and setSessionTimeout()`
* `ServletContext.addJspFile()`
* Support for new elements in `web.xml`:
** `default-context-path`
** `request-character-encoding`
** `response-character-encoding`
To enable the Servlet 4.0 feature, add the feature definition to your `server.xml`:
[source,xml]
----
<featureManager>
<feature>servlet-4.0</feature>
</featureManager>
----
For more info:
* https://www.ibm.com/support/knowledgecenter/en/SSEQTP_liberty/com.ibm.websphere.wlp.doc/ae/twlp_config_servlet40.html[Servlet 4.0 (Knowledge Center)]
* https://javaee.github.io/servlet-spec/[Java Servlet spec]
[#http2]
== HTTP/2 protocol support
HTTP/2 is an optimization of the HTTP/1.1 protocol. Use of the HTTP/2 protocol is initiated by the client and accepted by the server. Web applications that involve numerous HTTP/1.1 sessions per webpage can see a significant performance improvement by opting into HTTP/2. Much of the optimization is achieved by allowing multiple HTTP/1.1 sessions to be transacted in parallel over one initial upgraded HTTP/1.1 connection.
Secure HTTP/2 (h2) uses ALPN (Application-Layer Protocol Negotiation) to upgrade the protocol of an HTTP/1.1 session to HTTP/2. Insecure HTTP/2 (h2c) can be negotiated via an HTTP/1.1 Upgrade header. The HTTP/2 protocol then allows for full-duplex communication of HTTP/1.1 traffic between client and server over this one upgraded connection. Both client and server have to opt into the HTTP/2 protocol with the ALPN handshake being initiated by the client.
Servlet 4.0 makes use of the HTTP/2 protocol to implement the Servlet 4.0 Server Push APIs, and HTTP/2 is enabled when the Servlet 4.0 Liberty feature is enabled.
If the Servlet 3.1 Liberty feature is enabled instead of Servlet 4.0, HTTP/2 is off by default but can be enabled by setting the `protocolVersion = "http/2"` attribute of the `httpEndpoint` element.
For more info, see:
* https://www.ibm.com/support/knowledgecenter/en/SSEQTP_liberty/com.ibm.websphere.wlp.nd.multiplatform.doc/ae/cwlp_servlet40_http2.html[HTTP/2 in Servlet 4.0 (Knowledge Center)]
* https://www.ibm.com/support/knowledgecenter/en/SSEQTP_liberty/com.ibm.websphere.wlp.doc/ae/cwlp_alpnsupport.html[ALPN support (Knowledge Center)]
* https://tools.ietf.org/html/rfc7540[HTTP protocol specification]
* https://jcp.org/en/jsr/detail?id=369[Servlet 4.0 specification]
[#jsf]
== Build user interfaces for web application with JavaServer Faces (JSF) 2.3
Take advantage of the latest JSF features and enhancements. The `jsf-2.3` feature pulls in the Apache MyFaces implementation and integrates it into the Liberty runtime. The new JSF 2.3 capabilities include:
* `<f:importConstants/>`
* Enhanced component search facility
* DataModel implementions can be registered
* CDI replacement for `@ManagedProperty`
* UIData and `<ui:repeat>` support for Map and Iterable
* `<ui:repeat>` condition check
* Java Time support
* WebSocket integration using `<f:websocket>`
* Multi-field validation using `<f:validateWholeBean>`
* Use CDI for evaluation of JSF-specific Expression Language implicit objects
* Support `@Inject` on JSF-specific artifacts
* Ajax Method Invocation. See vdldoc for `<h:commandScript>`
* Add `PartialViewContext.getEvalScripts()` method which returns a mutable list of scripts
With the delivery of JSF 2.3 you can also use your own JSF 2.3 implementation using the `jsfContainer-2.3` feature.
To enable the JSF 2.3 feature, add the feature definition to your `server.xml`:
[source,xml]
----
<featureManager>
<feature>jsf-2.3</feature>
</featureManager>
----
The CDI 2.0 feature is now available (`cdi-2.0`) and should be used with the `jsf-2.3` feature.
For more info:
* https://www.ibm.com/support/knowledgecenter/en/SSEQTP_liberty/com.ibm.websphere.wlp.doc/ae/twlp_config_jsf23.html[JSF 2.3 (Knowledge Center)]
* https://myfaces.apache.org/[Apache MyFaces]
* https://javaee.github.io/javaserverfaces-spec/[JSF 2.3 spec]
[#jpa]
== Interact with databases with Java Persistence API (JPA) 2.2
Java 8 introduced a new Date and Time API, which is more powerful than the old APIs part of java.util for years. Collection streaming, introduced in Java 8, is now formally supported by the JPA 2.2 specification, enabling new ways to process query result sets. Many JPA annotations are now repeatable, eliminating the need to use grouping annotations.
To enable the JPA 2.2 feature, add the feature definition to your `server.xml`:
[source,xml]
----
<featureManager>
<feature>jpa-2.2</feature>
</featureManager>
----
This enables JPA 2.2 and the EclipseLink 2.7 JPA persistence provider that is bundled with the feature. If you prefer to use your own EclipseLink 2.7 binaries, you can instead enable the `<feature>jpaContainer-2.2</feature>` feature, which provides JPA 2.2 container integration but does not enable the provided EclipseLink JPA provider implementation.
Examples of JPA 2.2 Enhancements:
=== @Repeatable Annotations
Before JPA 2.2:
[source,java]
----
@PersistenceContexts(
@PersistenceContext(name=“foo”, unitName=“bar”),
@PersistenceContext(name=“cloud”, unitName=“sky”))
@Stateless
public class SomeEJB {
…
----
With JPA 2.2:
[source,java]
----
@PersistenceContext(name=“foo”, unitName=“bar”),
@PersistenceContext(name=“cloud”, unitName=“sky”)
@Stateless
public class SomeEJB {
…
----
=== JPA 2.2 Supports java.time Types
[source,java]
----
@Entity
public class MyEntity {
…(truncated)…