Jakarta Enterprise Edition (JEE)

Jakarta Enterprise Edition (JEE) is a fully open source Java Enterprise Edition based off version 8 including a change of package names from javax to jakarta (due to trademark issues during the open-sourcing process). The umbrella project to manage Jakarta EE is Eclipse Enterprise for Java (EE4J) and various Jakarta EE specifications are available.

Many of the patterns available in Java Enterprise Edition remain available in Jakarta EE and are not repeated here.

Jakarta RESTful client

  1. Create and cache the WebTarget instead of re-creating it for every call
    @Path("/client-test2")
    public class ClientTestCached {
    
      private static WebTarget cachedWebTarget = ClientBuilder.newBuilder().build().target("http://localhost:9081/endpoint");
    
      @GET
      @Produces(MediaType.TEXT_PLAIN)
      public String ping() {
        return cachedWebTarget.request().get(String.class);
      }
    }

JSON processing

  1. Create and cache a Factory first, and then create the reader, writer, or object builder from that factory
    @Path("/json-test2")
    public class JsonTest2 {
    
      private static final JsonBuilderFactory jsonBuilderFactory = Json.createBuilderFactory(null);
    
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      public JsonObject ping() {
        JsonObjectBuilder jsonObjectBuilder = jsonBuilderFactory.createObjectBuilder();
        return jsonObjectBuilder.add("example", "example").build();
      }
    }