back to all blogsSee all blog posts

More Jakarta EE 9 features and gRPC support in Open Liberty 20.0.0.9 beta

image of author
Laura Cowen on Aug 5, 2020

We now have two beta packages for Open Liberty:

This means that you can now try out our in-development Open Liberty features by just adding the relevant coordinates to your build tools (either the Jakarta EE 9 Beta Features package or the All Beta Features package, depending on what you want to try).

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

Jakarta EE 9 Beta Features package

The main change visible to developers in the Jakarta EE 9 planned release is the names of packages changing to accomodate the new jakarta.* namespace. In this Open Liberty beta, we have more Jakarta EE 9 features with their name change completed. We’ve also made excellent TCK progress with these features.

This Open Liberty beta introduces the following Jakarta EE 9 features which now possess their all-new Jakarta EE 9 package names:

  • Jakarta XML Binding 3.0 (jaxb-3.0)

  • Jakarta Managed Beans 2.0 (managedBeans-2.0)

  • Jakarta Concurrency 2.0 (concurrent-2.0)

  • Jakarta Enterprise Beans Home 4.0 (ejbHome-4.0)

  • Jakarta Enterprise Beans Lite 4.0 (ejbLite-4.0)

  • Jakarta Bean Validation 3.0 (beanValidation-3.0)

  • Jakarta Contexts and Dependency Injection 3.0 (cdi-3.0)

  • Jakarta WebSocket 2.0 (websocket-2.0; currently the integration with CDI is not completed)

  • Jakarta Persistence 3.0 (jpa-3.0)

These join the Jakarta EE 9 features in previous Open Liberty betas:

  • JDBC 4.2 & 4.3 (jdbc-4.2 & jdbc-4.3)

  • Jakarta Transactions 2.0 (transaction-2.0)

  • Jakarta JSON Binding 2.0 (jsonb-2.0)

  • Jakarta JSON Processing 2.0 (jsonp-2.0)

  • Jakarta Servlet 5.0 (servlet-5.0)

  • Jakarta Server Pages 3.0 (jsp-3.0)

  • Jakarta Expression Language 4.0 (el-4.0)

Try it now

To try out these Jakarta EE 9 features on Open Liberty in a lightweight package, just update your build tools to pull the Open Liberty Jakarta EE 9 Beta Features package instead of the main release. The beta works with Java SE 14, 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>20.0.0.9-beta</version>
    <type>zip</type>
</dependency>

Or for Gradle:

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

Or take a look at our Downloads page.

Enable the Jakarta EE 9 beta features in your app’s server.xml. You can enable the individual features you want (but remember if you enable the jsp-3.0 feature, the servlet-5.0 and el-4.0 features are automatically enabled for you) or you can just add the Jakarta EE 9 convenience feature to enable all of the Jakarta EE 9 beta features at once:

  <featureManager>
    <feature>jakartaee-9.0</feature>
  </featureManager>

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

  <featureManager>
    <feature>webProfile-9.0</feature>
  </featureManager>

TCK progress

TCKs are the tests that we run to ensure that the implementation of a feature meets the Jakarta EE 9 spec. Every implementation, including Open Liberty, must run the TCKs and pass them before the implementation can be considered "Jakarta EE compatible". We’re running the TCKs for the Jakarta EE 9 specs and fixing any problems as we go so that we can be sure that all the features will pass 100% of the tests by the time we release the Jakarta EE 9 features for real. So far, particularly good progress has been made for the EJB Lite, Concurrency, and WebSocket features in this beta. So things are going well.

All Beta Features package

As well as the Jakarta EE 9 features listed above, the new All Beta Features package contains our new gRPC and gRPC Client features which have been available in our nightly builds for a few weeks but are now easy to install from Maven Central too.

Provide and consume gRPC services from your web applications

