Contents
Jakarta EE
Enterprise Java: servlets, CDI, JAX-RS, JPA, transactions and application servers.
1.Getting started
- What is Jakarta EEWhere Jakarta EE came from, how specifications differ from implementations, what an application server is and where the platform is used today.
- Project and server startCreating the blog project with the Open Liberty generator, a look at pom.xml with the jakarta.jakartaee-api dependency, the server.xml file and starting the server with liberty:dev.
- The first servletWhat a servlet is, how the @WebServlet annotation binds a class to an address and how the server calls the doGet method.
- Request and responseReading parameters and headers from HttpServletRequest, setting the status code, headers and a redirect through HttpServletResponse.
- FiltersA servlet filter runs shared code before and after a request is handled: logging, headers, checks.
2.Jakarta REST
- Jakarta REST resourcesHow to enable Jakarta REST in an application, what a resource is and how the @Path, @GET and @Produces annotations turn a class into a REST API.
- Request parametersHow a resource method gets part of the path, query string parameters, headers and form fields: @PathParam, @QueryParam, @DefaultValue, @HeaderParam and @FormParam.
- JSON and JSON-BHow a Jakarta REST resource returns and accepts JSON: records as data models, an in-memory store for blog posts and tuning JSON with JSON-B annotations.
- Status codes and ResponseHow to return the right HTTP status from a resource: the Response class, 201 Created with a Location header, 204 No Content and 404 Not Found.
- Exception mappersHow an ExceptionMapper turns application exceptions into clear API responses with a JSON error description.
3.CDI and validation
- Beans and injectionWhat CDI is, which classes become beans and how @Inject passes objects into resources, servlets and other beans.
- ScopesHow long a bean lives: @ApplicationScoped, @SessionScoped, @RequestScoped and @Dependent, shown with a view counter and a reading history.
- Producers and qualifiersHow to turn an object of someone else's class into a bean with @Produces and how to tell beans of the same type apart with qualifiers.
- CDI eventsHow one bean announces that something happened through Event, while other beans react with @Observes and @ObservesAsync methods without knowing about each other.
- Bean ValidationValidating input with @NotBlank, @Size and @Min, the automatic 400 response in Jakarta REST and a validation error mapper with JSON.
4.Working with a database
- Jakarta PersistenceConnecting an H2 database to Open Liberty, describing a data source in server.xml, setting up persistence.xml and moving blog posts to a JPA entity and EntityManager.
- Transactions and @TransactionalHow the server manages transactions: the @Transactional annotation, rollback on an exception shown with a post import, and TxType modes.
- Jakarta DataA new Jakarta EE 11 specification: a repository interface with @Repository, the built-in CrudRepository methods, the link to the persistence unit and injecting the repository into a resource.
- Queries in Jakarta DataYour own repository methods: queries by method name, the @Find and @By annotations, @Query in JDQL, sorting and pagination with PageRequest and Order.
5.Faces, security and release
- Jakarta FacesServer-side pages with Jakarta Faces: a Facelets file, a page bean with @Named, rendering a list and a form with validation. Why know Faces when new interfaces are built differently.
- Jakarta SecurityHTTP Basic login, your own IdentityStore of users, roles and protecting methods with @RolesAllowed, information about the signed-in user through SecurityContext.
- MicroProfile Config and HealthApplication settings with MicroProfile Config, overridden from environment variables, and MicroProfile Health checks for orchestrators.
- TestingHow to test a Jakarta EE application: unit tests of beans without a server, integration tests with HTTP requests to a running Open Liberty and tools such as Arquillian.
- Packaging and deploymentHow to build a WAR, deploy it to an installed server, package the application together with Open Liberty into a runnable JAR and a Docker image, and what changes on other Jakarta EE servers.