Jakarta EE Application Development - David R. Heffelfinger - E-Book

Jakarta EE Application Development E-Book

David R. Heffelfinger

0,0
28,79 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Jakarta EE stands as a robust standard with multiple implementations, presenting developers with a versatile toolkit for building enterprise applications. However, despite the advantages of enterprise application development, vendor lock-in remains a concern for many developers, limiting flexibility and interoperability across diverse environments.
This Jakarta EE application development guide addresses the challenge of vendor lock-in by offering comprehensive coverage of the major Jakarta EE APIs and goes beyond the basics to help you develop applications deployable on any Jakarta EE compliant runtime.
This book introduces you to JSON Processing and JSON Binding and shows you how the Model API and the Streaming API are used to process JSON data. You’ll then explore additional Jakarta EE APIs, such as WebSocket and Messaging, for loosely coupled, asynchronous communication and discover ways to secure applications with the Jakarta EE Security API. Finally, you'll learn about Jakarta RESTful web service development and techniques to develop cloud-ready microservices in Jakarta EE.
By the end of this book, you'll have developed the skills to craft secure, scalable, and cloud-native microservices that solve modern enterprise challenges.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 341

Veröffentlichungsjahr: 2024

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Jakarta EE Application Development

Build enterprise applications with Jakarta CDI, RESTful web services, JSON Binding, persistence, and security

David R. Heffelfinger

Jakarta EE Application Development

Copyright © 2024 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Group Product Manager: Kunal Sawant

Publishing Product Manager: Akash Sharma

Book Project Manager: Prajakta Naik

Senior Editor: Esha Banerjee

Technical Editor: Vidhisha Patidar

Copy Editor: Safis Editing

Indexer: Hemangini Bari

Production Designer: Shankar Kalbhor

DevRel Marketing Coordinator: Samriddhi Murarka

First published: December 2017

Second edition: February 2024

Production reference: 1160224

Published by

Packt Publishing Ltd.

Grosvenor House

11 St Paul’s Square

Birmingham

B3 1RB, UK

ISBN 978-1-83508-526-4

www.packtpub.com

Contributors

About the author

David R. Heffelfinger is an independent consultant based in the Washington D.C. area. He is a Java Champion and Apache Netbeans Project Management Committee.

He has written several books on Java EE, application servers, NetBeans, and JasperReports. His previous titles include Java EE 8 Application Development, Java EE 7 Development with NetBeans 8, Java EE 7 with GlassFish 4 Application Server, JasperReports 3.5 For Java Developers, among others.

David has spoken at various software conferences, including JavaOne and Oracle Code One, multiple times. He has also presented at NetBeans Day in both San Francisco and Montreal.

About the reviewers

Amol Gote is a seasoned technology professional adept at building scalable, resilient microservices in both Java and .NET. He excels in deploying and managing microservices in AWS and Azure environments, boasting technical proficiency across multiple applications and tools. His expertise spans full-stack capabilities, from designing to constructing end-to-end solutions that include databases (SQL/NoSQL), back-end services, messaging services, and modern interactive web applications using web sockets.

Currently serving as a Solutions Architect at a Fintech startup, Amol has built the underwriting platform from scratch, along with multiple horizontal and vertical business domain-specific microservices. Previously, he has engaged in consulting roles with major clients like Bank of America, Morgan Stanley, and the Associated Press, and has worked with Microsoft for seven years.

With over 18 years of experience, Amol is passionate about writing blogs and technical articles for online platforms like DZone, Baeldung, and InfoQ. He has also served as a judge and mentor at various Hackathon events. Amol’s commitment to excellence is evident in his multiple certifications, including AWS Certified Solutions Architect and various Microsoft certifications.

Edwin Derks is a Java Champion from The Netherlands who loves solving complex and strategic IT challenges. He is passionate about gathering and sharing knowledge about anything related to the Java ecosystem, composable architectures, and cloud-driven development in general. He contributes to MicroProfile and Jakarta EE and often speaks at conferences, passionately sharing his knowledge and experience.

In his spare time, he is a loving husband and a father of three. He can often be found in the gym or having a good time at dance parties or heavy metal concerts.

Table of Contents

Preface

1

Introduction to Jakarta EE

