Book Review: Java EE 7 with GlassFish 4 Application Server
Book Review: Java EE 7 with GlassFish 4 Application Server
Join the DZone community and get the full member experience.Join For Free
How do you break a Monolith into Microservices at Scale? This ebook shows strategies and techniques for building scalable and resilient microservices.
David R. Heffelfinger's Java EE 7 with GlassFish 4 Application Server has been published by Packt Publishing. The subtitle of this book is "A practical guide to install and configure the GlassFish 4 application server and develop Java EE 7 applications to be deployed to this server."
The Preface of Java EE 7 with GlassFish 4 Application Server states that JDK 7 (or newer), GlassFish 4.0, andMaven are needed to build and run the examples in this book. The Preface also expects that readers are expected to have "familiarity with the Java language" and that the book is intended for Java developers wanting to learn Java EE or current Java EE developers wanting to learn about the newest specification.
Chapter 1: Getting Started with GlassFish
The first chapter of Java EE 7 with GlassFish 4 Application Server begins by briefly describing GlassFish and by providing a high-level overview of the new features of Java EE 7. The new Java EE 7 specifications covered at this high level are JavaServer Faces (JSF) 2.2, Java Persistence API (JPA) 2.1, Java API for RESTful Web Services(JAX-RS) 2.0, Java Message Service (JMS) 2.0, Java API for JSON Processing (JSON-P) 1.0, and Java API for WebSocket 1.0.
Chapter 1 lists two of the primary advantages of using GlassFish as a Java EE application server: it being the reference implementation and, as such, it providing implementations of the latest and newest Java EE features. There is no mention of what I perceive to be GlassFish 4's biggest disadvantage: Oracle has declined to provide commercial support for GlassFish 4.
The initial chapter demonstrates how to download GlassFish 4 and mentions that it is also available bundled with NetBeans IDE ("Java EE" or "All" bundles) since version 7.4. The chapter shows the basics of installing the downloaded GlassFish and assumes that JDK 1.7 or later (note there have been rumors of GlassFish 4 not working well on JDK 8 yet) has been installed and that the Java application launcher is available from the environment's path.
Starting GlassFish from the command-line using the well-known (to previous users of GlassFish) asadmin start-domain command is demonstrated in Chapter 1. The chapter shows bringing up a web browser with the URLhttp://localhost:8080 to verify that GlassFish is running and then demonstrates using the web-based administrative console at URL http://localhost:4848 to deploy a WAR (
simpleapp.war) provided on the book's Packt Publishing site. This chapter also demonstrates using the web-based Administrative Console toundeploy the web application as well before demonstrating two ways to deploy the WAR from the command line (by copying the WAR into the
autodeploy directory and by using the asadmin deploy command).
This meaty first chapter concludes with a demonstration of how to configure GlassFish to use a JDBC driver for working with a relational database. The example specifically demonstrates configuration of a MySQL database driver and datasource, but the author points out that the examples in the rest of the book that work with relational databases use the Apache Derby-based JavaDB that comes bundled with GlassFish.
Nothing in this first chapter on downloading, installing, deploying to, and configuring a data source for GlassFish seems different to me from previous versions of GlassFish. I believe that experienced GlassFish users who are reading Java EE 7 with GlassFish 4 Application Server to learn the new Java EE 7 features and new GlassFish 4 features could skip most of the introductory chapter with the exception of the section providing concisely worded high-level overviews of the new Java EE 7 features. For readers entirely new to GlassFish, this chapter provides a nice starting point for everything you need to do to get GlassFish up and running for use with examples later in the book.
Chapter 2: JavaServer Faces
The second chapter of Java EE 7 with GlassFish 4 Application Server focuses on JavaServer Faces (JSF), which it describes as "the standard component framework of the Java EE platform." This chapter's coverage includes discussion of Facelets as now (as of Java EE 6/JSF 2.0) JSF's "preferred view technology." The chapter describes how adhering to JSF's expected conventions can lead to minimal required configuration.
Chapter 2 continues its JSF coverage with an example XHTML-based Facelet that is described in detailed text. Along the way, the author explains how to use JSF 2.0 project stages and explains how to specify a project stage to GlassFish as a JNDI resource.
JSF's "built-in input validation capabilities" are covered next. A table of standard JSF validators is provided and there is minor discussion on using Bean Validation with JSF. The chapter also includes discussion on creation of custom validators. The example illustrating custom validators uses Apache Commons Validator. When the chapter includes an example of implementing custom validation methods on Named Beans, it makes use ofApache Commons StringUtils.
After Chapter 2 covers customization of message styles and text, it moves onto a section called "Ajax-enabling JSF applications." This section points out that "JSF 2.0 standardized Ajax support by introducing the <f:ajax> tag" and then provides an example of using that new tag. There is thorough coverage of the Ajax tag, how it works, and what its other options are.
The parts of JSF 2.2 that interest me most and which I looked forward most to reading about in this book are JSF 2.2's HTML5 support and JSF 2.2's Faces Flows. Both subjects are covered well in this chapter with examples and descriptions of those examples.
Chapter 3: Object Relational Mapping with JPA
Chapter 3 is dedicated to Java Persistence API and most of the chapter covers basics of JPA that have been in place well before Java EE 7. The chapter describes JPA as "the standard Java EE Object Relational Mapping (ORM) tool" and provides examples and discussion on using JPA with one-to-one relationships, one-to-many relationships, many-to-many relationships, and composite primary keys. The chapter also introduces Java Persistence Query Language (JPQL).
The third chapter discusses how the Criteria API limitations of JPQL. It also introduces JPA 2.1 (Java EE 7) enhancements to the Criteria API that allow "for updating database data via the CriteriaUpdate interface" because Criteria API could only be used for reading data previously.
Chapter 4: Enterprise JavaBeans
The fourth chapter's focus is Enterprise JavaBeans (EJB), which are introduced as "server side components that encapsulate business logic of an application" and "simplify application development by automatically managing transaction management and security." Two types of EJBs (session beans and message-driven beans) are discussed. Although not necessary anymore, it was interesting (or a walk down memory lane) to read the historical information about how session and entity beans have changed since the days of J2EE.
The examples and discussions regarding Session Enterprise JavaBeans include invocation of these deployed beans from a standalone client using appclient and from a web client using JSF and CDI. The examples also involve JPA, making them very inclusive of the significant Java EE specifications.
This fourth chapter covers several other EJB topics include security, the Timer Service, transactions, and the EJB lifecycle. None of these concepts are new to Java EE 7, but EJBs are of course a significant part of many Java EE applications.
Chapter 5: Contexts and Dependency Injection
Contexts and Dependency Injection (CDI), introduced with Java EE 6, is the subject of Chapter 5. The coverage includes named beans, dependency injection, CDI Qualifiers, and CDI named bean scopes (with particular emphasis on conversation scope).
Chapter 6: JSON Processing with JSON-P
The sixth chapter states that "JSON-P includes two APIs for processing JSON - the Model API and the Streaming API" and covers generating JSON and parsing JSON with each of these two APIs. The examples include code and text descriptions as well as brief descriptions of the advantages and disadvantages of JSON Model API versus JSON Streaming API.
Chapter 7: WebSockets
Chapter 8: The Java Message Service
This is one of the chapters of Java EE 7 with GlassFish 4 Application Server that includes GlassFish-specific coverage within the topic of a general Java EE 7 specification. In this case, the chapter indicates how to configure GlassFish to use JMS by setting up "a JMS Connection Factory, a message queue, and a message topic." Like Chapter 4 on EJBs, this chapter on JMS also demonstrates using the GlassFish-specific applclient.
Chapter 8 coverage of JMS includes sending and receiving messages to/from queues and topics. It also includes an examples of browsing message queues and creating durable subscribers.
Chapter 9: Securing Java EE Applications
The ninth chapter of Java EE 7 with GlassFish 4 Application Server is on securing Java EE applications with Java Authentication and Authorization Service (JAAS) API and GlassFish. The chapter describes using security realmsand covers both preconfigured realms (file, admin-realm, and certificate) and "defining additional realms" (with examples including an LDAP realm, a JDBC realm, and custom realms).
Chapter 10: Web Services with JAX-WS
The final two chapters of Java EE 7 with GlassFish 4 Application Server are on using web services with Java EE and Chapter 10 specifically covers working with SOAP-based web services using Java API for XML Web Services(JAX-WS). Chapter 10 defines web services as "application programming interfaces that can be invoked remotely" and that "can be invoked from clients written in any programming language."
Chapter 10 describes using JAX-WS to develop web services, to develop clients of web services, to add attachments to web services calls, to expose EJBs as web services, and to secure web services. The chapter looks at WSDLs and generating Java from WSDLs using GlassFish's wsimport.
Chapter 11: Developing RESTful Web Services with JAX-RS
The final chapter of Java EE 7 with GlassFish 4 Application Server covers REST-based web services support in Java EE as provided by Java API for RESTful Web Services (JAX-RS). Although this was originally added to enterprise Java with Java EE 6, Java EE 7 introduces JAX-RS 2.0.
Chapter 11 introduces REST and covers basic support for REST-based web services that was added with Java EE 6. This discussion covers basic JAX-RS annotations, using GlassFish logs to analyze working functionality, usingcurl as a client, and using JAXB for Java/XML binding. The chapter then moves onto discussion of Java EE 7's introduction of "a standard client-side API that we can use to easily develop RESTful web service clients." The chapter concludes with a discussion on query parameters and path parameters (@QueryParam and@PathParam).
- Java EE 7 with GlassFish 4 Application Server liberally uses full color (in the PDF version I reviewed) screen snapshots that have sufficient resolution to be easy on the eyes and to nicely illustrate the concepts. This was particularly the case in the first chapter on installing and configuring GlassFish 4 and in other chapters dealing with the GlassFish web admin console.
- I like that Java EE 7 with GlassFish 4 Application Server includes code examples that not only illustrate the points being made, but also include common and useful third-party libraries.
- Heffelfinger has written other Packt Publishing books on J2EE/Java EE topics and portions of those books are the same across the books. For example, portions of Java EE 7 with GlassFish 4 Application Server are also available in Enterprise JavaBeans, Java EE 5 Development using GlassFish Application Server, and Java EE 6 with GlassFish 3 Application Server. Indeed, Java EE 7 with GlassFish 4 Application Server can be viewed as the third edition of the latter two of those books (it says as much by stating that it was "first published" in October 2007, had a "Second Edition" in July 2010, and the "Third Edition" in March 2014). Much of the Java EE and GlassFish content is the same with this edition adding in Java EE 7 new features and GlassFish 4 coverage. As a third edition, this book is as polished as one expects third editions to be.
- Although Java EE 7 with GlassFish 4 Application Server explicitly covers GlassFish 4, there is not much that I can see in Java EE 7 with GlassFish 4 Application Server that is unique to GlassFish 4 other than its support for the newly added Java EE 7 specifications. The book is really more focused on Java EE in general and Java EE 7 in particular with GlassFish as the Java EE implementation used to demonstrate the examples. This is a great book for someone wanting to learn new Java EE 7 features and for someone wanting to learn how to use basic GlassFish features in Java EE development. The majority of GlassFish 4's new features are implementations of the new Java EE 7 specifications, so it's not surprising that the differences in this edition are more about Java EE 7 than about GlassFish 4.
- Java EE 7 with GlassFish 4 Application Server's coverage of Java EE 7 covers it cumulatively rather than covering only features new to Java EE with Java EE 7.
Java EE 7 with GlassFish 4 Application Server provides a polished presentation of Java EE as it stands today with its recently included Java EE 7 specifications. GlassFish 4 is the application server used to demonstrate these Java EE concepts.
Published at DZone with permission of Dustin Marx , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.