Building Modern Web Applications With JakartaEE, NoSQL Databases and Microservices: Create Web Applications Jakarta EE with Microservices, JNoSQL, ... and MicroProfile easily (English Edition)
()
About this ebook
This book will be your comprehensive guide to creating Jakarta EE applications and microservices with Microprofile. The book begins with an introduction to Jakarta EE and quickly goes on to teach you about the various databases and their advantages. After this, you will explore the JNoSQL and Jmoordb frameworks to understand how to build Jakarta EE applications with NoSQL databases. Moving forward, you'll explore Eclipse MicroProfile and see how it helps build microservices with Java. Also, you will learn about various development applications such as Java Server Faces, Eclipse Krazos, PrimeFaces, Vaadin, and understand how to integrate them with your backend. Towards the end, you will learn about security, testing, and understanding continuous integration.
Related to Building Modern Web Applications With JakartaEE, NoSQL Databases and Microservices
Related ebooks
Getting Skilled with Java: Learn Java Programming from Scratch with Realistic Applications and Problem Solving Programmes (English Edition) Rating: 0 out of 5 stars0 ratingsJava Persistence with NoSQL: Revolutionize your Java apps with NoSQL integration (English Edition) Rating: 0 out of 5 stars0 ratingsJava: A complete practical solution Rating: 0 out of 5 stars0 ratingsMastering NetBeans Rating: 0 out of 5 stars0 ratings100+ Solutions in Java: A Hands-On Introduction to Programming in Java (English Edition) Rating: 0 out of 5 stars0 ratingsCode with Java 21: A practical approach for building robust and efficient applications (English Edition) Rating: 0 out of 5 stars0 ratingsJava 8 to 21: Explore and work with the cutting-edge features of Java 21 (English Edition) Rating: 0 out of 5 stars0 ratingsUltimate Node.js for Cross-Platform App Development Rating: 0 out of 5 stars0 ratingsObject Oriented Programming with Angular: Build and Deploy Your Web Application Using Angular with Ease ( English Edition) Rating: 0 out of 5 stars0 ratingsJakarta EE for Java Developers: Build Cloud-Native and Enterprise Applications Using a High-Performance Enterprise Java Platform Rating: 0 out of 5 stars0 ratingsJasmine JavaScript Testing - Second Edition Rating: 0 out of 5 stars0 ratingsJavaScript for Modern Web Development: Building a Web Application Using HTML, CSS, and JavaScript Rating: 0 out of 5 stars0 ratingsJAVA Programming Simplified: From Novice to Professional - Start at the Beginning and Learn the World of Java Rating: 0 out of 5 stars0 ratingsLearning AngularJS Animations Rating: 4 out of 5 stars4/5Vue.js for Jobseekers: A complete guide to learning Vue.js, building projects, and getting hired (English Edition) Rating: 0 out of 5 stars0 ratingsUltimate Certified Kubernetes Administrator (CKA) Certification Guide Rating: 0 out of 5 stars0 ratingsJava with TDD from the Beginning Rating: 0 out of 5 stars0 ratingsMastering Concurrency Programming with Java 8 Rating: 0 out of 5 stars0 ratingsDependency Injection: Design patterns using Spring and Guice Rating: 0 out of 5 stars0 ratingsPro Angular 16 Rating: 0 out of 5 stars0 ratings
Programming For You
Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsExcel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5HTML in 30 Pages Rating: 5 out of 5 stars5/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 5 out of 5 stars5/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5Spies, Lies, and Algorithms: The History and Future of American Intelligence Rating: 4 out of 5 stars4/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Tiny Python Projects: Learn coding and testing with puzzles and games Rating: 4 out of 5 stars4/5Python QuickStart Guide: The Simplified Beginner's Guide to Python Programming Using Hands-On Projects and Real-World Applications Rating: 0 out of 5 stars0 ratingsC# Programming from Zero to Proficiency (Beginner): C# from Zero to Proficiency, #2 Rating: 0 out of 5 stars0 ratingsHTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5SQL: For Beginners: Your Guide To Easily Learn SQL Programming in 7 Days Rating: 5 out of 5 stars5/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5C# 7.0 All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsiPhone For Dummies Rating: 0 out of 5 stars0 ratingsJavaScript All-in-One For Dummies Rating: 5 out of 5 stars5/5C All-in-One Desk Reference For Dummies Rating: 5 out of 5 stars5/5
Reviews for Building Modern Web Applications With JakartaEE, NoSQL Databases and Microservices
0 ratings0 reviews
Book preview
Building Modern Web Applications With JakartaEE, NoSQL Databases and Microservices - Geovanny Mendoza Gonzalez
CHAPTER 1
Jakarta EE Platform
Today the Java EE/Jakarta EE platform has proven to be one of the leading platforms for developing cloud applications.
This chapter is an introduction to The Jakarta EE platform. It will present a feedback of its history of the platform, a set of specifications and simple examples that will help you to use the potential of the platform for building enterprise applications ready for use in the cloud.
Numbered APIs and frameworks will be used to demonstrate our goal: Jakarta NoSQL, Jmoordb, Vaadin, and Java Server Faces.
Structure
Jakarta EE platform
Context and Dependency Injection (CDI) 2.0 (JSR 365)
Enterprise Java Beans 3.2 (JSR-345)
Java Servlet 4.0 (JSR-369)
Java API for RESTful Web Services JAX-RS 2.1 (JSR-370)
Java EE Security API 1.0 (JSR -375)
The Java API for JSON Binding JSON-B 1.0 (JSR-367)
JavaServer Faces JSF 2.3 (JSR-372)
Java Persistence API 2.2 (JSR-338)
Objective
This chapter is an introduction to the APIs that are part of the Java Enterprise Edition platform and Jakarta EE.
Jakarta EE platform
Jakarta EE is a platform that offers a set of components and APIs for the development of Java business applications. It orients towards the support of HTML5, Enterprise Java Beans, Web Services, JSON, Databases, Microservices, WebSocket among others.
These components are based on the combination of specifications (JSR) coming from the ecosystem of JavaEE platform led by Java Community Process (http://jcp.org) but rebranded under Eclipse Jakarta EE and Eclipse Microprofile standards (https://microprofile.io/); formed by companies, user groups, communities, which establish consensus on them, to be adaptable to the new requirements of the industry.
The APIs that are part of the specifications are known as Java Specification Request (JSR).
History
The Java EE platform has incorporated major changes in recent years, allowing a simpler development, performance improvements through reusable components resulting in lighter and scalable applications adapting to environments such as cloud, and Microservices.
We will briefly review the evolution of the platform over the last few years, showing each version along with the corresponding specifications.
The following table shows the different versions of the platform:
Table 1.1
From JavaEE to Jakarta EE
Over time companies and developer communities began to show concern for the evolution of the platform. Faced with the slowness in the evolution of specifications two important initiatives emerged in recent years; on the one hand, Microprofile (http://microprofile.io) and on another one Java EE Guardian (https://javaee-guardians.io/).
Microprofile brings an innovative standardization path to produce new APIs based on a consensus of large companies intending to optimize Java business applications to support Microservices. In 2017, Reza Rahman and Dr. James Gosling, created the Java EE Guardian formed by enthusiasts, to achieve a more open and agile process to implement new advances in the Java EE platform.
These efforts led Oracle to relinquish control of the Java EE platform to the Eclipse foundation. In what has been called Jakarta EE (https://jakarta.ee), whose purpose is focused on the active participation of the community to achieve progress more quickly and adapt to changing market needs.
Throughout this book we will develop a series of examples, so we specify some requirements that you must have installed on your computer.
We assume that the reader has prior knowledge of Java and the process of installing the development tools.
We will begin by briefly describing some of the JSR with code segments that will help you understand these APIs. If you already have experience with the Java EE platform, you will realize that they are very basic examples and concepts as they are aimed at new developers who want to know and develop with the Java EE/Jakarta EE platform.
You will see many definitions of the specification to guide the reader through the rules established through the JSR.
Above all let us mention some APIs grouped around the usage: web application, enterprise application, Web service and security management, microservices application.
The following table shows the APIs of the Web application technologies:
Table 1.2
The following table shows APIs stack of the Enterprise application technologies:
Table 1.3
The following table shows APIs stack of the Web services technologies:
Table 1.4
The following table shows APIs of the management and security technologies:
Table 1.5
The following table shows APIs of the Java EE-related Specs in Java SE
Table 1.6
Java EE/Jakarta EE application development
In this part, we will show you how to develop an application based Jakarta EE. Below a list of requirements we defined to develop our samples:
Java Development Kit
JDK 8 or higher
Build Tools
Maven or Gradle
Integrated Development Environment
Apache NetBeans
Plugin for Payara Micro
Eclipse
IntelliJ IDEA
NoSQL Databases
MongoDB
Application Server
Payara or any Jakarta EE certified application server
Dockers
The source code of the projects are available at the following link:
https://github.com/avbravo/Building-JakartaEE-Applications-Microservices
To create a Web project that supports the Jakarta EE 8 specification, you must just include your Maven project dependency:
A Jakarta EE applications run in containers that provide a running environment for the components and APIs of the Jakarta EE platform.
Java EE defines four main container types which are the following:
Application client container: They are usually applications that run on the desktop, with a user interface and use the platform components.
Applet container: Manages the execution of applets.
Web container: Servlet. JSP, Java Server Faces are applications that run in a Web container using HTTP protocols.
EJB container: Manages the execution of Enterprise Java Beans, which runs inside a Java EE server.
Context and Dependency Injection CDI 2.0 (JSR 365)
Context and Dependency Injection (CDI) was introduced from Java EE 6, and the specification defines it as a set of services that allow objects to be linked to the context life cycle, injected, and associated with Interceptor and Decorator.
It allows interacting with events. Offers integration with Enterprise Java Beans components, Java Server Faces Managed Beans, Bean Validation. It supports asynchronous events.
Injection of dependencies can be performed at the level of:
Attributes
Constructor
Method
The permitted scoped are:
RequestScoped
SessionScoped
ApplicationScoped
ConversationScoped
DependentScoped
The specification defines some annotations that we will show in the following table:
Table 1.7
The @Model annotation helps us define a model that we can use with other components:
@Model
public class Dog {
private Integer id;
private String name;
//Setters/Getters
}
define @Qualifier Domestic:
@Qualifier
@Retention(RUNTIME)
@Target({METHOD, FIELD, PARAMETER, TYPE})
public @interface Domestic {
}
The @Qualifier can be applied to a class or attribute definition levels:
@Domestic
public class AnimalProcessor {
}
Or by dependency injection:
public class AnimalController{
@Inject
@Domestic
AnimalProcessor animalProcessor;
}
To declare a Bean from a session bean we use the annotation @SessionScoped:
@Named
@SessionScoped
public class MySession implements Serializable {
private Dog dog;
//Setters/Getters
}
CDI allows easy integration with Java Server Faces components through Expression Language (EL):
@Interceptor example
We’ll develop an example of an interceptor. When the start() method is executed through the interceptor, it will invoke the authorize() method defined in ExerciseInterceptor, and then the control is returned to the start() method.
Figure 1.1
Steps to show the use of interceptor in a project that we will use as a very basic example:
Firstly, we will define the Model as shown below:
@Model
public class Person {
private Integer id;
private String name;
private Boolean walk;
public Person() {
}
//Setter/Getter
}
Next, we will define the Feed interface for use with the interceptor:
Inherited
@InterceptorBinding
@Target({TYPE, METHOD})
@Retention(RUNTIME)
public @interface Exercise {
}
We declare the FeedInterceptor to intercept the event of the method where we use the @Exercise interface:
@Exercise
@Interceptor
public class Exercisenterceptor {
@Inject
Person person;
@AroundInvoke
public Object authorize(InvocationContext ic) throws Exception {
try {
if (!person.getWalk()) {
return ic.proceed();
} else {
throw new Exception();
}
} catch (Exception e) {
throw e;
}
}
}
Create the beans.xml file in the WEB-INF directory and specify the class that was created of Interceptor type:
1.0 encoding=UTF-8
?>
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation=http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd
>
Use the @Exercise annotation in the start() method to intercept invocations to this method that will be trapped by ExerciseInterceptor:
@Model
public class ExerciseController implements Serializable {
@Inject
Person person;
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
@Feed
public String start() {
try {
System.out.println(The person started the walk
);
} catch (Exception e) {
System.out.println(error
+ e.getLocalizedMessage());
}
return ;
}
}
Enterprise Java Beans 3.2 (JSR-345)
The specification defines the Enterprise Java Beans architecture (EJB) as architecture for the development and deployment of components for enterprise applications.
The EJBs have as goals to be:
Standard component architecture for enterprise applications in Java.
Development, deployment and distribution of enterprise components in Java.
Development and deployment of Web services.
Make easy the creation of business applications.
The session types used by EJBs are:
Singleton
Stateful
Stateless
The components can be used simply utilizing annotations @EJB:
@EJB
MyResources myResources;
This example implements a @Schedule that sends a notification every 10 minutes:
@Singleton
public class SendCongratulations {
@Schedule(minute = */10
, hour = *
, persistent = false)
public void send() {
// …
}
}
@Producer example
Create an Enterprise Java Beans project from NetBeans IDE to manage a connection to a MongoDB database using a @Producer.
Select from the menu File | New | Project. In Categories, select Java With Maven option and in Projects, select EJB Module option:
Figure 1.2
Indicate the name of the project as nosqlejb
Figure 1.3
In the following dialog we leave the Server at
Figure 1.4
At the end of the process, the project structure is generated with all the necessary files. Our next step is to configure it according to our requirements:
Figure 1.5
Edit the pom.xml file and locate the javaee-api dependency:
And replace with Jakarta EE