Java EE 7 Development with WildFly
()
About this ebook
Java Enterprise Edition is a well-known platform for application development. Its seventh release brings many new features and API improvements. WildFly is a successor of the JBoss Application Server family and fully implements the Java EE 7 standards.
Java EE 7 Development with WildFly shows you how to use the latest version of the Java EE 7 platform, including its most advanced features. Every topic is presented using working examples that are prepared to work out of the box with the new WildFly application server. This book will give you an insight into JBoss' message-oriented middleware, which allows you to loosely couple heterogeneous systems together, while typically providing reliability and many other features.
By the end of the book, you will have covered important topics such as learning the most important info about Java EE technologies, what changes the Java EE 7 brought, and how to use JBoss Forge scaffolding mechanisms (for example AngularJS) and perform endpoint generation, including JAX-RS.
Francesco Marchioni
Francesco Marchioni is a Red Hat Certified JBoss Administrator (RHCJA) and a Sun Certified enterprise architect working as a freelancer in Rome, Italy. He started learning Java in 1997, and since then, he has followed the path to the newest application program interfaces released by Sun. In 2000, he joined the JBoss community, when the application server was running the release 2.X. He has spent many years as a software consultant, wherein he envisioned many successful software migrations from vendor platforms to open source products such as JBoss AS, fulfilling the tight budget requirements of current times. Over the past 5 years, he has been authoring technical articles for OReilly Media and running an IT portal focused on JBoss products (http://www.mastertheboss.com). In December 2009, he published JBoss AS 5 Development, which describes how to create and deploy Java Enterprise applications on JBoss AS (http://www.packtpub.com/jboss-as-5-development/book). In December 2010, he published his second title, JBoss AS 5 Performance Tuning, which describes how to deliver fast and efficient applications on JBoss AS (http://www.packtpub.com/jboss-5-performance-tuning/book). In December 2011, he published yet another title, JBoss AS 7 Configuration, Deployment, and Administration, which covers all the aspects of the newest application server release (http://www.packtpub.com/jboss-as-7-configuration-deploymentadministration/book). In June 2013, he authored a new title, JBoss AS 7 Development, which focuses on developing Java EE 6 API applications on JBoss AS 7 (https://www.packtpub.com/application-development/jboss-7-development).
Read more from Francesco Marchioni
Mastering JBoss Enterprise Application Platform 7 Rating: 0 out of 5 stars0 ratingsJBoss AS 7 Development Rating: 0 out of 5 stars0 ratingsJBoss AS 5 Development Rating: 0 out of 5 stars0 ratingsJBoss AS 5 Performance Tuning Rating: 0 out of 5 stars0 ratings
Related to Java EE 7 Development with WildFly
Related ebooks
Nginx Troubleshooting Rating: 0 out of 5 stars0 ratingsPHP Oracle Web Development: Data processing, Security, Caching, XML, Web Services, and Ajax Rating: 0 out of 5 stars0 ratingsHeroku Cloud Application Development Rating: 0 out of 5 stars0 ratingsSpring MVC Blueprints Rating: 0 out of 5 stars0 ratingsSpring MVC Cookbook Rating: 0 out of 5 stars0 ratingsJava EE 7 Development with NetBeans 8 Rating: 5 out of 5 stars5/5Flux Architecture Rating: 0 out of 5 stars0 ratingsMastering Web Application Development with Express Rating: 0 out of 5 stars0 ratingsLearning Continuous Integration with Jenkins Rating: 0 out of 5 stars0 ratingsOracle Coherence 3.5 Rating: 4 out of 5 stars4/5Building Scalable Apps with Redis and Node.js Rating: 0 out of 5 stars0 ratingsSpring Essentials Rating: 0 out of 5 stars0 ratingsNode.js 6.x Blueprints Rating: 0 out of 5 stars0 ratingsSpring MVC: Designing Real-World Web Applications Rating: 0 out of 5 stars0 ratingsMastering NetBeans Rating: 0 out of 5 stars0 ratingsSpring MVC: Beginner's Guide - Second Edition Rating: 0 out of 5 stars0 ratingsProfessional Java EE Design Patterns Rating: 0 out of 5 stars0 ratingsRed Hat OpenShift A Complete Guide - 2021 Edition Rating: 1 out of 5 stars1/5Mastering Java EE Development with WildFly Rating: 0 out of 5 stars0 ratingsJasmine JavaScript Testing - Second Edition Rating: 0 out of 5 stars0 ratingsRestlet in Action: Developing RESTful web APIs in Java Rating: 0 out of 5 stars0 ratingsJess in Action: Rule-Based Systems in Java Rating: 0 out of 5 stars0 ratingsCross-Platform Desktop Applications: Using Node, Electron, and NW.js Rating: 0 out of 5 stars0 ratingsDjango Admin Cookbook Rating: 0 out of 5 stars0 ratingsDocker: Build, Test, And Deploy Applications Fast Rating: 0 out of 5 stars0 ratingsJava EE 7 First Look Rating: 0 out of 5 stars0 ratingsPentaho Analytics for MongoDB Cookbook Rating: 0 out of 5 stars0 ratingsContinuous Integration in .NET Rating: 0 out of 5 stars0 ratingsCassandra High Availability Rating: 5 out of 5 stars5/5Test-Driven Java Development Rating: 4 out of 5 stars4/5
Computers For You
Elon Musk Rating: 4 out of 5 stars4/5Standard Deviations: Flawed Assumptions, Tortured Data, and Other Ways to Lie with Statistics Rating: 4 out of 5 stars4/5The Invisible Rainbow: A History of Electricity and Life Rating: 4 out of 5 stars4/5Everybody Lies: Big Data, New Data, and What the Internet Can Tell Us About Who We Really Are Rating: 4 out of 5 stars4/5Slenderman: Online Obsession, Mental Illness, and the Violent Crime of Two Midwestern Girls Rating: 4 out of 5 stars4/5101 Awesome Builds: Minecraft® Secrets from the World's Greatest Crafters Rating: 4 out of 5 stars4/5CompTIA Security+ Practice Questions Rating: 2 out of 5 stars2/5Mastering ChatGPT: 21 Prompts Templates for Effortless Writing Rating: 5 out of 5 stars5/5Alan Turing: The Enigma: The Book That Inspired the Film The Imitation Game - Updated Edition Rating: 4 out of 5 stars4/5The ChatGPT Millionaire Handbook: Make Money Online With the Power of AI Technology Rating: 0 out of 5 stars0 ratingsCompTIA IT Fundamentals (ITF+) Study Guide: Exam FC0-U61 Rating: 0 out of 5 stars0 ratingsDeep Search: How to Explore the Internet More Effectively Rating: 5 out of 5 stars5/5Ultimate Guide to Mastering Command Blocks!: Minecraft Keys to Unlocking Secret Commands Rating: 5 out of 5 stars5/5Remote/WebCam Notarization : Basic Understanding Rating: 3 out of 5 stars3/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Procreate for Beginners: Introduction to Procreate for Drawing and Illustrating on the iPad Rating: 0 out of 5 stars0 ratingsCreating Online Courses with ChatGPT | A Step-by-Step Guide with Prompt Templates Rating: 4 out of 5 stars4/5Hacking: Ultimate Beginner's Guide for Computer Hacking in 2018 and Beyond: Hacking in 2018, #1 Rating: 4 out of 5 stars4/5CompTIA Security+ Get Certified Get Ahead: SY0-701 Study Guide Rating: 5 out of 5 stars5/5People Skills for Analytical Thinkers Rating: 5 out of 5 stars5/5The Hacker Crackdown: Law and Disorder on the Electronic Frontier Rating: 4 out of 5 stars4/5Practical Lock Picking: A Physical Penetration Tester's Training Guide 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/5Dawn of the New Everything: Encounters with Reality and Virtual Reality Rating: 4 out of 5 stars4/5
Reviews for Java EE 7 Development with WildFly
0 ratings0 reviews
Book preview
Java EE 7 Development with WildFly - Francesco Marchioni
Table of Contents
Java EE 7 Development with WildFly
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Instant updates on new Packt books
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. Getting Started with WildFly
An overview of Java EE and WildFly
WildFly and Enterprise Application Platform
Welcome to Java EE 7
JavaServer Faces 2.2 – JSR 344
Enterprise JavaBeans 3.2 – JSR 345
Java Persistence API 2.1 – JSR 338
Contexts and Dependency Injection for Java EE 1.1 – JSR 346
Java Servlet API 3.1 – JSR 340
JAX-RS, the Java API for RESTful Web Services 2.0 – JSR 339
Java Message Service 2.0 – JSR 343
Bean Validation 1.1 – JSR 349
Concurrency utilities for Java EE 1.0 – JSR 236
Batch applications for the Java Platform 1.0 – JSR 352
Java API for JSON Processing 1.0 – JSR 353
Java API for WebSocket 1.0 – JSR 356
New features in WildFly
Installing the server and client components
Installing Java SE
Testing the installation
Installing WildFly
Starting WildFly
Connecting to the server with the command-line interface
Stopping WildFly
Locating the shutdown script
Stopping WildFly on a remote machine
Restarting WildFly
Installing the Eclipse environment
Installing JBoss Tools
Alternative development environments
Installing Maven
Testing the installation
Summary
2. Your First Java EE Application on WildFly
WildFly 8 core concepts
The WildFly 8 directory layout
Managing the application server
Managing WildFly 8 with the web interface
Launching the web console
Deploying your first application to WildFly 8
Advanced Eclipse deployment options
Managing deployments with the web console
Changing the deployment scanner properties
Deploying applications using the command-line interface
Deploying applications to a domain
Summary
3. Introducing Java EE 7 – EJBs
EJB 3.2 – an overview
Developing singleton EJBs
Configuring the EJB project object module (pom.xml)
Coding our EJB application
Controlling bean concurrency
Using bean-managed concurrency
Cooking session beans
Adding a stateless bean
Adding a stateful bean
Deploying the EJB application
Creating a remote EJB client
Configuring the client's project object module
Coding the EJB client
Adding the EJB client configuration
Running the client application
Adding user authentication
Using the EJB timer service
Programmatic timer creation
Scheduling timer events
Adding asynchronous methods to our EJBs
Using fire-and-forget asynchronous calls
Returning a Future object to the client
Summary
4. Learning Context and Dependency Injection
Introducing Contexts and Dependency Injection
Named beans
CDI scopes
WildFly CDI implementation
Rethinking your ticketing system
Adding the required dependencies
Creating the beans
Building the view
JSF 2 facet suggestions
Getting ready to run the application
Combining the scheduler into our application
Installing RichFaces
Making your application rich
Running the application
Creating interceptors
Are EJBs and JSF Managed Beans obsolete?
Summary
5. Combining Persistence with CDI
Data persistence meets the standard
Working with JPA
Adding persistence to our application
Setting up the database
Installing the JDBC driver in WildFly
Using the command-line interface to create a new data source
Creating the Maven project
Adding the Maven configuration
Cooking entities
Adding Bean Validation
Configuring persistence
Adding producer classes
Coding queries for your application
Adding services to your application
Adding a controller to drive user requests
Coding the JSF view
Running the example
Summary
6. Developing Applications with JBoss JMS Provider
A short introduction to JMS
The building blocks of JMS
The JBoss messaging subsystem
Creating and using connection factories
Using JMS destinations
Adding message-driven beans to your application
Cooking message-driven beans
Adding the JMS producer
Compiling and deploying the application
Specifying which message to receive using selectors
Transaction and acknowledgment modes
Using JMS to integrate with external systems
A real-world example – HornetQ and ActiveMQ integration
Installing the ActiveMQ resource adapter
Consuming ActiveMQ messages
Summary
7. Adding Web Services to Your Applications
Developing SOAP-based web services
Strategies to build SOAP-based web services
JBoss SOAP-based web services stack
A brief look at the JAX WS architecture
Coding SOAP web services with WildFly
Developing a POJO web service
Inspecting the web service from the console
Testing our simple web service
EJB3 Stateless Session Bean (SLSB) web services
Developing a web service consumer
Developing REST-based web services
Accessing REST resources
JBoss REST web services
Activating JAX-RS
Adding REST to our ticket example
Adding filters
Consuming our REST service
Compiling our ticket example
Adding AngularJS
Choosing between SOAP and REST services
Summary
8. Adding WebSockets
An overview of WebSockets
How do WebSockets work
Creating our first endpoint
Expanding our client application
Transforming POJOs to JSON
An alternative to WebSockets
Summary
9. Managing the Application Server
Entering the WildFly CLI
Launching the CLI
Connecting from remote hosts
Using a CLI in the graphical mode
Constructing CLI commands
Determining the resource address
Performing operations on resources
Using the tab completion helper
Deploying applications using the CLI
Deploying applications to a WildFly domain
Deploying to all server groups
Deploying to a single server group
Creating CLI scripts
Deploying an application to several WildFly nodes
Restarting servers in a domain
Installing a data source as a module
Adding JMS resources
Using advanced languages to create powerful CLI scripts
Using scripting languages to wrap CLI execution
Using the raw management API to manage the application server
Reading management model descriptions via the raw management API
Creating your resource watches using the detyped API
Role-based security
Auditing administrative operations
Patching a running instance
Summary
10. Securing WildFly Applications
Approaching the Java security API
The WildFly security subsystem
Setting up your first login module
Using the login module in the Ticket web application
Switching to FORM-based security
Creating a Database login module
Encrypting passwords
Using the Database login module in your application
Securing EJBs
Securing web services
Securing the transport layer
Enabling the Secure Socket Layer on WildFly
Certificate management tools
Securing the HTTP communication with a self-signed certificate
Generating the server and client certificates
Creating an SSL-aware security realm
Securing HTTP communication with a certificate signed by a CA
Securing EJB communication
Connecting to an SSL-aware security realm
Summary
11. Clustering WildFly Applications
Clustering basics
WildFly clustering
Starting a cluster of standalone nodes
Starting a cluster of domain nodes
The domain controller configuration
Host configurations
Deploying clustered applications
Creating HA Stateful Session Beans
Clustering the Ticket example
Turning your cache into a distributed cache
Coding the cluster-aware remote client
Deploying and testing high availability
Web application clustering
Load balancing your web applications
Installing mod_cluster
Clustering your web applications
Programming considerations to achieve HA
Achieving HA in JSF applications
Summary
12. Long-term Tasks' Execution
The overview of the batching framework
Our first batch job
Creating a chunk-based batch step
Creating a job-based batch step
Using concurrency utilities in Java EE
Introducing threads to enterprise beans
Summary
13. Testing Your Applications
Test types
Instruments used for testing
Getting started with Arquillian
Writing an Arquillian test
Configuring the pom.xml file
Writing your first Arquillian test
Running Arquillian TicketTest
Running Arquillian tests using Spock
ShrinkWrap Resolver
ShrinkWrap Descriptors
Persistence testing
Arquillian Warp
WebSockets testing
Enhancing your Arquillian test
Additional information
Summary
A. Rapid Development Using JBoss Forge
Installing Forge
Starting Forge
Creating your first Java EE 7 application with JBoss Forge
Building and deploying the application
Your Forge-demo application in action
Index
Java EE 7 Development with WildFly
Java EE 7 Development with WildFly
Copyright © 2014 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 authors, 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: June 2013
Second edition: December 2014
Production reference: 1241214
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78217-198-0
www.packtpub.com
Cover image by Michael Jasej (<milak6@wp.pl>)
Credits
Authors
Michał Ćmil
Michał Matłoka
Francesco Marchioni
Reviewers
Dustin Kut Moy Cheung
Adam Dudczak
Maxime Gréau
Bartosz Majsak
Jakub Marchwicki
Commissioning Editor
James Jones
Acquisition Editor
James Jones
Content Development Editor
Mohammed Fahad
Technical Editors
Indrajit A. Das
Rohit Kumar Singh
Copy Editors
Gladson Monteiro
Adithi Shetty
Project Coordinator
Akash Poojary
Proofreaders
Ting Baker
Simran Bhogal
Ameesha Green
Indexers
Rekha Nair
Priya Sane
Production Coordinator
Shantanu N. Zagade
Cover Work
Shantanu N. Zagade
About the Authors
Michał Ćmil is a Java developer with experience in web and desktop application development. In the past, he has worked for the e-commerce sector. Currently, he is developing manufacturing execution systems for industry clients. He has been a volunteer at GeeCON. Michał works as a software designer/developer for PSI Poland.
Michał Matłoka is a Java developer with experience in both Java EE and Spring technologies. He is a JBoss community contributor, focusing mainly on Arquillian and ShrinkWrap, and is also a winner of the JBoss Community Recognition Award in 2013 for his contributions to ShrinkWrap. He has spoken at Poznan Java User Group and volunteered at GeeCON. Michał is currently one of the 20 CEOs at SoftwareMill, a fully distributed company with no main office and a completely flat organization structure.
Francesco Marchioni is a Sun Certified Enterprise architect employed for an Italian company based in Rome. He started learning Java in 1997, and since then he has followed the path to the newest Application Program Interfaces released by Sun. In 2000, he joined the JBoss community when the application server was running the 2.x release.
He has spent many years as a software consultant, where he has envisioned many successful software migrations from vendor platforms to the open source products such as JBoss AS, fulfilling the tight budget requirements of current times.
For the past 5 years, he has been authoring technical articles for O'Reilly Media and also runs an IT portal focused on JBoss products (http://www.mastertheboss.com).
In December 2009, he authored JBoss AS 5 Development, Packt Publishing, which describes how to create and deploy Java Enterprise applications on JBoss AS.
In December 2010, he authored his second title, JBoss AS 5 Performance Tuning, Packt Publishing, which describes how to deliver fast and efficient applications on JBoss AS.
In December 2011, he authored yet another title, JBoss AS 7 Configuration Deployment Administration, Packt Publishing, which covers all the aspects of the newest application server release.
In August 2012, he coauthored the book, Infinispan Data Grid Platform, Packt Publishing, with Manik Surtani, which covers all aspects related to the configuration and development of applications using the Infinispan data grid platform.
I'd like to thank Packt Publishing for sharing the vision of this new book and for all the effort they put in it. I'd also like to thank my family for being always on my side, particularly, my wife for allowing me to follow my book author ambitions, and my father for buying me a C-64 instead of a motorcycle when I was young.
About the Reviewers
Dustin Kut Moy Cheung was born and raised in the island of Mauritius. His interest in computers was sparked when he got his first computer at the age of nine. He went on to study Electrical Engineering at McGill University in Montreal, Canada. Dustin is currently working as a productization engineer in the JBoss productization team at Red Hat.
I would like to thank the authors for giving me the opportunity to be one of the reviewers for this book. Java EE 7 has certainly made web development in Java easier and more elegant. Using the Wildfly application server will enable users to fully unlock all the capabilities that Java EE has to offer while providing easy administration, configuration, deployment, clustering, and much more!
Adam Dudczak is an experienced software engineer working with Java and related technologies since 2004. He is interested in the creation of lightweight, bulletproof, and scalable applications. He has a strong background in information retrieval and text mining. Currently, he is working on a better search experience in one of the major east European e-commerce portals. He is one of the leaders of Poznań JUG (http://www.jug.poznan.pl) and a co-organizer of the GeeCON conference (http://geecon.org). Adam is a father and husband and occasionally blogs at http://dudczak.info/dry. His Twitter handle is @maneo.
Maxime Gréau has been building software professionally for about 12 years, mostly for the Web and most of it with Java. He wrote a French book about Apache Maven 3 in 2011. He currently works as a Java EE architect.
Maxime is a speaker at conferences on Java and web technologies such as DevNation and DevFest. He is also a technical reviewer.
He blogs at http://mgreau.com/blog/ and can be found on Twitter and GitHub at @mgreau.
Bartosz Majsak works as a software developer at Cambridge Technology Partners, based in Zurich. He is passionate about open source technologies and testing methodologies. He is a proud JBoss Community Recognition award recipient for 2012 and 2013. He's also an Arquillian team member and the lead for two modules: Persistence Extension (makes writing database-oriented tests easier) and Spock Test Runner (gives your Arquillian tests some BDD and Groovy love). One thing that perhaps proves Bartosz is not a total geek is his addiction to alpine skiing.
Jakub Marchwicki has been in the software development industry for the past 10 years—wearing multiple hats, getting his hands dirty in multiple environments, and securing both technical as well as the business side of The Thing, which is an engineer with a human-friendly interface. Additionally, he has worked with a variety of languages and frameworks.
Jakub has always considered programming a tool to solve real-life problems in a pragmatic way. He has always stayed close to the business side of the solution, focusing on the technology. He combines his daily job of managing a horde of software engineers at Young Digital Planet with lectures, technical trainings, and commitment to Gdańsk Java User Group.
www.PacktPub.com
Support files, eBooks, discount offers, and more
For support files and downloads related to your book, please visit www.PacktPub.com.
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
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.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a 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 9 entirely free books. Simply use your login credentials for immediate access.
Instant updates on new Packt books
Get notified! Find out when new books are published by following @PacktEnterprise on Twitter or the Packt Enterprise Facebook page.
Preface
WildFly, the newest release of the JBoss Application Server, provides developers with a full implementation of the Java EE 7 platform. It is built on solid foundations of the modular architecture introduced with JBoss AS 7, but it has grown in terms of flexibility and performance. The newest version of the Enterprise Java focuses on developers' productivity, and so does WildFly.
This book will introduce Java developers to the world of enterprise applications. We will use modern development techniques and tools that are battle-tested in real-life projects. We'll also utilize the features provided by the WildFly platform, such as security, caching, testing, and clustering. Finally, you will learn how to manage your server using dedicated tools, created specifically for WildFly.
The learning process will be concentrated around a ticket booking application, which is a sample project that will get more features (and sometimes completely different user interfaces) with every chapter.
What this book covers
Chapter 1, Getting Started with WildFly, is an introduction to the Java EE platform and new Java EE 7 version specifications. It also focuses on presenting WildFly's new features, the developer environment setup, and basic server management.
Chapter 2, Your First Java EE Application on WildFly, describes the basics of the WildFly server usage, presenting information required to deploy your first application.
Chapter 3, Introducing Java EE 7 – EJBs, introduces Java EE business objects called Enterprise Java Beans. In this chapter, we create the foundations of the ticket booking application.
Chapter 4, Learning Context and Dependency Injection, covers the CDI technology that connects the building blocks of your applications.
Chapter 5, Combining Persistence with CDI, is a look into the database world and object mapping in Java EE.
Chapter 6, Developing Applications with JBoss JMS Provider, is a dive into HornetQ and enterprise system integration using JCA.
Chapter 7, Adding Web Services to Your Applications, discusses not only the old-style SOAP web services but also the modern and popular approach based on JAX-RS (REST). We'll also take a look at how to integrate a Java EE 7 backend with an AngularJS browser application.
Chapter 8, Adding WebSockets, introduces a completely new asset to the Java EE 7 platform: WebSockets. We will look at them in our sample AngularJS application.
Chapter 9, Managing the Application Server, discusses WildFly management features.
Chapter 10, Securing WildFly Applications, focuses on security-related aspects of the server and your application.
Chapter 11, Clustering WildFly Applications, discusses making Java EE applications highly available and scalable.
Chapter 12, Long-term Tasks' Execution, describes the new area of enterprise Java batch applications and concurrency management on the server.
Chapter 13, Testing Your Applications, demonstrates how we can write integration tests for for our applications using Arquillian after covering the most important Java EE technologies.
Appendix, Rapid Development Using JBoss Forge, covers the JBoss Forge tool. It shows how you can use this application to speed up your work with its code generation features on starting Java EE-based projects.
What you need for this book
This book is a code-oriented guide into the Java EE and WildFly worlds. To fully benefit from this book, you will need access to an Internet connection in order to download all the required tools and libraries. Knowledge of Java is required. We will also use Maven as a build automation tool, but thanks to its verbosity, the examples provided in this book are self-explanatory.
Although we will use AngularJS, additional JS knowledge is not required. All examples for the framework will be showcase-based, and their aim is to show how different parties can interact with Java EE in typical scenarios.
Who this book is for
If you are a Java developer who wants to learn about Java EE basics or if you are already a Java EE developer who wants to learn what's new in WildFly or Java EE 7, this book is for you. This book covers basics of the described technologies and also ensures to bring some more interesting, advanced topics for those who already have some knowledge.
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: After an MDB instance's onMessage() method returns, the request is complete, and the instance is placed back in the free pool.
A block of code is set as follows:
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
@Stateless
public class SampleEJB {
@Resource(mappedName = java:/ConnectionFactory
) private ConnectionFactory cf;
}
Any command-line input or output is written as follows:
CREATE DATABASE ticketsystem; CREATE USER jboss WITH PASSWORD 'jboss'; GRANT ALL PRIVILEGES ON DATABASE ticketsystem TO jboss;
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: For example, the Eclipse's File menu includes an option JPA Entities from Table that (once a connection has been set up to the database) allows reversing your DB schema (or part of it) into Java entities.
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 <feedback@packtpub.com>, 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 at 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 could 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 to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
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 <copyright@packtpub.com> 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 <questions@packtpub.com> if you are having a problem with any aspect of the book, and we will do our best to address it.
Chapter 1. Getting Started with WildFly
Java Enterprise Edition provides a standard to develop enterprise software, but allows the developers to choose its specific implementation. For every technology that is included in the Java EE (Enterprise Edition) specification, there is a reference implementation; an open source library or component that fulfills all of the requirements. Companies and organizations can create their own versions of the components, which means that there is no central Java EE platform that everybody uses. In place of that, we get multiple approaches on the implemented specification, with improvements and optimizations for specific cases. At the time of writing this, there are about 20 certified (full) implementations of Java EE 6 and three implementations of Java EE 7.
An application server is a runtime environment that provides applications with all the Java EE components. Glassfish is the reference implementation sponsored by Oracle, but beginning from Version 4 (created for Java EE 7), there is no longer commercial support for it. In this book, you will learn how to develop applications on the WildFly Application Server, previously known as the JBoss Application Server.
JBoss is a division of Red Hat, which seeks to provide a developer-friendly open source ecosystem for enterprise development. Currently, the company supports multiple projects (around 100), and some of them are implementations of Java EE specifications. The enterprise elements are combined in JBoss's own application server, WildFly.
It is worth noting that the name change from JBoss AS to WildFly was made to separate the application server from the company and other subprojects. The name was chosen in a public vote (more information on this is available at http://jbossas.jboss.org/rename/vote).
The new release features a scalable and high performing web server called Undertow, which supports the HTTP upgrade mechanism and WebSocket protocol. What's more, the new version of the container is even faster than JBoss Application Server 7, and offers a unified configuration mechanism. However, the main essence of the latest release is the Java EE 7 compliance, which allows developers to use technologies from the newest version of the Java EE specification.
The focus of this book is on application development; therefore, we will first need to gather all resources required to deliver our applications. In this chapter, we will cover the following topics in detail:
An overview of Java EE and WildFly
Preparing your environment for the installation of software
Downloading and installing WildFly
Verifying the WildFly installation
Installing other resources needed for development
An overview of Java EE and WildFly
Java EE (formerly called J2EE) is an umbrella specification embracing a standard set of technologies for server-side Java development. Java EE technologies include Java Servlet, JavaServer Pages (JSPs), JavaServer Faces (JSFs), Enterprise JavaBeans (EJB), Contexts and Dependency Injection (CDI), Java Messaging Service (JMS), Java Persistence API (JPA), Java API for XML Web Services (JAX-WS), and Java API for RESTful Web Services (JAX-RS), among others. The newest version of Java EE extends the range of available technologies even further by providing support for Batch Applications, Concurrency Utilities, JSON Processing (JSON-P) and WebSocket. Several commercial and open source application servers exist, which allow developers to run applications compliant with Java EE; WildFly (formerly known as JBoss AS) is the leading open source solution adopted by developers and, although this is difficult to measure in exact terms, it is likely to be the most widely used application server in the market.
As with all application servers compliant with Java EE, WildFly ships with all the required libraries to allow us to develop and deploy Java applications that are built on the Java EE platform.
WildFly and Enterprise Application Platform
WildFly and previous JBoss Application Servers were freely available for the community in the form of downloadable binary packages (for major releases) or buildable source code (for bug fixing releases). These versions are called community releases and are free to use for development and production.
JBoss also releases more stable and hardened versions of software of the community builds, which are called Enterprise Application Platform (EAP), a commercial product with support service from Red Hat. Red Hat calls this kind of relationship between projects as upstream/downstream. The community builds are the source of changes and innovations for the downstream, the code is downstream. The commercial version numeration differed from the community line, but it was an extended variant of the community releases (for example, EAP 6.1.0 was built on JBoss 7.2.0, which was available only on GitHub in the form of buildable source code; the same goes for EAP 6.2.0 and JBoss 7.3.0). EAP builds have a more complex licensing system; the usage terms depend on the maturity of the build and are as follows:
EAP Alpha is free for the developers and production use, as they are an equivalent of the standard community version with optional fixes included. The corresponding community binaries may not be available for download, as they would be similar to the EAP Alpha version.
EAP Beta is available to developers for free (after registration to a subscription program), but cannot be used in production.
EAP Final is also available to developers for free, but additionally, new security patches are available only in the paid subscription.
The distribution model proposed by JBoss allows the developers to work for free on the same version as the one used in production. This is a huge benefit, especially since the competitive solution from Oracle (Glassfish: the reference implementation of a Java EE compliant server) no longer has a version with commercial support.
Welcome to Java EE 7
Java EE 7 includes several improvements and additions to the existing version. The new version is focused on three themes: developer productivity, HTML5, and providing new features required by enterprise applications. The following sections list the major improvements to the specifications that are of interest to enterprise application developers.
If you are starting your adventure with Java EE, feel free to skip this section. The technologies described in the following sections will be covered in future chapters in more detail.
JavaServer Faces 2.2 – JSR 344
Java EE 7 includes a new version of the JSF specification, which is not so revolutionary as 2.0, but still provides some appealing additions for developers. The key features delivered by JSF 2.2 are as follows:
The HTML5 markup is now supported by the usage of pass-through elements and attributes. Earlier, custom attributes would have to be supported by an extended renderer for every component. The new constructs allow the developer to pass additional HTML attributes to the markup generated by JSF components.
The flow scope has been introduced with @FlowScoped, which makes the creation of wizards (dialogs with multiple steps) easier.
The Ajax-based file upload is now supported out of the box.
Also, stateless views have been presented as a way to improve performance.
Enterprise JavaBeans 3.2 – JSR 345
Compared to EJB 3.1, the Version 3.2 is a minor update of the existing version. It concentrates mainly on marking some older features as obsolete (they are now optional, which means that not every Java EE 7-compliant application server will support them). The optional features are connected with persistence to web services based on EJB 2.1 and JAX-RPC. The main enhancements provided by the new specification are as follows:
Life cycle methods for stateful session beans can now be transactional.
The Timer Service API, now allows you to access all active timers in the current EJB module.
A new container provided role (**) has been introduced. It can be used to