Introduction to Jakarta EE

Contributing to Jakarta EE

Jakarta EE APIs

One standard, multiple implementations

Jakarta EE, Java EE, J2EE, and the Spring Framework

Summary

2

Contexts and Dependency Injection

Named beans

Dependency injection

Qualifiers

CDI bean scopes

CDI events

Firing CDI events

Handling CDI events

Asynchronous events

Event ordering

CDI Lite

Summary

3

Jakarta RESTful Web Services

Introduction to RESTful web services

Developing a simple RESTful web service

Configuring the REST resources path for our application

Developing a RESTful web service client

Seamlessly converting between Java and JSON

Query and path parameters

Query parameters

Path parameters

Server-sent events

Testing server-sent events

Developing a server-sent events client

JavaScript server-sent events client

Summary

4

JSON Processing and JSON Binding

Jakarta JSON Processing

The JSON Processing Model API

The JSON Processing Streaming API

Jakarta JSON Binding

Populating Java objects from JSON with JSON Binding

Generating JSON data from Java objects with JSON Binding

Summary

5

Microservices Development with Jakarta EE

An introduction to microservices

The advantages of a microservices architecture

The disadvantages of a microservices architecture

Microservices and Jakarta EE

Developing microservices using Jakarta EE

Developing microservices client code

The controller service

The persistence service

Summary

6

Jakarta Faces

Introduction to Jakarta Faces

Facelets

Optional faces-config.xml

Standard resource locations

Developing our first Faces application

Facelets

Project stages

Validation

Grouping components

Form submission

Named beans

Static navigation

Dynamic navigation

Custom data validation

Creating custom validators

Validator methods

Customizing default messages

Customizing message styles

Customizing message text

Summary

7

Additional Jakarta Faces Features

Ajax-enabled Faces applications

Jakarta Faces HTML5 support

HTML5-friendly markup

Pass-through attributes

Faces Flows

Faces WebSocket support

Additional Faces component libraries

Summary

8

Object Relational Mapping with Jakarta Persistence

The CUSTOMERDB database

Configuring Jakarta Persistence

Persisting data with Jakarta Persistence

Entity relationships

One-to-one relationships

One-to-many relationships

Many-to-many relationships

Composite primary keys

Jakarta Persistence Query Language

Criteria API

Updating data with the Criteria API

Deleting data with the Criteria API

Bean Validation support

Final notes

Summary

9

WebSockets

Developing WebSocket server endpoints

Developing an annotated WebSocket server endpoint

Developing WebSocket clientsin JavaScript

Developing JavaScript client-side WebSocket code

Developing WebSocket clients in Java

Summary

10

Securing Jakarta EE Applications

Identity stores

Setting up an identity store stored in a relational database

Setting up an identity store stored in an LDAP database

Custom identity stores

Authentication mechanisms

Basic authentication mechanism

Form authentication mechanism

Custom form authentication mechanism

Summary

11

Servlet Development and Deployment

What is a servlet?

Writing our first servlet

Testing the web application

Processing HTML forms

Request forwarding and response redirection

Request forwarding

Response redirection

Persisting application data across requests

Passing initialization parameters to a servlet via annotations

Servlet filters

Servlet listeners

Pluggability

Configuring web applications programmatically

Asynchronous processing

HTTP/2 server push support

Summary

12

Jakarta Enterprise Beans

Session beans

A simple session bean

A more realistic example

Invoking session beans from web applications

Singleton session beans

Asynchronous method calls

Message-driven beans

Transactions in enterprise beans

Container-managed transactions

Bean-managed transactions

Enterprise bean life cycles

Stateful session bean life cycle

Stateless and singleton session bean life cycle

Message-driven bean life cycle

Enterprise bean timer service

Calendar-based enterprise bean timer expressions

Enterprise bean security

Summary

13

Jakarta Messaging

Working with message queues

Sending messages to a message queue

Retrieving messages from a message queue

Browsing message queues

Working with message topics

Sending messages to a message topic

Receiving messages from a message topic

Creating durable subscribers

Summary

14

Web Services with Jakarta XML Web Services

Developing web services with Jakarta XML Web Services

Developing a web service client

Sending attachments to web services

Exposing Enterprise Beans as web services

