Java EE 7 First Look - Armel Fabrice NDJOBO - E-Book

Java EE 7 First Look E-Book

Armel Fabrice NDJOBO

0,0
31,19 €

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

Mehr erfahren.
Beschreibung

For several years, the development of robust, scalable, and secured applications was a headache for software companies. They had to use proprietary solutions with non-standard methods. With Java EE, many of these solutions have been standardized, simplified, adapted to the needs of the developer, and made freely available to the community. Thus, it is now possible to develop truly robust, secure, and scalable applications at a lower cost using tools such as: Eclipse, NetBeans, and GlassFish.Java EE 7 First Look is a practical guide which, through the creation of an online pre-registration website, will introduce you to the novelties of Java EE 7 and give you ideas for utilizing them.Giving you an insight on new features introduced in Java EE 7, this book begins with the objectives of Java EE 7 and then covers the new specifications added in Java EE 7. Next, you will move on to the improvements made in APIs and EJBs and how to work with them. You will also learn how to ensure that the quality of data is maintained that has been manipulated by your application and gives you the opportunity to put a small part of AOP (Aspect Oriented Programming) in action.Finally, the book will give you some ideas to realize n-tier applications using the Java EE platform and will also provide some guidance for the integration of your Java EE application to heterogeneous systems with which your application will interact.After reading Java EE 7 First Look, you'll have a good idea about the changes brought in by Java EE 7, as well as how to make the best use of these to build a large-scale application.

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

EPUB
MOBI

Seitenzahl: 204

Veröffentlichungsjahr: 2013

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.



Table of Contents

Java EE 7 First Look
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. What's New in Java EE 7
A brief history of Java EE
The main goals of Java EE 7
Productivity
HTML5 support
Novelties of Java EE 7
Summary
2. New Specifications
Concurrency Utilities for Java EE 1.0
Why concurrency?
Benefits of concurrency
Risks of concurrency
Concurrency and Java EE
Java EE Concurrency API
Batch Applications for Java Platform 1.0
What is batch processing?
Why a dedicated API for batch processing?
Understanding the Batch API
JobRepository
Job
Step
Chunk
Batchlet
The batch.xml configuration file
JobOperator
Java API for JSON Processing 1.0
What is JSON?
Object
Array
Value
Why JSON?
Java API for JSON processing
The streaming API
The object model API
Java API for WebSocket 1.0
What is WebSocket?
Why WebSocket?
The WebSocket API
Server endpoint
Client endpoint
Summary
3. The Presentation Layer
Servlet 3.1
What is a Servlet?
A login page with a Servlet
Latest improvements of Servlet 3.1 in action
Non blocking I/O API
Protocol upgrade processing
Expression Language 3.0
What is Expression Language?
The latest improvements of EL 3.0 in action
API for standalone environments
Lambda expressions
Collection object support
Collection object construction
Collection operations
String concatenation operator (+=)
Assignment operator (=)
Semi-colon operator (;)
Static fields and methods
JavaServer Faces 2.2
What is JavaServer Faces?
An identification page with JSF
The latest improvements of JSF 2.2 in action
HTML5-friendly markup
Pass-through attributes
Pass-through elements
Resource Library Contracts
Faces Flow
Stateless views
Summary
4. The Java Persistence API
Java Persistence API 2.1
JPA (Java Persistence API)
JPA in action
The latest improvements of JPA 2.1 in action
Persistence context synchronization
Entity
New annotations
Entity graphs
Static or named entity graphs
Dynamic entity graphs
JPQL
Support for stored procedures
New reserved identifiers
Support for creating named queries at runtime
The Criteria API
Support for bulk update/delete
Support for new reserved identifiers
DDL generation
Java Transaction API 1.2
The Java Transaction API
JTA in action
Innovations introduced by JTA 1.2
Summary
5. The Business Layer
Enterprise JavaBeans 3.2
Pruning some features
The latest improvements in EJB 3.2
Session bean enhancement
EJB Lite improvements
Changes made to the TimerService API
Harmonizing with JMS's novelties
Other improvements
Putting it all together
Presenting the project
Use Case Diagram (UCD)
Class diagram
Component diagram
Summary
6. Communicating with External Systems
JavaMail
Sending e-mails in Java
Sending an e-mail via the SMTP protocol
The latest improvements in action
The added annotations
The added methods
The changing of some access modifiers
Java EE Connector Architecture (JCA)
What is JCA?
JCA in action
Latest improvements
Java Message Service (JMS)
When to use JMS
The latest improvements in action
New features
Sending messages asynchronously
Delivery delay
Handling of the JMSXDeliveryCount message property
Simplification of the API
Java API for RESTful Web Services
When to use Web Services
JAX-RS in action
The latest improvements in action
The Client API
Asynchronous processing
Filters and entity interceptors
Filters
Entity interceptors
Summary
7. Annotations and CDI
Common annotations for the Java platform
The goal of this specification
Building your own annotation
Latest improvements in action
The new annotation
Contexts and Dependency Injection
What is CDI ?
Example 1 – instantiation of a POJO
Example 2 – accessing an EJB from a JSF page
Example 3 – setting a bean with a specific scope for simple operations
Example 4 – use of objects usually created by a factory
Latest improvements in action
Avoiding CDI processing on a bean
Accessing the non contexual instance of a bean
Accessing the current CDI container
Destroying CDI bean instances explicitly
Summary
8. Validators and Interceptors
Bean Validation
Validating your data
Building a custom constraint
Creating a constraint annotation
Implementing a validator
Latest improvements in action
Openness
Support for dependency injection and CDI integration
Support for method and constructor validation
Support for group conversion
Support message interpolation using expression language
Interceptors
Intercepting some processes
Defining interceptors in the target class
Defining interceptors in an interceptor class
Latest improvements in action
Intercept constructor invocation
Associating an interceptor with a class using interceptor binding
Creation of interceptor binding types
Declaring interceptor binding
Binding an interceptor by using interceptor binding type
Defining the execution order of interceptors
Summary
9. Security
JASPIC 1.1
Secure access to forms
Implementing an authentication module
Implementing the ServerAuthModule interface
Installing and configuring the authentication module
Binding the authentication module to a web application
Creating a realm
Security configuration
The latest improvements in action
Integrating the authenticate, login, and logout methods called
Standardizing access to the application context identifier
Support for forward and include mechanisms
Summary
Index

