back to all blogsSee all blog posts

Configurable Response Headers and more exciting new features in Open Liberty 21.0.0.11-beta

image of author
Ryan Storey on Oct 5, 2021

Open Liberty 21.0.0.11-beta provides new configurable response headers, which offer more granular control over response headers. This beta release also introduces important changes to the Jakarta EE convenience features, with the removal of Jakarta EE 9.0 features in the transition to Jakarta EE 9.1.

We have two beta packages for Open Liberty:

  • All Beta Features: a larger package that contains all Open Liberty beta features (including Jakarta EE 9.1 beta features) and GA features and functions.

  • Jakarta EE 9.1 Beta Features: a lightweight package that contains only the Jakarta EE 9.1 features.

This means that you can now try out our in-development Open Liberty features by just adding the relevant coordinates to your build tools.

If you try either package, let us know what you think.

All Beta Features package

The All Beta Features package includes the following beta features:

Configurable Response Headers

You can now configure Open Liberty (21.0.0.11-beta) to modify response headers. The configuration options enable you to:

  • append headers;

  • overwrite existing headers;

  • add missing headers; and

  • remove undesired headers from all responses that are serviced by an HTTP endpoint.

This granular control over response headers means you can modify headers without having to modify existing applications or filters.

Try it out!

To use configurable response headers, begin by defining a new element called headers in the server.xml. You can configure this for individual HTTP endpoints or for all endpoints at once.

To configure the headers element for an individual endpoint, specify the element inside the httpEndpoint configuration for that endpoint:

<httpEndpoint id="defaultHttpEndpoint"
                  httpPort="9080"
                  httpsPort="9443" >

       <headers>
            <add>foo:bar</add>
            <add>foo:bar2</add>
            <set>customHeader:customValue</set>
            <setIfMissing>X-Forwarded-Proto:https</setIfMissing>
            <remove>Via</remove>
       </headers>

</httpEndpoint>

To configure the headers element once to apply to multiple endpoints in your configuration, specify it as a peer of httpEndpoint and then reference it in each httpEndpoint element with the headersRef attribute:

 <httpEndpoint id="defaultHttpEndpoint"
                         httpPort="9080"
                         httpsPort="9443"
                         headersRef="myHeadersID">
     </httpEndpoint>

     <httpEndpoint id="otherHttpEndpoint"
                         httpPort="9081"
                         httpsPort="9444"
                         headersRef="myHeadersID">
    </httpEndpoint>

     <headers id="myHeadersID">
            <add>foo:bar</add>
            <add>foo:bar2</add>
            <set>customHeader:customValue</set>
            <setIfMissing>X-Forwarded-Proto:https</setIfMissing>
            <remove>Via</remove>
     </headers>

The add attribute allows multiple headers with the same name to be added to a response, similar to the HttpServletResponse’s addHeader API. Similarly, the set attribute is analogous to the setHeader API, which sets a response header to the given name and value. This overwrites existing headers that share the same name. The setIfMissing attribute sets the configured headers only if they are not already present on the response. Lastly, the remove attribute removes any response headers with a name that matches the value that is specified in the attribute.

Try it now

To try out these features, just update your build tools to pull the Open Liberty All Beta Features package instead of the main release. The beta works with Java SE 17, Java SE 11, or Java SE 8.

If you’re using Maven, here are the coordinates:

<dependency>
  <groupId>io.openliberty.beta</groupId>
  <artifactId>openliberty-runtime</artifactId>
  <version>21.0.0.11-beta</version>
  <type>pom</type>
</dependency>

Or for Gradle:

dependencies {
    libertyRuntime group: 'io.openliberty.beta', name: 'openliberty-runtime', version: '[21.0.0.11-beta,)'
}

Or take a look at our Downloads page.

Jakarta EE 9.1 Beta Features package

As documented in the release of Open Liberty 21.0.0.8-beta, the convenience features jakartaee-9.0, jakarteeClient-9.0 and webProfile-9.0 have now been deleted in Open Liberty 21.0.0.11-beta, and completely replaced by jakartaee-9.1, jakarteeClient-9.1 and webProfile-9.1.

Enable the Jakarta EE 9.1 beta features in your server.xml. You can enable the individual features you want or you can just add the Jakarta EE 9.1 convenience feature to enable all of the Jakarta EE 9.1 beta features at once:

  <featureManager>
    <feature>jakartaee-9.1</feature>
  </featureManager>

Or you can add the Web Profile convenience feature to enable all of the Jakarta EE 9.1 Web Profile beta features at once:

  <featureManager>
    <feature>webProfile-9.1</feature>
  </featureManager>

Try it now

To try out these Jakarta EE 9.1 features on Open Liberty in a lightweight package, just update your build tools to pull the Open Liberty Jakarta EE 9.1 Beta Features package instead of the main release. The beta works with Java SE 17, Java SE 11, or Java SE 8.

If you’re using Maven, here are the coordinates:

<dependency>
    <groupId>io.openliberty.beta</groupId>
    <artifactId>openliberty-jakartaee9</artifactId>
    <version>21.0.0.11-beta</version>
    <type>zip</type>
</dependency>

Or for Gradle:

dependencies {
    libertyRuntime group: 'io.openliberty.beta', name: 'openliberty-jakartaee9', version: '[21.0.0.11-beta,)'
}

Or take a look at our Downloads page.

Your feedback is welcomed

Let us know what you think on our mailing list. If you hit a problem, post a question on StackOverflow. If you hit a bug, please raise an issue.

Tags