Enterprise Beans web service clients

Summary

15

Putting it All Together

The sample application

The landing page

Creating customer data

Viewing customer data

Updating customer data

Deleting customer data

Implementing pagination

Summary

Index

Other Books You May Enjoy

1

Introduction to Jakarta EE

Jakarta EE consists of a set of Application Programming Interface (API) specifications used to develop server-side enterprise Java applications. Most chapters in this book will cover a single Jakarta EE specification, such as Contexts and Dependency Injection (CDI), which is used to integrate different parts of an application, or Jakarta RESTful Web Services, which is used to develop RESTful web services. We also cover Jakarta EE APIs for processing data in JSON format, as well as Jakarta Faces, which is used to develop web-based user interfaces. We also delve into how to interact with relational databases, implementing two-way communication between clients and servers in web applications, security, and messaging.

In this chapter, we will cover the following topics:

Introduction to Jakarta EEJakarta EE, Java EE, J2EE, and the Spring Framework

Introduction to Jakarta EE

Jakarta EE is a collection of API specifications designed to work together when developing server-side enterprise Java applications. Jakarta EE is a standard for which there are multiple implementations. This fact prevents vendor lock-in since code developed against the Jakarta EE specification can be deployed in any Jakarta EE-compliant implementation.

Jakarta EE is an Eclipse Software Foundation project. Since the Jakarta EE specification is open source, any organization or individual wishing to contribute is free to do so.

Contributing to Jakarta EE

There are many ways of contributing, including participating in discussions and providing suggestions for future versions of Jakarta EE. To do so, one simply needs to subscribe to the appropriate mailing list, which can be done by visiting https://jakarta.ee/connect/mailing-lists/.

In order to subscribe to the mailing list, you need to create a free Eclipse.org account at https://accounts.eclipse.org/user/register.

To go beyond participating in discussions and actually contribute code or documentation, the Eclipse Contributor Agreement must be signed. The Eclipse Contributor Agreement can be found at https://www.eclipse.org/legal/ECA.php.

Jakarta EE APIs

As previously mentioned, Jakarta EE is a collection of API specifications designed to work together when developing server-side enterprise Java applications.

In addition to the full Jakarta EE platform, there are two Jakarta EE profiles that contain a subset of the specifications and APIs included in the full platform. The Jakarta EE Web Profile contains a subset of specifications and APIs suitable for developing web applications. The Jakarta EE Core Profile contains an even smaller subset of specifications and APIs more suitable for developing microservices.

The Jakarta EE core profile APIs include the following:

Jakarta Context and Dependency Injection Lite (CDI Lite)Jakarta RESTful Web ServicesJakarta JSON ProcessingJakarta JSON Binding

The version of Contexts and Dependency Injection API included in the core profile is a subset of the full specification. The Jakarta EE Web Profile APIs include the full CDI specification instead of CDI Lite, plus all other specifications and APIs in the core profile, along with some additional ones:

Jakarta Context and Dependency InjectionJakarta FacesJakarta PersistenceJakarta WebSocketJakarta SecurityJakarta ServletJakarta Enterprise Beans Lite

The version of Jakarta Enterprise Beans included in the Web Profile is a subset of the full enterprise beans specification.

The full Jakarta EE Platform includes the full Jakarta Enterprise Beans spec, plus all other specifications and APIs included in the Web Profile, along with some additional ones:

Jakarta Enterprise BeansJakarta MessagingJakarta Enterprise Web Services

Full list of Jakarta EE APIs

The preceding list is not exhaustive, and only lists some of the most popular Jakarta EE APIs. For an exhaustive list of Jakarta EE APIs, please refer to https://jakarta.ee/specifications/.

Application server vendors or the open-source community need to provide compatible implementations for each Jakarta EE API specification in the preceding list.

One standard, multiple implementations

At its core, Jakarta EE is a specification, a piece of paper, if you will. Implementations of Jakarta EE specifications need to be developed so that application developers can actually develop server-side enterprise Java applications against the Jakarta EE standard.

Each Jakarta EE API can have multiple implementations. The popular Hibernate Object-Relational Mapping tool, for example, is an implementation of Jakarta Persistence, but it is by no means the only one. Other Jakarta Persistence implementations include EclipseLink and Open JPA. Similarly, there are multiple implementations of every single Jakarta EE specification.