Java EE 7 First Look

Java EE 7 First Look

Copyright © 2013 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, and its dealers and distributors will be held liable for any damages caused or alleged to be 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.

First published: November 2013

Production Reference: 1121113

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-84969-923-5

www.packtpub.com

Cover Image by Abhishek Pandey (<[email protected]>)

Credits

Author

NDJOBO Armel Fabrice

Reviewers

Markus Eisele

E.P. Rama krishnan

Acquisition Editors

Sam Birch

Joanne Fitzpatrick

Commissioning Editor

Mohammed Fahad

Technical Editors

Ritika Singh

Nikhita K. Gaikwad

Project Coordinator

Ankita Goenka

Proofreader

Christopher Smith

Indexer

Monica Ajmera Mehta

Graphics

Yuvraj Mannari

Production Coordinator

Shantanu Zagade

Cover Work

Shantanu Zagade

About the Author

NDJOBO Armel Fabrice is a Design Computer Engineer and graduate from the National Advanced school of Engineering Cameroon, and Oracle Certified Expert, Java EE 6 Java Persistence API Developer. In the past, he has worked with Java EE to develop several systems among which are a helpline system and a commercial management application. He currently works on several systems based on EJB, Spring and ICEFaces solutions. In addition, he has made a technical review of the books Pro Spring Integration published by Apress and Beginning EJB 3, Java EE published by Apress. He is also a copywriter in developpez.com (his home page is: http://armel-ndjobo.developpez.com/).

First of all, I want to thank the Lord Jesus who makes everything possible for me. I would like to thank Dr. Georges Edouard Kouamou for making me love Software Engineering. I would like to thank Fomba Ken Collins for his critiques that have helped me improve the quality of the book. I would also like to thank Serge Tsala, Armel Mvogo, and my fiancée Ines Tossam who encouraged me during the writing of this book. And finally, I would like to express my gratitude to Licel Kenmue Youbi for all his efforts.

About the Reviewers

Markus Eisele is a Principal Technology Consultant working for msg systems AG in Germany. He is a Software Architect, a Developer, and a Consultant. He also writes for IT magazines. He joined msg in 2002 and has been a member of the Center of Competence IT-Architecture for nine years. After that he moved on to the IT-Strategy and Architecture group. He works daily with customers and projects dealing with Enterprise-level Java and infrastructures. This includes the Java platform and several Web-related technologies on a variety of platforms using products from different vendors. His main areas of expertise are Java EE Servers. He speaks at different conferences about his favorite topics. He is also part of the Java EE 7 expert group.

Follow him on twitter.com/myfear or read his ramblings with Enterprise level software development at http://blog.eisele.net.

E.P. Rama krishnan is an enthusiastic freelance developer and a technical writer. He has steady industry exposure of 5 years. His areas of expertise include JSF (JavaServer Faces), Java Persistence API, CDI, RESTful Services, Swings, Tomcat Clustering, and Load-balancing. His other areas of interest are Linux, Android, and Systems security. Besides development his major interest lies in writing technical blogs which simplify the latest technologies for early adopters. You are welcome to visit his blog at http://www.ramkitech.com and feel free to give your feedback. He can be reached at <[email protected]>.

www.PacktPub.com

Support files, eBooks, discount offers and more

You might want to visit www.PacktPub.com for support files and downloads related to your book.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

http://PacktLib.PacktPub.com

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books. 

Why Subscribe?

Fully searchable across every book published by PacktCopy and paste, print and bookmark contentOn demand and accessible via web browser

Free Access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.

Preface

When we considered writing this book, the main objective was to present the new features of Java EE 7 platform. But while writing, we came to realize that it would be interesting to make a clear and concise presentation of the relevant specifications and how to implement them. This led us to imagine a project that will help present almost all the specifications affected by Java EE 7 and how to put them together in order to build a large-scale application.

In short, this book does not aim to show how to implement the different aspects of each Java EE 7 specification or list the best practices. Rather, it positions itself similar to the yellow pages for a city that has been built recently. In other words, this book will help you discover the innovations introduced by Java EE 7 and give you ideas to build solid applications.

What this book covers

Chapter 1, What's New in Java EE 7, gives an overview of the improvements made in the Java EE 7 platform.

Chapter 2, New Specifications, explains concepts concerning the new specifications that have been added in Java EE 7 and shows how they can be used.

Chapter 3, The Presentation Layer, demonstrates the implementation of the improvements brought by the Java EE 7 platform for the presentation layer specifications.

Chapter 4, The Java Persistence API, shows how your Java application can store and retrieve data from the database in a safe way and explains the innovations that have been made in the relevant specifications.

Chapter 5, The Business Layer, begins by giving a presentation of the improvement in the business layer and then demonstrates how various Java EE 7 specifications can be put together for the realization of an application.

Chapter 6, Communicating with External Systems, demonstrates how a Java EE 7 application can interact with heterogeneous systems.

Chapter 7, Annotations and CDI, explains how annotations and CDI can be used to improve the quality of applications.

Chapter 8, Validators and Interceptors, shows how the validation and interception of data can be implemented in a Java EE environment to ensure the quality of the data handled by an application.

Chapter 9, Security, demonstrates the implementation of security and setting up a personal module for security in Servlet and EJB containers.

What you need for this book

To implement the various examples present in this book, you will need the following software:

NetBeans IDE 7.3.1 or higherJDK 7GlassFish Application Server 4, at least b89MySQL 5.5 or higher DBMS

Who this book is for

Given the main objectives, this book targets three groups of people who possess knowledge about Java. They are:

Beginners in using the Java EE platform who would like to have an idea about the main specifications of Java EE 7Developers who have experimented with previous versions of Java EE and want to know what Java EE 7 has brought as noveltiesBudding architects who want to learn how to put together various Java EE 7 specifications for building robust and secure enterprise applications

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to <[email protected]>, and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

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.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the erratasubmissionform link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.

Chapter 1. What's New in Java EE 7

Because of their use, distributed applications require some non functional services such as remote access, security, transaction management, concurrency, and robustness, among others. Unless you have APIs that offer these types of services, you need to implement them all from scratch and therefore, increase the number of bugs, reduce software quality, and increase production costs and time. The Java EE platform was set up to save the developer from these concerns. It is made up of a set of APIs that facilitate the development and deployment of distributed, robust, scalable, and interoperable applications.

Since its first release in 1999, the Java EE platform has evolved over time by offering a newer, richer, and simpler version than the previous one. In order for you to have an overview of the improvements in Java EE 7, this chapter addresses the following topics:

A brief history of Java EEThe main goals of Java EE 7Novelties of Java EE 7

A brief history of Java EE

Formerly called J2EE, the first version of Java EE platform was officially released in December 1999 with 10 specifications. Among these specifications, there were Servlets and JavaServer Pages (JSP) for data presentation, Enterprise JavaBeans (EJB) for the management of persistent data, remote access to business services through RMI-IIOP (Remote Method Invocation over Internet Inter-ORB Protocol), and the JMS (Java Message Service) specification, which was used to send messages.

Despite efforts and many contributions, early versions of Java EE were too complex and difficult to implement. This led to much criticism and caused the rise of competing frameworks such as Spring Framework.

Having drawn lessons from its previous failures, the platform has considerably evolved over time until the production of Java EE 5, which permitted the platform to regain its lost esteem. From this version, Java EE continues to provide easier, richer, and more powerful versions of the platform.

The preceding diagram gives an overview of the important changes made to Java EE platform since the release of the first version in December 1999. This diagram highlights the release dates, updates, and major improvements in each version. It also allows us to have an idea about the central theme behind each version.

The main goals of Java EE 7

Since May 2006, the Java EE platform has known remarkable evolution in terms of implementation. First, with Java EE 5, it greatly simplified the development of applications by allowing the transformation of a simple Java class (POJO class) into a business object through annotations or XML descriptions. Still in the line of simplification, Java EE 6 helps enrich annotations and introduces new concepts such as pruning, RESTful Web Services, CDI, EJB Lite, and configuration by exception and web profiles. This allows the platform to provide many easy-to-deploy and consume services. After the success of Java EE 6, the JCP (Java Community Process) envisaged turning the platform into a service by providing an infrastructure for cloud support. But, due to lack of significant progress in the concerned specifications, it revised its objectives. It is from the perspective of preparing the migration of the Java EE platform to the cloud that Java EE 7 focuses on productivity and HTML5 support. Having missed the big goal (that is, the migration to the cloud), it will reach its new goals through completion of Java EE 6 features and addition of some new specifications.

Productivity

Productivity in Java EE 7 has been improved upon in many ways. By simplifying some APIs such as JMS and JAX-RS, Java EE 7 platform significantly reduces boilerplate code. As you will notice in the chapters that follow, sending a JMS message can fit on one line and no longer requires the creation of several objects as was the case with JMS 1.1, where it was first necessary to create a Connection, Session, MessageProducer, and TextMessage.

Java EE 7 has integrated new APIs to better address the needs of enterprise applications relative to the processing of large amounts of data. We have, for example, the concurrency utilities, which allow the creation of managed threads within a container and give developers the ability to break down large processes into smaller units that can be computed concurrently. Similarly, there is a Java API for batch processing to manage bulk and long-running jobs.

Finally, Java EE 7 is enriched in annotations and has set a focus on configuration by exception. Whether it is for data source or batch processing, compatible Java EE 7 containers provide a number of default objects. It is even possible to produce complex applications with minor configuration.

In short, the new platform frees the developer from performing a number of tasks and the creation of several types of objects that are required for setting up an application.

HTML5 support

Some people might wonder why the support of HTML5 is so important. The answer is simple: HTML5 is the latest release of the HTML standard. More so, it offers new features that ease the building of more powerful and suitable web applications. For example, via the <audio> and <video> elements of HTML5, you can play, pause, and resume audio and video media content without the use of a third-party plugin such as Flash. Through the canvas element and WebGL library (a subset of OpenGL), you can easily integrate 2D and 3D graphics in your website. With regards to communication between the client and server, the perfect integration of WebSocket protocol in HTML5 allows us to build a web application with full-duplex P2P communication and get over some limitations of HTTP for real-time communication. Using this protocol, you will have no difficulty in realizing chat applications or other web applications that require real-time communication between the client and server, such as trading and e-commerce platforms. In terms of data exchange, the native support of JSON format in HTML5 simplifies processing of information and reduces the size of documents. Many other areas have been improved, but for now we will only mention these ones.

Given all these innovations, the support for HTML5 features was added in JSF (JavaServer Faces), a new API was added to Java EE 7 platform to build WebSocket-driven applications and another API to process JSON data format.

Novelties of Java EE 7

The Java EE 7 was developed as a Java Specification Request (JSR 342). It has a total of 31 specifications including 4 new specifications, 10 major releases, and 9 MRs (Maintenance Releases). All these specifications are taken into account by the GlassFish Server 4.0 (accessible via the address https://glassfish.java.net/download.html), which is the reference implementation of Java EE 7.

The new specifications introduced in Java EE are as follows:

Concurrency Utilities for Java EE 1.0 (http://jcp.org/en/jsr/detail?id=236), for asynchronous processing and multi-threaded tasks in Java EE application components.Batch Applications for the Java Platform 1.0 (http://jcp.org/en/jsr/detail?id=352), to perform long-running tasks and bulk operations.Java API for JSON Processing 1.0 (http://jcp.org/en/jsr/detail?id=353), which provides support for JSON processing. It offers Java EE components the ability to parse, generate, transform, and query JSON format.Java API for WebSocket 1.0 (http://jcp.org/en/jsr/detail?id=356), to build WebSocket applications.

APIs inherited from the Java EE 6 platform that have undergone major changes are the following:

Java Platform, Enterprise Edition 7 (Java EE 7) Specification (http://jcp.org/en/jsr/detail?id=342), when compared to Java EE 6, further simplifies development, adds support for HTML5, and prepares the platform to migrate to the cloudJava Servlet 3.1 Specification (http://jcp.org/en/jsr/detail?id=340) introduces some features such as non blocking I/O API and protocol upgrade processingExpression Language 3.0 (http://jcp.org/en/jsr/detail?id=341) was separated from JSP specification request,