Program reactively in a type-safe RESTful client, define security tokens in a container-neutral way to simplify deployment, and enable all the MicroProfile features in a convenient way in the August/September 2018 beta of WebSphere Liberty.

Thanks to your support for our regular beta programme, we are able to release new Liberty features every few months. We recently released WebSphere Liberty 18.0.0.2, built on Open Liberty 18.0.0.2.

Look out for more betas over the coming months. If you just can’t wait, take a look at the daily builds of Open Liberty.

Follow Open Liberty happenings on @OpenLibertyIO.

What’s new in this beta?

Get it now! Ask a question about the beta

Program reactively in a type-safe RESTful client (MicroProfile Rest Client 1.1)

MicroProfile Rest Client 1.1 expands on the 1.0 version by providing asynchronous method support using Java 8’s CompletionStage APIs. It also allows better integration with other MicroProfile technologies and third parties and adds support for URIs.

The new async method support makes reactive programming possible in a type-safe RESTful client. Prior to this feature, you would either have to sacrifice type-safety and use the JAX-RS 2.X Client APIs to get asynchronous/reactive support, or sacrifice async/reactive support for type-safety. No more!

The other improvements are minor in nature but still make life easier for developers. You no longer need to specify the @Dependent annotation on REST client interfaces when used with CDI. You can also use URIs, which can be constructed without throwing a MalformedURLException, saving a few lines of unnecessary try/catch blocks.

REST client interface methods that return a CompletionStage are treated as asynchronous:

...
MyClient client = RestClientBuilder.newBuilder()
                                   .executorService(executor)
                                   .build(MyClient.class);
CompletionStage<Widget> cs = client.getWidget(widgetId);
cs.thenApply(...);
...
@Path("/widget")
public interface MyClient {
    @GET
    @Path("/{widgetId}"
    CompletionStage<Widget> getWidget(@PathParam("widgetId") String widgetId);
}

Learn about MicroProfile Rest Client in Consuming RESTful services with template interfaces.

To enable the MicroProfile Rest Client 1.1 feature, add it to the server.xml:

<featureManager>
  <feature>mpRestClient-1.1</feature>
</featureManager>

For more info, see:

Verify security tokens in a container-neutral way to simplify deployment (MicroProfile JWT 1.1)

Previously, a server using MicroProfile JWT had to be specifically configured to define token issuers and store or obtain the public keys used to validate the JWT tokens. Now this information can be included in an app, or supplied directly in, or referenced by, system properties or environment variables.

MicroProfile JWT 1.0 allows authentication and identity propagation using JWT tokens. However the mechanism for configuring the token issuers, public keys or JWKS URLs used for token validation is container-specific. MicroProfile JWT 1.1 uses MicroProfile Config 1.x to allow token issuers, public keys, and JWKS URLs to be defined at the server or in an application in a container-neutral way. This simplifies deployment and improves interoperability. MicroProfile JWT 1.1 also adds Authentication Filter support, so MicroProfile JWT authentication can be limited to a subset of application URLs.

Learn about MicroProfile JWT in Securing microservices with JSON Web Tokens.

To enable the MicroProfile JWT 1.1 feature:

  1. Add the mpJwt-1.1 and appSecurity-2.0 features to the server.xml and, optionally, define an mpJwt configuration if configuration beyond public keys and issuers is needed:
    <featureManager>
      <feature>mpJwt-1.1</feature>
    <feature>appSecurity-2.0</feature>
    </featureManager>
    
    <mpJwt id="myMpJwt" ... />
    
  2. Supply either the token issuer and public key or the public key retrieval path or URL that will be used to retrieve the key. These can be system properties, environment variables, or entries in a microprofile-config.properties file within an application. For example, add to the microprofile-config.properties file one of the following entries:
    •     mp.jwt.verify.publickey.location=/META-INF/orange.pem
      
    •     mp.jwt.verify.publickey=(pkcs#8 key goes here)
      
          mp.jwt.verify.issuer=https://server.example.com
      

      For UNIX and Linux platforms (which do not accept dots in environment variables), use _.

For more info, see:

Conveniently enable all MicroProfile 2.0 or MicroProfile 1.4 features

Enable all the MicroProfile 2.0 features or all the MicroProfile 1.4 features at once with the new convenience features. MicroProfile 2.0 is based on Java EE 8 technologies while MicroProfile 1.4 is based on Java EE 7 technologies.

To enable MicroProfile 2.0 features:

<featureManager>
  <feature>microProfile-2.0</feature>
</featureManager>

This is the equivalent of individually enabling the following features: jaxrs-2.1, cdi-2.0, jsonp-1.1, jsonb-1.0, mpConfig-1.3, mpFaultTolerance-1.1, mpHealth-1.0, mpJwt-1.1, mpMetrics-1.1, mpOpenAPI-1.0, mpOpenTracing-1.1, mpRestClient-1.1.

To enable MicroProfile 1.4 features:

<featureManager>
  <feature>microProfile-1.4</feature>
</featureManager>

This is the equivalent of individually enabling the following features: jaxrs-2.0, cdi-1.2, jsonp-1.0, mpConfig-1.3, mpFaultTolerance-1.1, mpHealth-1.0, mpJwt-1.1, mpMetrics-1.1, mpOpenAPI-1.0, mpOpenTracing-1.1, mpRestClient-1.1.

New to MicroProfile? Try building a RESTful web service with Liberty and MicroProfile.

What’s already in there?

The early August Liberty beta included easily and dynamically updating your Java microservice configuration by adding or modifying variables in the Liberty server configuration with MicroProfile Config 1.3.

Looking for the latest?

If you’re visiting this post from the future and you’re looking for the latest releases of Liberty, here are the links you’re looking for:

Latest beta release
Latest stable release
Open Liberty downloads

Get it now! Ask a question on Stack Overflow

Join The Discussion

Your email address will not be published. Required fields are marked *