Book Image

Java EE 7 with GlassFish 4 Application Server

By :
Book Image

Java EE 7 with GlassFish 4 Application Server

By:

Overview of this book

<p>GlassFish is a free, open source application server which supports all the major Java features such as Enterprise JavaBeans, JPA, JavaServer Faces, JMS, RMI, JavaServer Pages, and servlets. It is the first Java EE 7 compliant application server. All major Java EE technologies and API's are covered in this version of Java. GlassFish server allows the user to work with the extensile, adaptable, and lightweight Java EE 7 platform. <br /><br />This book explores the installation and configuration of GlassFish, and then moves on to Java EE 7 application development, covering all major Java EE 7 APIs. It focuses on going beyond the basics to develop Java applications deployed to the GlassFish 4 application server. The book covers all major Java EE 7 APIs including JSF 2.2, EJB 3.2, CDI 1.1, the Java API for WebSocket, JAX-WS, JAX-RS and more. <br /><br />The book also introduces JSON-P, the Java API for JSON (Javascript Object Notation) Processing. This advanced topic deals with how the two APIs are used to process JSON function, namely the Model API and the Streaming API. Apart from revisiting Java Server Faces (JSF), it explains why Facelets, the new features introduced in modern versions of JSF, are the preferred view technology over Java Server Pages (JSP)<br /><br />The later chapters explore competing implementations of the WebSocket standard in Java, describing the updates in JMS; which aims to provide a simpler API and reduction in boilerplate code among a host of other features. Readers will also learn how to secure Java EE applications by taking advantage of GlassFish's built-in security features. Finally, we learn more about the RESTful web service development using the JAX-RS specification.</p>
Table of Contents (18 chapters)
Java EE 7 with GlassFish 4 Application Server
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
9
Securing Java EE Applications
Index

Preface

Java Enterprise Edition 7, the latest version of Java EE, adds several new features to the specification. Several existing Java EE APIs have gone through major improvements in this version of the specification; additionally, some brand new APIs have been added to Java EE. This book includes coverage of the latest versions of the most popular Java EE specifications, including JavaServer Faces (JSF), Java Persistence API (JPA), Enterprise JavaBeans (EJB), Contexts and Dependency Injection (CDI), the new Java API for JSON Processing (JSON-P), WebSocket, the completely revamped Java Messaging Service (JMS) API 2.0, the Java API for XML Web Services (JAX-WS) and the Java API for RESTful Web Services (JAX-RS), as well as securing Java EE applications.

The GlassFish application server is the reference implementation for Java EE; it is the first Java EE application server in the market to support Java EE 7. This book covers GlassFish 4.0, the latest version of this powerful open source application server.

What this book covers

Chapter 1, Getting Started with GlassFish, explains how to install and configure GlassFish. Deploying Java EE applications through the GlassFish web console are also explained. Finally, basic GlassFish administration tasks such as setting up domains and database connectivity by adding connection pools and data sources are discussed.

Chapter 2, JavaServer Faces, covers development of web applications using JSF, including new features such as HTML5-friendly markup and Faces Flows. It also covers how to validate user input using JSF's standard validators and also by creating our own custom validators or by writing validator methods.

Chapter 3, Object Relational Mapping with JPA, discusses how to develop code that interacts with a Relational Database Management System (RDBMS) such as Oracle or MySQL through the Java Persistence API.

Chapter 4, Enterprise JavaBeans, explains how to develop applications using both session and message-driven beans. Major EJB features such as transaction management, the EJB timer service, and security are covered. The life cycle of the different types of Enterprise JavaBeans are covered, including an explanation of how to have EJB methods automatically invoked by the EJB container at certain points in the life cycle.

Chapter 5, Contexts and Dependency Injection, provides an introduction to Contexts and Dependency Injection (CDI). The chapter covers CDI named beans, dependency injection using CDI, and CDI qualifiers.

Chapter 6, JSON Processing with JSON-P, covers how to generate and parse JavaScript Object Notation (JSON) data using the new JSON-P API. It also covers both APIs for processing JSON: the Model API and the Streaming API.

Chapter 7, WebSockets, explains how to develop web-based applications that feature full duplex communication between the browser and the server as opposed to relying on the traditional HTTP request/response cycle.

Chapter 8, The Java Message Service, covers how to set up JMS connection factories, JMS message queues, and JMS message topics in GlassFish using the GlassFish web console. The chapter also discusses how to develop messaging applications using the completely revamped JMS 2.0 API.

Chapter 9, Securing Java EE Applications, covers how to secure Java EE applications through provided security realms as well as how to add custom security realms.

Chapter 10, Web Services with JAX-WS, covers how to develop web services and web service clients via the JAX-WS API. Web service client code generation using ANT or Maven as a build tool has been explained.

Chapter 11, Developing RESTful Web Services with JAX-RS, discusses how to develop RESTful Web services via the Java API for RESTful Web services as well as how to develop RESTful Web service clients via the brand new standard JAX-RS client API. It also explains how to automatically convert data between Java and XML by taking advantage of the Java API for XML Binding (JAXB).

What you need for this book

The following software needs to be installed to follow the material in this book:

  • The Java Development Kit (JDK) 1.7 or newer

  • GlassFish 4.0

  • Maven 3 or newer is needed to build the examples

  • A Java IDE such as NetBeans, Eclipse, or IntelliJ IDEA (optional, but recommended).

Who this book is for

This book assumes familiarity with the Java language. The target market for this book is the existing Java developers who wish to learn Java EE and the existing Java EE developers who wish to update their skills to the latest Java EE specification.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The @Named class annotation designates this bean as a CDI named bean."

A block of code is set as follows:

if (!emailValidator.isValid(email)) {
  FacesMessage facesMessage = new FacesMessage(htmlInputText.
getLabel()
+ ": email format is not valid");
  throw new ValidatorException(facesMessage);
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

        <ejb>
            <ejb-name>CustomerDaoBean</ejb-name>
            <ior-security-config>
                <as-context>
                    <auth-method>username_password</auth-method>
                    <realm>file</realm>
                    <required>true</required>
                </as-context>
            </ior-security-config>
        </ejb>

Any command-line input or output is written as follows:

$ ~/GlassFish/glassfish4/bin $ ./asadmin start-domain
Waiting for domain1 to start ........

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Clicking on the Next button moves you to the next screen."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

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 , 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 errata submission form 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 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 if you are having a problem with any aspect of the book, and we will do our best to address it.