• Complain

Abdalla Mahmoud [Abdalla Mahmoud] - Developing Middleware in Java EE 8

Here you can read online Abdalla Mahmoud [Abdalla Mahmoud] - Developing Middleware in Java EE 8 full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2018, publisher: Packt Publishing, genre: Home and family. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Abdalla Mahmoud [Abdalla Mahmoud] Developing Middleware in Java EE 8

Developing Middleware in Java EE 8: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Developing Middleware in Java EE 8" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Use Java features such as JAX-RS, EJBs, and JPAs to build powerful middleware for newer architectures such as the cloud

About This Book
  • Explore EJBs to build middleware solutions for enterprise and distributed applications
  • Understand middleware designs such as event-based and message-driven web services
  • Learn to design and maintain large-scale systems and vendor disputes
Who This Book Is For

Enterprise architects, designers, developers, and programmers who are interested in learning how to build robust middleware solutions for enterprise software will find this book useful. Prior knowledge of Java EE is essential

What You Will Learn
  • Implement the latest Java EE 8 APIs and manage dependencies with CDI 2.0
  • Perform CRUD operations and access databases with JPA 2.1
  • Use bean validation API 2.0 to validate data
  • Develop business logic with EJB 3.2
  • Incorporate the REST architecture and RESTful API design patterns
  • Perform serialization and deserialization on JSON documents using JSON-B
  • Utilize JMS for messaging and queuing models and securing applications
  • Test applications using JUnit and Mockito and deploy them using Docker
In Detail

Middleware is the infrastructure in software based applications that enables businesses to solve problems, operate more efficiently, and make money. As the use of middleware extends beyond a single application, the importance of having it written by experts increases substantially. This book will help you become an expert in developing middleware for a variety of applications.

The book starts off by exploring the latest Java EE 8 APIs with newer features and managing dependencies with CDI 2.0. You will learn to implement object-to-relational mapping using JPA 2.1 and validate data using bean validation. You will also work with different types of EJB to develop business logic, and with design RESTful APIs by utilizing different HTTP methods and activating JAX-RS features in enterprise applications. You will learn to secure your middleware with Java Security 1.0 and implement various authentication techniques, such as OAuth authentication. In the concluding chapters, you will use various test technologies, such as JUnit and Mockito, to test applications, and Docker to deploy your enterprise applications.

By the end of the book, you will be proficient in developing robust, effective, and distributed middleware for your business.

Style and approach

Learn how to design and implement professional enterprise middleware solutions using the latest techniques and features provided by the Java EE 8 platform.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Abdalla Mahmoud [Abdalla Mahmoud]: author's other books


Who wrote Developing Middleware in Java EE 8? Find out the surname, the name of the author of the book and a list of all author's works by series.

Developing Middleware in Java EE 8 — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Developing Middleware in Java EE 8" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Query examples

In this section, we are going to learn the most common operations that we will need to perform in most enterprise applications. More complex use cases are supported too; you can refer to the JPA documentation to find out more about them.

About the author

Abdalla Mahmoud is a Java software architect and trainer with 14+ years of experience in the software development industry. He's led many successful projects using a broad range of technologies and frameworks covering the most out of the web, desktop, and mobile development aspects. He's also contributed in training hundreds of Java software engineers for more than 7 years, on different topics including Java EE, Spring, design patterns, and Android.

Map collections of primitives

Sometimes, you need to associate your entity with a collection of primitive values to represent a simple one/many-to-many relationship. For example, each movie has a set of associated genres that we want to keep stored in the database. To represent them from an object-oriented perspective, we will define a list (collection) of strings in our Movie class. To reflect this relationship inside the database, we will use the @ElementCollecion annotation, as shown in the following example:

