Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building Microservices with Java EE 8 and Micro...

Building Microservices with Java EE 8 and MicroProfile

With Java EE 8 finally released and the latest additions to MicroProfile it is about time we have a closer look at how to develop modern and lightweight microservices with the latests API improvements. This session is a comprehensive guide showing how to develop state-of-the-art microservices with the latest Java EE 8 APIs. We will start by giving an overview of Java EE 8 and the latest API additions and improvements. Then we will implement, build and package our first working Java EE 8 microservice. We will then dive into the details of implementing synchronous RESTful web services, and learn about the specifics of data binding and content marshalling using the JSON-B and JSON-P APIs. We will see how to leverage the power of using the asynchronous APIs on the server as well as the client-side, and how Server-Sent-Events (SSE) can be used for push communication. Finally we will cover some advanced topics such as validation, security, resiliency, health checks and diagnosability.

M.-Leander Reimer

October 09, 2018
Tweet

More Decks by M.-Leander Reimer

Other Decks in Programming

Transcript

  1. CDI Extensions Web Fragments Bean Validation 2.0 CDI 2.0 Managed

    Beans 1.0 JCA 1.7 JPA 2.2 JMS 2.0 JSP 2.3 EL 3.0 EJB 3.2 Batch 1.0 JSF 2.3 Interceptors 1.2 Mail 1.6 Common Annotations 1.3 JTA 1.2 JAX-WS 1.4 JAX-RS 2.1 Concurrency 1.0 JSON-P 1.1 JSON-B 1.0 WebSocket 1.1 JAPSIC 1.1 JACC 1.5 Security 1.0 Servlet 4.0 JCache 1.0
  2. @ApplicationPath("api") public class JAXRSConfiguration extends Application { } @Path("hello") public

    class HelloWorldResource { @GET @Produces(MediaType.APPLICATION_JSON) public JsonObject helloWorld() { String hostname = ofNullable(getenv("HOSTNAME")).orElse("localhost"); return Json.createObjectBuilder() .add("message", "Cloud Native Application Development with Java EE.") .add("hostname", hostname) .build(); } }
  3. // JSON Patch is a web standard format for describing

    changes in a JSON document. // The JSON Patch media type is application/json-patch+json. [ { "op": "replace", "path": "/0/aString", "value": "Patched JSON-P." } ] JsonArray jsonArray = Json.createArrayBuilder() .add(Json.createObjectBuilder() .add("aString", "Hello Json-P.") .add("aInteger", 42) .add("aBoolean", false) .add("aNullValue", JsonValue.NULL)) .build(); JsonPatch jsonPatch = Json.createPatchBuilder(jsonPatchArray).build(); jsonPatch.apply(jsonArray) Add: add a value into an object or array. Remove: remove a value from an object or array. Replace: replaces a value. Logically identical to using remove and then add. Copy: copy a value from one path to another by adding the value at a specified to another location. Move: moves a value from one place to another by removing from one location and adding to another. Test: tests for equality at a certain path for a certain value.
  4. JsonbConfig jsonbConfig = new JsonbConfig() .withDateFormat("dd.MM.yyyy", Locale.GERMANY) .withFormatting(true) .withPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CASE_WITH_DASHES) .withNullValues(true)

    .withPropertyOrderStrategy(PropertyOrderStrategy.REVERSE); Jsonb jsonb = JsonbBuilder.newBuilder().withConfig(jsonbConfig).build(); String jsonBody = jsonb.toJson(jsonPojo); JsonbPojo jsonbPojo = jsonb.fromJson(jsonBody, JsonbPojo.class); @JsonbNillable public class JsonbPojo { @JsonbProperty(value = "greeting", nillable = true) private String message; @JsonbNumberFormat("#,##0.00") private Integer answerToEverything; @JsonbTransient private Object ignored; }