gRPC is a high-performance, open source universal RPC framework. gRPC support on Liberty allows developers to both provide and consume gRPC services from your web applications. The introduction of gRPC support in Open Liberty now means you can take advantage of the benefits of gRPC more easily than before. Those benefits include great performance, simple service definitions via Protocol Buffers, cross-platform and language support, and wide industry adoption.

Two features are available in beta: grpc-1.0, which enables gRPC services, and grpcClient-1.0, which enables the use of a gRPC client for outbound calls.

The grpc-1.0 feature works by scanning web apps for gRPC service implementations, through implementors of io.grpc.BindableService. The web app must include the protocol buffer compiler-generated code for the services it intends to provide, and additionally the service class must provide a no-argument constructor. The web app does not need to include any core gRPC libraries; those are provided by the Liberty runtime. Once a gRPC service is scanned and started, it becomes accessible to remote gRPC clients on the configured HTTP ports.

The grpcClient-1.0 feature provides applications with access to a Netty gRPC client, as well as the related libraries. A web app must provide a client implementation and stubs, and can make outbound calls with a io.grpc.ManagedChannel without needing to provide the supporting client libraries.

Try out gRPC with the following basic Hello World service (add the grpc-1.0 to the server.xml):

package com.ibm.ws.grpc;

import com.ibm.ws.grpc.beans.GreetingBean;

import io.grpc.examples.helloworld.GreeterGrpc;
import io.grpc.examples.helloworld.HelloReply;
import io.grpc.examples.helloworld.HelloRequest;
import io.grpc.stub.StreamObserver;

public class HelloWorldService extends GreeterGrpc.GreeterImplBase {

    public HelloWorldService(){}

    @Override
    public void sayHello(HelloRequest req, StreamObserver<HelloReply> responseObserver) {
        HelloReply reply = HelloReply.newBuilder().setMessage("Hello " + req.getName()).build();
        responseObserver.onNext(reply);
        responseObserver.onCompleted();
    }
}

For this example, the application must provide the helloworld protof definition along with the protobuf compiler output. No additional libraries need to be provided with the application, and once it’s started the helloworld greeter service will be accessible on the server’s HTTP endpoints.

For a client example, a basic Servlet using gRPC can be defined via grpcClient-1.0 with:

package com.ibm.ws.grpc;

import io.grpc.examples.helloworld.GreeterGrpc;
import io.grpc.examples.helloworld.HelloReply;
import io.grpc.examples.helloworld.HelloRequest;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
...
@WebServlet(name = "grpcClient", urlPatterns = { "/grpcClient" }, loadOnStartup = 1)
public class GrpcClientServlet extends HttpServlet {

        ManagedChannel channel;
        private GreeterGrpc.GreeterBlockingStub greetingService;

        private void startService(String address, int port)
        {
            channel = ManagedChannelBuilder.forAddress(address , port).usePlaintext().build();
            greetingService = GreeterGrpc.newBlockingStub(channel);
        }

        private void stopService()
        {
            channel.shutdownNow();
        }

        @Override
        protected void doGet(HttpServletRequest reqest, HttpServletResponse response)
            throws ServletException, IOException
        {

            // set user, address, port params
        }

        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
        {

        // grab user, address, port params
        startService(address, port);
        HelloRequest person = HelloRequest.newBuilder().setName(user).build();
        HelloReply greeting = greetingService.sayHello(person);

        // send the greeting in a response
        stopService();
        }
    }
}

As with the service example, the application must provide the helloworld protof definition along with the protobuf compiler output. All required gRPC client libraries are provided by grpcClient-1.0.

Try it now

To try out these gRPC 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 14, 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>20.0.0.9-beta</version>
  <type>pom</type>
</dependency>

Or for Gradle:

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

Or take a look at our Downloads page.

To enable the new beta features in your app, add them to your server.xml:

  <featureManager>
    <feature>grpc-1.0</feature>
    <feature>grpcClient-1.0</feature>
  </featureManager>

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