@Entity public class Movie { @Id @GeneratedValue private long id; private String title; @ElementCollection private List genres = new ArrayList<>(); public Movie() { } // getters and setters here }

The @ElementCollection annotation will make the JPA provider create another table (movie_genres) to store the list of genres, mapped to the movies table using the movie's primary key as a secondary key in the (movie_genres) table. Now, let's create a movie, associate some genres, then store it in the database:

Movie movie = new Movie(); movie.setTitle("Beauty and the Beast"); movie.getGenres().add("Family"); movie.getGenres().add("Fantasy"); movie.getGenres().add("Musicial"); movie.getGenres().add("Romance");

Referring to the database, you will find a movie_genres table has been created, with a list of the genres we have associated.

There are times when you will be required to customize the table name, and/or the foreign key used to map each genre to its owner movie. To do this, we can provide some attributes to the @ElementCollection annotation, as in the following example:

@Entity public class Movie { @Id @GeneratedValue private long id; private String title; @CollectionTable(name = "movie_genres", joinColumns =@JoinColumn(name = "movie_title", referencedColumnName = "title")) @ElementCollection private List genres = new ArrayList<>(); public Movie() { } // getters and setters here }

As you see, the name attribute is used to specify the secondary table's desired name. Moreover, the joinColumns annotation is used to specify which column will be used to join rows in the secondary table (with genres) to the primary one (with movies). We have provided an annotation (@JoinColumn) specifying two attributes: the name, which represents the join column name in the secondary table, and the referencedColumnName, which represents the name of the owner entity's attribute that will be used to map it. In this example, we have used the title, rather than the ID, as a mapping value for the secondary table.

Postman as a test tool

In the previous section, we tested our REST ful service using a web browser. However, this is not the best tool we normally test our REST ful services with; we will need more advanced tools to test our upcoming REST ful services. One of the most popular tools around is Postman, which introduced an advanced GUI-based interface for testing our RESTful services with very complex scenarios. You can download Postman as a plugin for your Chrome browser, or even install a standalone version. You can get your free copy from https://www.getpostman.com .

After installing and launching Postman, you will see the following screen:

As you can see there is a URL bar similar to those found in web browsers You - photo 1

As you can see, there is a URL bar similar to those found in web browsers. You can write the URL of our REST ful service there. On the left of this bar, there's a drop-down menu that is used to select the HTTP method we need to test our REST ful service with. For the previous example, we will leave it as GET. The button ( Send ) is used to call the REST ful service, and by calling it, we can see the result in the big box, under the Body tab.

Postman is very easy to use, we will explore its other great features in the upcoming sections.

Receiving parameters

Like any programming function, web services may, and most will be passed various parameters. In JAX-RS, there are different types of parameters that can be passed, including:

  • Query parameters
  • Path parameters
  • Form parameters
  • Matrix parameters
  • Header parameters
Setting To, CC, and BCC fields

In the following example, we are going to show how to include the To, CC, and BCC fields in our email messages:

.... String[] arrTo = {}; String[] arrCC = {}; String[] arrBCC = {}; // setting to for (String to : arrTo) { message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); } // setting cc for (String cc : arrCC) { message.addRecipient(Message.RecipientType.CC, new InternetAddress(cc)); } // setting bbc for (String bcc : arrBCC) { message.addRecipient(Message.RecipientType.BCC, new InternetAddress(bcc)); } ....

As you see, we have used the addRecipient method to include multiple recipients to our email message, where the first parameter denotes whether this recipient is either To, CC, or BCC by using the Message.RecipientType.* constant.

Seat-booking application

In the following sections, we will create a more advanced application to put together everything we have learned in this chapter.

In a cinema booking application, you typically get prompted with a diagram of available seats, where you can choose one or more seats to book. One of the primary features of such an application is to keep the user updated with any new bookings that have been made while he is still choosing his favorite seats. We will implement a scenario where the user can choose one or more seats, without choosing some other seats being booked in the same moment.

Our application should look as follows:

As you can see the page shows a simple seat matrix to the user as HTML buttons - photo 2

As you can see, the page shows a simple seat matrix to the user as HTML buttons arranged in a grid. The text color for buttons is as follows:

  • Black: Available seats
  • Red: Seats booked by other users
  • Green: Seats booked by the current user

For the user to book an available seat, all he has to do is click on the seat's button. It should go green (as it has been booked by the current user), while all other users opening the same page for the same movie should instantaneously see those buttons in red.

For the sake of simplicity, we have ignored other details such as movies and date choices; the user will simply access this page using the following URL: http://localhost:9354/ch10_websockets/ex3.html?movieId=27

We will manually write an arbitrary number for the movie ID as a path parameter. Our backend will initialize data for the specified ID on the first request.

Validating Data with Bean Validation 2.0

Validating data is one of the most common and important operations in an enterprise solution. Whatever your application domain is, you should always validate your data against the proposed business constraints, and in the different layers of your application. You should always validate data entered directly by the user (in the presentation layer), data received by your web services, data received by your business objects, and data before being sent to the database (in the data access layer).

Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Developing Middleware in Java EE 8»

Look at similar books to Developing Middleware in Java EE 8. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Developing Middleware in Java EE 8»

Discussion, reviews of the book Developing Middleware in Java EE 8 and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.