Jakarta EE applications are typically deployed to an application server. Some popular application servers include JBoss, Websphere, Weblogic, and GlassFish. Each application server is considered to be a Jakarta EE implementation. Application server vendors either develop their own implementations of the several Jakarta EE specifications or choose to include an existing implementation.

Application developers benefit from the Jakarta EE standard by not being tied to a specific Jakarta EE implementation. As long as an application is developed against the standard Jakarta EE APIs, it should be very portable across application server vendors.

Application server vendors then bundle a set of Jakarta EE API implementations together as part of their application server offerings. Since each implementation is compliant with the corresponding Jakarta EE specification, code developed against one implementation can run unmodified against any other implementation, avoiding a vendor lock-in.

The following table lists some popular Jakarta EE implementations:

Jakarta EE Implementation

Vendor

License

URL

Apache Tomee

Tomitribe

Apache License, Version 2.0

https://tomee.apache.org/

Eclipse GlassFish

Eclipse Foundation

Eclipse Public License - v 2.0

https://glassfish.org/

IBM Websphere Liberty

IBM

Commercial

https://www.ibm.com/products/websphere-liberty

JBoss Enterprise Application Platform

Red Hat

Commercial

https://www.redhat.com/en/technologies/jboss-middleware/application-platform

Open Liberty

IBM

Eclipse Public License 2.0

https://openliberty.io/

Payara Server Community

Payara Services Ltd

Dual licensed :CDDL 1.1 / GPL v2 + Classpath Exception

https://www.payara.fish/products/payara-platform-community/

Payara Server Enterprise

Payara Services Ltd

Commercial

https://www.payara.fish/products/payara-platform-community/

Wildfly

Red Hat

LGPL v2.1

https://www.wildfly.org/

Table 1.1 – Popular Jakarta EE Implementations

Note

For the full list of Jakarta EE-compatible implementations, please refer to https://jakarta.ee/compatibility/.

For most examples in this book, we will be using GlassFish as our Jakarta EE runtime. This is because it is a high-quality, up-to-date, open-source implementation not tied to any particular vendor; all examples should be deployable to any Jakarta EE-compliant implementation.

Jakarta EE, Java EE, J2EE, and the Spring Framework

In 2017, Oracle donated Java EE to the Eclipse Foundation and as part of the process, Java EE was renamed Jakarta EE. The donation to the Eclipse Foundation meant that the Jakarta EE specification became truly vendor-neutral, with no single vendor having control over the specifications.

Java EE, in turn, was introduced back in 2006 by Sun Microsystems. The first version of Java EE was Java EE 5. Java EE replaced J2EE; the last version of J2EE was J2EE 1.4, released back in 2003. Even though J2EE can be considered obsolete technology, having been superseded by Java EE several years ago and then renamed Jakarta EE, the term J2EE refuses to die. Many individuals to this day still refer to Jakarta EE as J2EE and many companies advertise on their websites and job boards that they are looking for “J2EE developers”, seemingly unaware that they are referring to a technology that has been obsolete for several years. The current correct term for the technology is Jakarta EE.

Additionally, the term J2EE has become a “catch-all” term for any server-side Java technology; frequently Spring applications are referred to as J2EE applications. Spring is not and never has been J2EE. As a matter of fact, Spring was created by Rod Johnson as an alternative to J2EE back in 2002. Just as with Jakarta EE, Spring applications are frequently erroneously referred to as J2EE applications.

Summary

In this chapter, we provided an introduction to Jakarta EE, outlining a list of several technologies and APIs included with Jakarta EE:

We covered how Jakarta EE is openly developed both by software vendors and the Java community at large via the Eclipse Software FoundationWe explained how there are multiple implementations of Jakarta EE, a fact that avoids vendor lock-in and allows us to easily migrate our Jakarta EE applications from one implementation to anotherWe cleared up the confusion between Jakarta EE, Java EE, J2EE, and Spring, explaining how Jakarta EE and Spring applications are frequently referred to as J2EE applications, even though J2EE has been obsolete for several years

Now that we’ve had a general overview of Jakarta EE, we are ready to start learning how to use Jakarta EE to develop our applications.