Skip to content

HTTP Server Microservice Provider

Radek Koubsky edited this page Nov 23, 2017 · 17 revisions

This provider allows deploying a servlet into a servlet container and exposing microservices via REST. In addition, REST endpoints can be secured via SSL. The underlying web server is represented by Undertow, a flexible, performant and fully embeddable web server based on NIO.

Content

  1. Configuration
  2. Exposing microservices via REST
    1. JAXB and JSON support
    2. Securing REST microservices
  3. Usage

Configuration

HTTP Server Microservice Provider contains the following set of configuration properties:

  • silverware.http.address - property with the hostname/IP address where the server is accessed, default value=0.0.0.0
  • silverware.http.port - property with the HTTP port number on which the server listens, default value=8080

Exposing microservices via REST

A microservice in SilverWare can be exposed via REST using JAX-RS 2.0 annotations. SilverWare scans all microservices annotated by JAX-RS annotations and adds each one as a web resource to RESTEasy deployment in Undertow. When a REST microservice instance is created, SilverWare looks up the microservice in all providers and then returns the correct microservice instance that has all other microservices injected via CDI. The injection of other microservices into the REST microservice instance is provided by CDI Microservice Provider.

To configure REST in SilverWare, the following set of properties is defined:

  • silverware.http.rest.context.path - the context path where microservice web resources are exposed, default value=silverware
  • silverware.http.rest.servlet.mapping.prefix - configure the resteasy.servlet.mapping.prefix property in RESTEasy, default value=rest

JAXB and JSON support

Currently, HTTP Microservice Provider uses the following features in RESTEasy

Securing microservices

A REST microservice can be secured using SSL. To configure SSL properly, the following set of properties is provided:

  • silverware.http.server.ssl.enabled - main property enabling/disabling SSL in SilverWare, default value=false
  • silverware.https.port - property with the HTTPS port number on which the server listens, default value=10443
  • silverware.http.server.keystore - keystore used in SSL context, default value=silverware-server.keystore
  • silverware.http.server.keystore.password - password to the server keystore file, default value=silverware
  • silverware.http.server.truststore - truststore used in SSL context, default value=silverware-server.truststore
  • silverware.http.server.truststore.password - password to the server truststore file, default value=silverware

If a user wants to use custom keystore/truststore, they must provide both keystore and truststore, otherwise default SSL configuration will be used.

The keystore and truststore properties can contain:

  • absolute path of the keystore/truststore on a filesystem e.g. /etc/ssl/my_keystore.keystore
  • specific path on classpath e.g. silverware-server.keystore (the file is located in the root of the classpath)

When the SSL property is enabled, HTTP requests to the REST microservices are redirected to HTTPS.

Usage

The following microservice MyRestService is a REST microservice that has MicroserviceA microservice injected via CDI.

   @Path("helloservice")
   @Microservice
   public class MyRestService {
      @Inject
      @MicroserviceReference
      private MicroserviceA msA;

      @GET
      @Produces(MediaType.TEXT_PLAIN)
      @Path("hello")
      public Response sayHello() {
         System.out.println("Redirecting to " + MicroserviceA.class.getName());
         return Response.ok(this.msA.hello()).build();
      }
   }

The injected MicroserviceA microservice:

   @Microservice
   public class MicroserviceA {
      public String hello() {
         return "Hello from " + this.getClass().getName();
      }
   }

With default configuration, we can access the MyRestService microservice on url 0.0.0.0:8080/silverware/rest/helloservice/hello.