JB183 EAP7.0 en 2 20180124 IG 1 PDF
JB183 EAP7.0 en 2 20180124 IG 1 PDF
TRAINING
The contents of this course and all its modules and related materials, including handouts
to audience members, are Copyright © 2018 Red Hat, Inc.
This instructional program, including all material provided herein, is supplied without
any guarantees from Red Hat, Inc. Red Hat, Inc. assumes no liability for damages or legal
action arising from the use or misuse of contents or details contained herein.
If you believe Red Hat training materials are being used, copied, or otherwise improperly
distributed please e-mail [email protected] or phone toll-free (USA) +1 (866) 626-2994
or +1 (919) 754-3700.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, JBoss, Hibernate, Fedora, the
Infinity Logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States
and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other
countries.
The OpenStack® Word Mark and OpenStack Logo are either registered trademarks/
service marks or trademarks/service marks of the OpenStack Foundation, in the United
States and other countries and are used with the OpenStack Foundation's permission.
We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the
OpenStack community.
JB183-EAP7.0-en-2-20180124 v
Red Hat Application Development I: Programming in Java EE
vi JB183-EAP7.0-en-2-20180124
Document Conventions
Notes and Warnings
Note
"Notes" are tips, shortcuts or alternative approaches to the task at hand. Ignoring a
note should have no negative consequences, but you might miss out on a trick that
makes your life easier.
Important
"Important" boxes detail things that are easily missed: configuration changes that
only apply to the current session, or services that need restarting before an update
will apply. Ignoring a box labeled "Important" will not cause data loss, but may cause
irritation and frustration.
Warning
"Warnings" should not be ignored. Ignoring warnings will most likely cause data
loss.
References
"References" describe where to find external documentation relevant to a subject.
JB183-EAP7.0-en-2-20180124 vii
viii
Course Timing
ILT
Day 1
Activity Time
Introduction 20 minutes (40 minutes with i18n)
Chapter 1 125 minutes
Chapter 2 95 minutes
Chapter 3 (started) 150 minutes
Total for day 390 minutes (410 minutes)
Day 2
Activity Time
Chapter 3 (continued) 60 minutes
Chapter 4 215 minutes
Chapter 5 115 minutes
Total for day 390 minutes
Day 3
Activity Time
Chapter 6 140 minutes
Chapter 7 105 minutes
Chapter 8 (started) 145 minutes
Total for day 390 minutes
Day 4
Activity Time
Chapter 8 (continued) 25 minutes
Chapter 9 140 minutes
Chapter 10 215 minutes
Total for day 380 minutes
VT
Day 1
Activity Time
Introduction 20 minutes (40 minutes with i18n)
JB183-EAP7.0-en-2-20180124 ix
Course Timing
Activity Time
Chapter 1 125 minutes
Chapter 2 95 minutes
Chapter 3 70 minutes
Total for day 310 minutes (350 minutes)
Day 2
Activity Time
Chapter 3 140 minutes
Chapter 4 (started) 170 minutes
Total for day 310 minutes
Day 3
Activity Time
Chapter 4 (continued) 45 minutes
Chapter 5 115 minutes
Chapter 6 140 minutes
Chapter 7 (started) 10 minutes
Total for day 310 minutes
Day 4
Activity Time
Chapter 7 (continued) 95 minutes
Chapter 8 170 minutes
Chapter 9 (started) 45 minutes
Total for day 310 minutes
Day 5
Activity Time
Chapter 9 (continued) 95 minutes
Chapter 10 215 minutes
Total for day 310 minutes
x JB183-EAP7.0-en-2-20180124
Introduction
Chapter Information
Overview
Cover introductory material for this class.
Schedule
ILT/VT Schedule
Section Title Presentation & Time
Engagement Methods (minutes)
1 Course Objectives and Structure P: Lecture 10
2 Orientation to the Classroom Network P: Lecture 10
3 Internationalization P: Lecture 20
Course Introduction
Objectives
• Welcome students and provide an orientation to the class, classroom hardware, and facility
or VT environment.
Student Benefits
• Prepares students for this class.
Presentation Notes
Introduce yourself and welcome students to the class. Before starting make sure any
operational requirements, including taking attendance and providing students with materials,
have been met. For an in-person training event, orient students to the facility. Make sure
students know the classroom hours and plans for any rest breaks and lunch.
Discuss the basic structure of the course and course timing with the students.
Objectives
Introduce your students to the main objectives of this course.
Audience/Prerequisites
Discuss the intended audience and prerequisites for this course.
JB183-EAP7.0-en-2-20180124 xi
Introduction
Objectives
• Orient students to their classroom hardware and how to access it for upcoming lab
exercises.
Presentation Notes
Discuss the classroom environment from a single student's perspective. Focus on the
machines that a student will directly interact with. This course has four student machines in
lab.example.com:
• workstation, which has a GNOME desktop environment and will be used for most of their
work
Discuss the appropriate student guide material on how students start and access their
machines in the ILT or VT classroom environment.
Warning
Be sure to warn students that performing a reset with rht-vmctl (in ILT) or with
the VT interface will cause the system to be reverted to its starting point and all work
they have saved on that system will be lost.
Instructor-only notes
The following notes are information provided for the instructor's reference and convenience.
Important
In the VT environment, the instructor initially has the same virtual machines as the
student. A VT instructor will not initially have the demo command available
in their environment.
To enable demos, you must log in as root on your workstation machine and run
the following commands:
In both ILT and VT, if the student workstation is down or stopped, the other machines will not
be able to see the classroom network or shared servers, because it is the NAT router for each
student.
In ILT, if you need to access a particular student's machines over the network, you will need
to have them use ip on workstation to find out and tell you what their address on the
xii JB183-EAP7.0-en-2-20180124
Internationalization
172.25.252.0/24 network is so you can ssh to that. From there you can reach that student's
other machines.
Internationalization
Note
Some regions run Red Hat training in classrooms which by policy should be localized
for the language in which the course is being taught. The classroom setup process
deploys all machines and users localized for en-US.utf8 (US English).
If your classroom needs to be set to a different locale, this section must be covered.
The instructor should guide students through appropriate language and input
configuration for their locale and hardware. The instructor should then have
students save the settings to their baseline machine images with rht-vmctl.
Per the directions in ClassroomSetup.txt, the locale settings for the physical
layer (foundationX) are inherited from the manual selections made when
foundation0 was installed. Modifying the locale in the pre-built virtual machine
images should be done as an exercise with the students updating and saving each
of their virtual machines using rht-vmctl save VMNAME as described in the final
step of the “DETAILED INSTRUCTIONS” in ClassroomSetup.txt.
Language Support
1. Explain to your students that Red Hat Enterprise Linux officially supports a large number
of languages. The book references the list at the time of writing.
2. Official support means that there is a certain level of support for the language in the
operating system, customers can recieve support for technical issues with those
languages, and can ask for correction of internationalization/localization (i18n/l10n)
issues if there are problems. It does not imply that communication with technical support
representatives will be available in their native language.
3. It may be possible to use unsupported languages on the system, but customers might
not recieve support for technical issues with those languages.
JB183-EAP7.0-en-2-20180124 xiii
Introduction
If your classroom machines need to have a locale and input method other than the defaults
set, use this subsection as a workshop. Have the students follow along with you in order to
set up their machines. At the end of the section, they will need to save their settings to their
baseline machine images so that the localization persists across server resets.
Language Settings
1. Mention that GNOME 3 may prompt a user for their preferred language on first login
(through /usr/libexec/gnome-initial-setup). This may be disabled by the
classroom setup process, but if it's available that's one way to set preferred locale.
3. Mention that these settings will only affect GNOME 3 sessions, not ssh logins or logins
on a text console. Optionally mention the Note box with the shell snippet on how to tie
together the GNOME locale for ssh and console logins in RHEL 7. The RHEL 6 file used by
GNOME was not in /var/lib, but was ${HOME}/.dmrc.
Important
The kernel's physical console/virtual consoles ($TERM="linux") barely support
Western European fonts, and do not support non-Latin text well at all. Locales
this definitely impacts: ja-JP, ko-KR, zh-CN, and zh-TW.
For affected languages, the sample code either shouldn't be used, or should
check to see if $TERM="linux" and $LANG is one of the affected languages, and
if so sets it to en_US.UTF-8. A good example of how to do this is in /etc/
profile.d/lang.sh.
5. Explain that single commands can be run in a different language by setting the LANG
variable just for that command.
LANG=ja_JP.UTF-8 ls nosuchfile
If Japanese fonts are not yet installed a dialog will pop-up to ask if you want to install
them. Click on Install and enter the root password when prompted.
2. Explain to your students that to switch between input methods they can use
Super+Space (also known as Windows+Space).
xiv JB183-EAP7.0-en-2-20180124
System-wide Default Language Settings
3. If your chosen input method has special features (such as the Japanese (Kana Kanji)
method), demonstrate them here.
2. We do not discuss setting console keyboard settings here in depth, but if you need to do
so, cover localectl and /etc/vconsole.conf.
3. Optionally, you may mention that /etc/profile.d/lang.sh will cause the system
console to use en_US.UTF-8 instead of the configured system-wide locale for languages
which are not well supported by the locale. (If the student sets $LANG manually after that
startup script runs, that will not happen.)
Language Packs
1. Explain that language packs install helper packages that include translated man pages,
help pages, spelling dictionaries, and other supporting files.
JB183-EAP7.0-en-2-20180124 xv
xvi
TRAINING
CHAPTER 1
TRANSITIONING TO MULTI-
TIERED APPLICATIONS
JB183-EAP7.0-en-2-20180124 1
Chapter 1. Transitioning to Multi-tiered Applications
Chapter Information
Overview
In this chapter introduce the basics of Java EE and multi-tiered applications.
Schedule
ILT/VT Schedule
Section Title Presentation & Time
Engagement Methods (minutes)
Introduction 3
1 Describing Enterprise Applications P: Lecture 10
A: Multiple Choice Quiz 5
2 Comparing Features of Java EE and P: Lecture 20
Java SE A: Multiple Choice Quiz 5
3 Describing the Java Community P: Lecture 10
Process A: Multiple Choice Quiz 5
4 Describing Multi-tiered Application P: Lecture 15
Architecture A: Multiple Choice Quiz 5
5 Installing Java Development Tools P: Lecture 25
A: Guided Exercise 25
Conclusion 2
Chapter Introduction
Introduction
This chapter enables the students to learn about the difference between simple standalone
JAVA applications that utilize the Java SE API and, Java EE enterprise applications running
on an application server that provide transaction capabilities, multi-threading, database
persistence, security and web services. The Java Community Process (JCP) is introduced and
the different standards and APIs that make up Java EE are presented. The students also learn
about multi-tiered applications and their use cases along with development tools required for
implementing Java EE applications.
2 JB183-EAP7.0-en-2-20180124
Objectives
• Define what is an "enterprise application" and name some of the benefits of Java EE
applications.
Presentation Notes
Introduction
For students who have just worked with Java SE and built simple applications, we define the
characteristics of enterprise applications and briefly introduce the Java EE platform. Discuss
the advantages of building enterprise applications using Java EE.
Lecture
Introduce the concept of an enterprise application and it's characteristics. Emphasize
the transactional nature of such applications and discuss real-world example of
enterprise applications. Introduce the Java EE specification and discuss the latest Java EE 7
standard. Discuss the benefits of the Java EE ecosystem and emphasize how this reduces
implementation time and quicker time to market.
Quiz
Tell your students to turn to the quiz in their books. Once they complete it, discuss the
answers.
Summary
Enterprise applications are characterized by their transactional nature, scalability, ability
to handle concurrency, asynchronous messaging, and security. Java EE offers an excellent
platform for building such applications. Java EE is standardized and managed by the JCP,
which is a community driven process.
Objectives
• Compare the features of Java EE and Java SE.
Presentation Notes
Introduction
This section discusses the differences between Java SE and Java EE applications and how they
are built and executed.
Lecture
Highlight the difference between the base Java SE API and the Java EE APIs that are part of the
Java EE specification. Discuss TCK compliance and the different profiles specified in the Java
JB183-EAP7.0-en-2-20180124 3
Chapter 1. Transitioning to Multi-tiered Applications
EE 7 specification. Briefly discuss the different APIs that are included in Java EE 7 and their
uses. Finally, present how Java SE and Java EE applications are built, packaged, deployed and
executed with a brief discussion on the different types of deployment types (JAR, WAR, EAR).
Quiz
Tell your students to turn to the quiz in their books. Once they complete it, discuss the
answers.
Summary
Java SE and Java EE applications are built in different ways. Java EE applications run on top of
a Java EE compliant application server and have a number of different deployment types. The
Apache Maven build tool is used to build, package, deploy and execute both Java SE and Java
EE applications.
Objectives
• Identify the purpose of the Java Community Process (JCP).
• Identify the process by which the JCP defines, releases and maintains Java Specification
Requests (JSR).
• Identify specification and version numbers of APIs that constitute the Java EE 7
specification.
Presentation Notes
Introduction
This section discusses the Java Community Process (JCP) and how it creates, releases,
evolves and maintains Java EE standards and specifications. We also discuss the Java EE 7
specifications (JSR 342) and it's constituent APIs.
Lecture
Present the JCP and how it functions. Discuss the concept of a Java Specification Request (JSR)
and how JSRs are created and released. Briefly highlight the parties involved in the JCP like
Expert Groups, Executive Committee, members and specification leads. Explain the concept
of a TCK and why it is used. Briefly discuss the Java EE 7 specification and the fact that it is
made up of many different JSRs. Highlight how each version of a particular API can have
different JSR numbers and discuss the most important APIs in the Java EE 7 specification
which are commonly used in enterprise web applications.
Quiz
Tell your students to turn to the quiz in their books. Once they complete it, discuss the
answers.
4 JB183-EAP7.0-en-2-20180124
Summary
Summary
The JCP is a community driven standards body that creates, evolves and maintains Java EE
standards and specifications via JSRs. The Java EE 7 standard consists of a collection of APIs
which are each maintained in a separate JSR. A Java EE compliant application server must
pass the Java EE TCK completely.
Objectives
• Define various multi-tiered architectures.
Presentation Notes
Introduction
Java EE is designed for multi-tier applications and there are different types of multi-tier
architectures depending on the type of applications being built.
Lecture
Briefly define the concept of a tier in enterprise applications. Highlight the fact that the
concept of a tier is a logical one and that it is not mandatory for each tier to be hosted in
a separate physical machine. Multi-tier applications can be scaled out to handle increased
workloads. Multi-tiered Java EE applications can be used for simple web based applications
with no database backend or for building much more complex applications with multiple EJB
components, database and EIS integration, web services and asynchronous messaging.
Quiz
Tell your students to turn to the quiz in their books. Once they complete it, discuss the
answers.
Summary
Multi-tier applications can be easily scaled out by adding more servers to handle increased
workloads. The Java EE specification is designed for different types of multi-tier applications
ranging from the simplest web application to larger and more complex applications consisting
of web and EJB components, web services, asynchronous messaging, transactions and
database integration.
JB183-EAP7.0-en-2-20180124 5
Chapter 1. Transitioning to Multi-tiered Applications
Objectives
• Perform development tasks with JBoss Developer Studio, Maven, and JBoss Enterprise
Application Platform.
Presentation Notes
Introduction
The Red Hat JBoss Developer Studio simplifies the process of developing Java EE enterprise
applications and has a number of built-in plugins for building, testing, packaging and
deploying applications to the JBoss EAP application server. Maven is the standard build,
packaging and deployment tool for Java EE applications.
Lecture
Discuss the features and benefits of the JBDS IDE. Emphasize the fact that it is based
on Eclipse and has a number of pre-integrated, well tested plugins that simplify Java EE
application development. Maven is the standard build, packaging and deployment tool for
Java EE applications and JBDS has built-in support for maven projects. Furthermore, unit
testing, deployment/undeployment and application server lifecycle can be managed from
within the JBDS IDE itself without resorting to the command line.
Summary
JBDS is a comprehensive IDE built on the eclipse platform which has a number of pre-
integrated, built-in plugins to simplify the development of Java EE applications. Maven is the
standard build tool for packaging and deploying Java SE and Java EE applications. JBDS has
built-in support for maven.
Guided Exercise
Tell your students to turn to the workshop in their books and follow along with you as you
demonstrate building and running the command line To Do List application that uses just the
Java SE API.
Wrap Up
Turn to the Summary section in the Student Guide and review bullets with the students.
Address any learner questions or comments and review the benefits with the students.
Review Questions
How would you re-design the command line TODO list application so that it is web-enabled,
accessible by multiple users, secure and store the tasks persistently. What are the different
types of multi-tier architectures that can accommodate this application?
• The application can be designed and implemented as a Java EE enterprise
application running on an application server. The combined web and EJB component
architecture as well as the web services architecture are a good fit for this
application.
6 JB183-EAP7.0-en-2-20180124
References
References
Here is a consolidated list of references from the chapter in the student guide.
References
JCP
https://www.jcp.org/en/home/index
References
Java EE 7 Specification JSR
https://www.jcp.org/en/jsr/detail?id=342
References
The Java Community Process (JCP)
https://jcp.org/en/home/index
References
Eclipse
https://eclipse.org
Apache Maven
https://maven.apache.org
JB183-EAP7.0-en-2-20180124 7
8
TRAINING
CHAPTER 2
JB183-EAP7.0-en-2-20180124 9
Chapter 2. Packaging and Deploying a Java EE Application
Chapter Information
Overview
In this chapter introduce application servers and EAP. Describe the process for packaging and
deploying applications to application servers.
Schedule
ILT/VT Schedule
Section Title Presentation & Time
Engagement Methods (minutes)
Introduction 3
1 Describing an Application Server P: Lecture 15
A: Multiple Choice Quiz 5
2 Identifying JNDI Resources P: Lecture 15
A: Guided Exercise 10
3 Packaging and Deploying a Java EE P: Lecture 15
Application A: Guided Exercise 15
Lab Packaging and 20
Deploying Applications
to an Application Server
Conclusion 2
Chapter Introduction
Introduction
This chapter enables the students to learn about the concept of an application server for
hosting and managing Java EE applications. Students learn about the different types of
containers within an application server and the different ways in which an application can be
packaged for deployment into an application server. Students also learn about JNDI and how
applications can register and look up resources at runtime using CDI, as well as the different
maven plugins available to package and deploy applications to EAP.
10 JB183-EAP7.0-en-2-20180124
Objectives
• Identify key features of application servers and describe Java EE server architecture.
Presentation Notes
Introduction
Introduce the concept of an application server as a runtime platform to host and manage
Java EE applications. The application server implements the Java EE specification and provides
APIs, tools, utilities, and a management framework for enterprise applications.
Lecture
Introduce the concept of an application server and it's characteristics. An application server
provides features like concurrency, distributed component architecture, portability to multiple
platforms, transaction management, web services, object relational mapping for databases
(ORM), asynchronous messaging and security for enterprise applications. Compare and
contrast the runtime differences between Java SE and Java EE applications. Briefly talk about
JBoss EAP and how it is designed, by highlighting the architecture of EAP and explain the
concept of modules and subsystems.
Quiz
Tell your students to turn to the quiz in their books. Once they complete it, discuss the
answers.
Summary
An Application Server provides the necessary runtime environment and infrastructure to host
and manage Java EE enterprise applications. Red Hat JBoss EAP 7 is a Java EE 7 compliant
application server that provides a reliable, efficient, light-weight and supported infrastructure
for deploying Java EE applications.
Objectives
• List the most common JNDI resource types and their typical naming convention.
Presentation Notes
Introduction
This section discusses the Java Naming and Directory Interface (JNDI), which is a Java API that
allows components to discover and look up objects at runtime via a logical name.
Lecture
The Java Naming and Directory Interface (JNDI) is a Java API for looking up resources (runtime
objects), and it allows components in an application to discover and look up objects via
JB183-EAP7.0-en-2-20180124 11
Chapter 2. Packaging and Deploying a Java EE Application
a logical name. Each resource is identified by a unique name, called the JNDI name or a
JNDI resource binding. Each of the different JNDI bindings are organized under a logical
Namespace, in a tree like hierarchy that is made available to applications for looking up
resources at runtime. Java EE 7 provides Contexts and Dependency Injection (CDI) to enable
components to obtain references to other component objects as well as application server
resources without manually instantiating them. Once you have configured the required
JNDI resource bindings at the application server level, you can then inject the resources into
applications that requires the resource by using a @Resource annotation. The application
sever takes care of instantiating the resource at runtime and provides a reference to it.
Guided Exercise
Tell your students to turn to the guided exercise in their books. When the students have
completed the exercise, discuss the activity and solution.
Summary
A JNDI resource is a logical object that is looked up and used by components in a Java
EE application. Each resource is identified by a unique name, called the JNDI name or a
JNDI resource binding. Each of the different JNDI bindings are organized under a logical
namespace, in a tree like hierarchy managed by the application server.
Objectives
• Package a simple Java EE application and deploy it to JBoss EAP using Maven.
Presentation Notes
Introduction
This section discusses the different ways a Java EE application can be packaged and the
process of deploying them to an application server.
Lecture
Briefly discuss the different ways to package an application - JAR, WAR and EAR and explain
the directory structure of each deployment type, along with the different deployment
descriptors within each type. Discuss the maven plugins available to package the application
and the process of deploying them to an application server.
Workshop
Tell your students to turn to the workshop in their books and follow along as you
demonstrate how to package and deploy a Java EE application to JBoss EAP. When the
students have completed the workshop, discuss the activity and solution.
12 JB183-EAP7.0-en-2-20180124
Summary
Summary
Java EE applications are packaged and deployed in different formats. The three most common
are JAR, WAR and EAR files. You can use Maven to deploy applications to JBoss EAP using the
Wildfly Maven plugin, which provides features to deploy and undeploy applications to EAP. It
supports deploying all three types of deployment units.
Lab
Have your students turn to the Lab in their books. When they have finished, discuss the
exercise and solution with them.
Wrap Up
Turn to the Summary section in the Student Guide and review bullets with the students.
Address any learner questions or comments and review the benefits with the students.
Review Questions
How would you package and deploy a large Java EE enterprise application that consists of
a number of smaller discrete applications, consisting of web and EJB components, each of
which connect to different databases and message queues? Assuming the application is to be
deployed to EAP as a single deployment unit, how would you achieve this?
• Package the web and EJB components separately into WAR and JAR files respectively.
• Use CDI resource injection to integrate with separate databases and message
queues.
• Use the Maven EAR plugin to package the application as a single EAR file and use the
maven wildfly plugin to deploy the EAR file to EAP.
References
Here is a consolidated list of references from the chapter in the student guide.
References
Further information is available in the Introduction to JBoss EAP chapter of the
Development Guide for Red Hat JBoss EAP 7.0:
https://access.redhat.com/documentation/en/red-hat-jboss-enterprise-
application-platform/
JB183-EAP7.0-en-2-20180124 13
Chapter 2. Packaging and Deploying a Java EE Application
References
Further information is available in the Remote JNDI lookup chapter and the
Contexts and Dependency Injection (CDI) chapter of the Development Guide for
Red Hat JBoss EAP:
https://access.redhat.com/documentation/en/red-hat-jboss-enterprise-
application-platform/7.0/
References
Further information is available in the Deploying Applications Using Maven chapter
of the Development Guide for Red Hat JBoss EAP 7.0:
https://access.redhat.com/documentation/en/red-hat-jboss-enterprise-
application-platform/
14 JB183-EAP7.0-en-2-20180124
TRAINING
CHAPTER 3
JB183-EAP7.0-en-2-20180124 15
Chapter 3. Creating Enterprise Java Beans
Chapter Information
Overview
In this chapter, introduce by describing the process for creating EJBs from POJOs and the
benefits of EJBs.
Schedule
ILT/VT Schedule
Section Title Presentation & Time
Engagement Methods (minutes)
Introduction 3
1 Converting a POJO to an EJB P: Lecture 30
A: Demo 15
A: Guided Exercise 20
2 Accessing EJBs Locally and Remotely P: Lecture 15
A: Guided Exercise 30
3 Describing the Life Cycle of an EJB P: Lecture 10
A: Multiple Choice Quiz 5
4 Demarcating Implicit and Explicit P: Lecture 25
Transactions A: Guided Exercise 30
Lab Creating Enterprise Java 30
Beans
Conclusion 2
Chapter Introduction
Introduction
This chapter enables the students to learn about the concept of an Enterprise Java Bean (EJB).
Students learn about the different types of EJBs, their characteristics, their lifecycle, and in
what scenarios they can be used. Students also learn about accessing EJB's locally and from
external clients, as well as the different ways to control transactions in EJB's.
16 JB183-EAP7.0-en-2-20180124
Objectives
• Convert a POJO to an EJB.
Presentation Notes
Introduction
Introduce the concept of an EJB as a portable Java EE component that encapsulates the core
business logic in an application. EJBs free the developer from writing code explicitly for multi-
threading, concurrency, transactions and security. If some students are unfamiliar with the
benefits, be sure to provide examples or explain concepts such as concurrency.
Lecture
Highlight the advantages of using EJBs for developing enterprise applications. Briefly talk
about the different types of EJBs in the Java EE specification, and their main characteristics.
Discuss the use cases where particular EJB's can be used and the rationale for using them.
Briefly explain how a simple POJO class can be converted to an EJB using the different types
of annotations. Highlight the use cases for a Singleton Session Bean and how the application
server can initialize the singleton at startup.
Demo
The demo illustrates the differences between a POJO and an EJB at a syntactical level. Focus
on showing the different annotations that are required to create an EJB.
Guided Exercise
Tell your students to turn to the guided exercise in their books. When the students have
completed the exercise, discuss the activity and solution.
Summary
An EJB is a portable Java EE component that is used for encapsulating the core business
logic in an enterprise application. EJBs can be of different types, each suited to a particular
use case and Java EE provides annotations that can be used to convert POJOs to EJBs in a
declarative manner.
Objectives
• Access an EJB both locally and remotely.
Presentation Notes
Introduction
This section discusses the different ways to access an EJB deployed on an application server.
Accessing EJBs locally in the same JVM as well as remote EJB access is discussed.
JB183-EAP7.0-en-2-20180124 17
Chapter 3. Creating Enterprise Java Beans
Lecture
Briefly discuss the different ways to access EJBs deployed in an application server. Discuss
how Java EE components can directly inject EJBs using the @EJB annotation. Students may
become unclear about the @Inject annotation as it relates to EJB. Let students know the
differences between the two annotations, but explain that CDI is covered in more detail in
later chapters.
Discuss how remote clients use JNDI to lookup and invoke methods on EJBs. Highlight the
JNDI naming standards in the Java EE specification the need for defining a remote interface
for an EJB to allow external access.
Guided Exercise
Tell your students to turn to the guided exercise in their books. When the students have
completed the exercise, discuss the activity and solution.
Summary
Clients running on the same JVM as the EJBs can inject the EJB directly using the @EJB
annotation, and remote clients can lookup and invoke methods on EJBs using JNDI.
Objectives
• Describe the life cycle of EJBs.
Presentation Notes
Introduction
This section discusses the lifecycle of the different types of EJBs. Students learn about how
the application server manages the lifecycle of the different types of EJBs and the different
types of annotations that can be used to customize the lifecycle of EJBs.
Lecture
Briefly highlight the lifecycle of each of the different types of EJBs and how the application
server manages their lifecycle. Discuss how the application server passivates Stateful Session
Beans to control memory consumption. Discuss how lifecycle of EJBs can be customized by
discussing the different types of annotations (lifecycle callback methods) that can be used on
each of the EJBs and give an example where this can be useful.
Quiz
Tell your students to turn to the quiz in their books. Once they complete it, discuss the
answers.
18 JB183-EAP7.0-en-2-20180124
Summary
Summary
The application server controls the lifecycle of the different types of EJBs in different ways.
A developer can customize the behavior further by using standard Java EE annotations on
lifecycle callback methods, where custom code can be executed. The application server
automatically invokes these callback methods as the EJBs transition between the various
states defined for each type of EJB.
Objectives
• Describe implicit and explicit transactions.
Presentation Notes
Introduction
This section discusses the concept of transactions in enterprise applications and why they are
important. Students learn about how the Java EE specification provides transaction support in
EJBs and the different types of transactions that can be used.
Lecture
Briefly talk about transactions and why they are important for enterprise applications that
are accessed concurrently by many users and systems. Highlight the different types of
transaction management in a Java EE application server - container managed (CMT) and bean
managed (BMT) and why you would choose one over the other. Highlight how the application
server manages transactions and does automatic rollback in CMT, and briefly talk about
the transaction attributes that can be used to customize this behavior. Briefly explain bean
managed transactions and the caveats when managing transactions explicitly.
Quiz
Tell your students to turn to the quiz in their books. Once they complete it, discuss the
answers.
Summary
Java EE provides support for transactions in two different ways - container managed and bean
managed. In CMT, the application server automatically takes care of committing and rollback,
whereas in BMT, the developer has full control. Transaction attributes can be used in CMT to
control transaction scope.
Lab
JB183-EAP7.0-en-2-20180124 19
Chapter 3. Creating Enterprise Java Beans
Have your students turn to the Lab in their books. When they have finished, discuss the
exercise and solution with them.
Wrap Up
Turn to the Summary section in the Student Guide and review bullets with the students.
Address any learner questions or comments and review the benefits with the students.
Review Questions
You have been asked to develop a couple of EJBs for a retail vendor, the first of which
interacts with an RDBMS and updates a number of tables on receipt of a purchase order
from a customer. The second EJB talks to an external web service and updates a separate set
of tables in the same database, ONLY after it receives a valid range of confirmation codes
(the valid range of code numbers are agreed upon before-hand by the retail vendor and
the provider of the external service) from the external web service. If the confirmation code
is outside the range of valid codes, you need to rollback the transaction. How would you
manage transactions in this scenario? What kind of transaction management strategy would
you use?
• Use CMT for the first EJB. The application server will automatically handle commit
and rollback in case of failure.
• Use BMT for the second EJB, since you need to explicitly check for valid confirmation
codes and commit or rollback based on the response from the external vendor.
References
Here is a consolidated list of references from the chapter in the student guide.
References
Further information is available in the Session Beans chapter and the Message
Driven Beans (MDB) chapter of the Development Guide for Red Hat JBoss EAP:
https://access.redhat.com/documentation/en/red-hat-jboss-enterprise-
application-platform/7.0/
References
Further information is available in the EJB chapter of the Development Guide for
Red Hat JBoss EAP:
https://access.redhat.com/documentation/en/red-hat-jboss-enterprise-
application-platform/7.0/
20 JB183-EAP7.0-en-2-20180124
TRAINING
CHAPTER 4
MANAGING PERSISTENCE
JB183-EAP7.0-en-2-20180124 21
Chapter 4. Managing Persistence
Chapter Information
Overview
In this chapter, provide an overview of the Persistence API, describe data persistence, use
annotations to validate data, and create custom queries.
Schedule
ILT/VT Schedule
Section Title Presentation & Time
Engagement Methods (minutes)
Introduction 3
1 Describing the Persistence API P: Lecture 45
A: Multiple Choice Quiz 5
2 Persisting Data P: Lecture 30
A: Guided Exercise 30
3 Annotating Classes to Validate Beans P: Lecture 15
A: Guided Exercise 15
4 Creating Queries P: Lecture 20
A: Guided Exercise 25
Lab Managing Persistence 30
Conclusion 2
Chapter Introduction
Introduction
This chapter enables the students to learn about database persistence in Java applications.
To understand this broad and complex topic, this chapter focuses on the persistence API,
creating entities, validating data and creating custom queries. The following chapter goes
deeper into topics such as entity relationships.
Objectives
• Describe the Persistence API.
22 JB183-EAP7.0-en-2-20180124
Presentation Notes
Presentation Notes
Introduction
Many students should already have experience with databases and know some of the basic
concepts. This section introduces some of the annotations, describes entity managers, and
has some brief examples. This is the longest lecture section in the class and plenty of time
should be provided to make sure students understand this fundamental section.
Lecture
Introduce the concept of Object Relational Mapping by relying heavily on using the given
examples from the student guide. These concepts are best learned by providing concrete
examples rather than high level discussion. When describing an entity, relate the concept
back to a POJO so students understand how to correctly annotate an entity. Be sure students
understand the significance and need for object IDs in the databases and that they are able
to recognize the advantages of the different ID generation strategies.
The entity manager examples contain several CDI topics that are not yet fully explained in the
course. At this point, provide students only with as much information on CDI as they need to
use an entity manager without going into too much detail about CDI, as this is covered more
thoroughly in a later chapter.
Quiz
Tell your students to turn to the quiz in their books. Once they complete it, discuss the
answers.
Summary
In Java EE applications, JPA provides the ability for applications to persist data.
Objectives
• Persist data to a data store using entities.
Presentation Notes
Introduction
This section takes a closer look at entities and how to configure the entity manager. Students
learn to create entities and configure the persistence.xml file to access and modify data in
a database.
Lecture
Highlight the difference between a POJO and an entity class and be sure students understand
what an entity represents in an ORM. When describing this concepts, refer to concrete
examples that may make the abstract concepts easier to understand for students. A lot of
the concepts about entity states may be challenging for students, and understanding this
JB183-EAP7.0-en-2-20180124 23
Chapter 4. Managing Persistence
point is not an exam objective but it is worth knowing and at least having a foundational
understanding when learning about entities. Be sure that students are comfortable
understanding when to use each of the entity manager primary methods.
When describing the persistence.xml file, make sure students understand that the
data source name is very important, but that they are not required to remember all of the
individual properties and property names.
Demo
Tell your students to follow along as you demonstrate how to create an entity and persist an
instance of that entity into a database.
Guided Exercise
Tell your students to turn to the guided exercise in their books. When the students have
completed the exercise, discuss the activity and solution.
Summary
The entity manager is configured using the persistence.xml and contains methods for
CRUD operations.
Objectives
• Annotate beans to validate data.
Presentation Notes
Introduction
This section discusses using annotations in entities to validate data.
Lecture
At this point in the course, students should feel comfortable with JEE syntax and annotations.
This section introduces lots of new annotations, which can be overwhelming. Reassure
students that they can reference these annotations by using the available documentation.
If students are confused about manual versus automatic invocation, be sure they can
understand that manual invocation is primarily only used for testing purposes and it is not an
exam objective.
Guided Exercise
Tell your students to turn to the guided exercise in their books. When the students have
completed the exercise, discuss the activity and solution.
24 JB183-EAP7.0-en-2-20180124
Summary
Summary
Use annotations in an entity to validate data.
Objectives
• Create a query using the Java Persistence Query Language
Presentation Notes
Introduction
This section introduces several approaches for creating custom queries for different database
operations using JPQL.
Lecture
Introduce students to JPQL and make sure they are familiar with its similarity to SQL. Identify
the different approaches for writing queries: named queries, positional parameters, and
named parameters. Explain the benefits of using named queries, primarily focusing on
the fact that they are reusable. Pay special attention to explaining the syntax for how to
create a named query and multiple named queries. With respect to the approaches for using
parameters in queries, both approaches are based on the user's preference.
Guided Exercise
Tell your students to turn to the guided exercise in their books. When the students have
completed the exercise, discuss the activity and solution.
Summary
PQL is a query language that supports dynamic and static queries. Queries can be created
with named parameters and positional parameters.
Lab
Have your students turn to the Lab in their books. When they have finished, discuss the
exercise and solution with them.
Wrap Up
Turn to the Summary section in the Student Guide and review bullets with the students.
Address any learner questions or comments and review the benefits with the students.
Review Questions
Which changes are required to make a Java SE application capable of using JPA for
persistence?
JB183-EAP7.0-en-2-20180124 25
Chapter 4. Managing Persistence
References
Here is a consolidated list of references from the chapter in the student guide.
References
Further information about configuring composite keys is available in the Public API
for Red Hat JBoss EAP 7, found at
https://developers.redhat.com/apidocs/eap/7.0.0/
References
Java Persistence JSR
https://www.jcp.org/en/jsr/detail?id=338
References
Further information is available in the Development Guide for Java Persistence API for
Red Hat JBoss EAP 7, found at
https://docs.jboss.org/author/display/AS7/JPA+Reference+Guide/
Persisting Data
References
Further information is available in the Development Guide for Java Persistence API for
Red Hat JBoss EAP 7, found at
https://docs.jboss.org/author/display/AS7/JPA+Reference+Guide/
References
Bean Validation API
http://beanvalidation.org/
26 JB183-EAP7.0-en-2-20180124
References
References
Further information is available in the JBoss Application Server 7 guide for Red Hat
JBoss EAP 7 at
https://docs.jboss.org/author/display/AS71/Documentation/
JB183-EAP7.0-en-2-20180124 27
28
TRAINING
CHAPTER 5
MANAGING ENTITY
RELATIONSHIPS
JB183-EAP7.0-en-2-20180124 29
Chapter 5. Managing Entity Relationships
Chapter Information
Overview
In this chapter, describe entity relationships and how to configure one-to-one, one-to-many,
and many-to-many relationships.
Schedule
ILT/VT Schedule
Section Title Presentation & Time
Engagement Methods (minutes)
Introduction 3
1 Configuring Entity Relationships P: Lecture 25
A: Demo 15
A: Guided Exercise 35
2 Describing Many-to-many Entity P: Lecture 10
Relationships A: Matching Quiz 5
Lab Managing Entity 25
Relationships
Conclusion 2
Chapter Introduction
Introduction
This chapter builds on persistence by introducing students to entity relationships. This
chapter covers the different types of entity relationships, when entity relationships are
required, and strategies for configuring the relationships using annotations.
Objectives
• Configure one-to-one and one-to-many entity relationships.
30 JB183-EAP7.0-en-2-20180124
Presentation Notes
Presentation Notes
Introduction
Students at this point in the course should have a good foundational understanding of
persistence. Use that foundation to introduce the more complex topic of entity relationships.
One-to-one and one-to-many relationships are best explained using simple and real-word
examples, such as the ones provided in the student guide.
Lecture
Introduce the concept of entity relationships by describing more complex data objects that
require multiple database tables. Because of this, entities need to have explicitly defined
relationships. Use the example of a User and a social security number to explain a one-to-one
relationship. To explain a one-to-many relationship, use the example of the Car, Make, Model,
and SubModel entities.
In the previous section, students learned how to include JPQL queries. In this section,
emphasize the need to make sure that the queries are efficient using Join Fetch and by
limiting which data is pulled by the query. Students need a solid understanding about Lazy
versus Eager loading and when to use each.
Demo
Tell your students to turn to the demo in their books and follow along as you demonstrate
how to configure entity relationships in entities.
Guided Exercise
Tell your students to turn to the guided exercise in their books. When the students have
completed the exercise, discuss the activity and solution.
Summary
Relationships between JPA entity classes are mapped using annotations.
Objectives
• Describe many-to-many entity relationships.
Presentation Notes
Introduction
This section builds on the previous section to introduce the concept of many-to-many entity
relationships.
JB183-EAP7.0-en-2-20180124 31
Chapter 5. Managing Entity Relationships
Lecture
Use the previous section about one-to-one and one-to-many relationships to introduce a
theoretical example such as the relationship between Student and Class entities. Explain
both how these two entities relate to each other and the necessary database and entity
configurations to enable this relationship.
The added complexity for this type of relationship is that a new table is required to map
the relationship between each instance in the many-to-many relationship. Ensure students
understand that even though this table must exist in the database, it does not need to be
implemented as an entity. In addition, rather than adding annotations referring to a column,
the annotations refer to this new table.
Quiz
Tell your students to turn to the quiz in their books. Once they complete it, discuss the
answers.
Summary
A many-to-many relationship requires a new table to map the related instances.
Lab
Have your students turn to the Lab in their books. When they have finished, discuss the
exercise and solution with them.
Wrap Up
Turn to the Summary section in the Student Guide and review bullets with the students.
Address any learner questions or comments and review the benefits with the students.
Review Questions
Describe an example of a one-to-one relationship, a one-to-many relationship, and a many-
to-many relationship.
This is an open-ended question.
References
Here is a consolidated list of references from the chapter in the student guide.
References
Further information is available in the JPA chapter of the Development Guide for
Red Hat JBoss EAP 7 at
https://access.redhat.com/documentation/en/red-hat-jboss-enterprise-
application-platform/
32 JB183-EAP7.0-en-2-20180124
References
References
Further information is available in the JPA chapter of the Development Guide for
Red Hat JBoss EAP 7; at
https://access.redhat.com/documentation/en/red-hat-jboss-enterprise-
application-platform/
JB183-EAP7.0-en-2-20180124 33
34
TRAINING
CHAPTER 6
JB183-EAP7.0-en-2-20180124 35
Chapter 6. Creating REST Services
Chapter Information
Overview
In this chapter, provide an overview of web services and describe how to create and consume
REST services.
Schedule
ILT/VT Schedule
Section Title Presentation & Time
Engagement Methods (minutes)
Introduction 3
1 Describing Web Services Concepts P: Lecture 15
A: Matching Quiz 5
2 Creating REST Services with JAX-RS P: Lecture 35
A: Guided Exercise 15
3 Consuming a REST Service P: Lecture 20
A: Matching Quiz 5
Lab Creating REST Services 45
Conclusion 2
Chapter Introduction
Introduction
This chapter introduces the topic of web services, particularly REST services, to students.
Objectives
• Describe web services concepts and list types of web services.
36 JB183-EAP7.0-en-2-20180124
Presentation Notes
Presentation Notes
Introduction
This section is primarily a high level discussion about web services and how services fit into
the JEE application architecture.
Lecture
Introduce the benefits of using web services and give some examples about when a service
oriented architecture is beneficial. Describe the two types of web services: REST and JAX-WS.
Inform students that JAX-WS is mentioned in this section, but that it is not an exam objective
and is not covered in the rest of the course. This is because JAX-WS is not as prevalent as REST
services. For this reason, spend more time discussing REST services and its benefits.
Quiz
Tell your students to turn to the quiz in their books. Once they complete it, discuss the
answers.
Summary
JAX-RS and JAX-WS are two implementations in Java EE for web services.
Objectives
• Create a REST service using the JAX-RS specification.
Presentation Notes
Introduction
This section explores REST services and describes the process for creating REST services.
Lecture
The previous section introduces REST services and general information about services. In this
section, students are tasked with creating REST web services. Introduce the many annotations
required to create a REST service as well as how to active the REST service. It is important for
students to know how to take a simple EJB class and convert it to an exposed REST service
and how to ensure that the path of the REST service is properly exposed.
Students need a firm understanding of when to use certain types of JAX-RS annotations,
such as @GET and @POST. Make sure they understand how these annotations relate back to
HTTP protocols and how the services interact with the persistence layer. Also emphasize the
importance of setting the path elements in order to produce the expected endpoint paths,
including using path parameters.
Another important aspect of configuring the services is setting the type of response and
request expected. The annotations @Produces and @Consumes are important for setting the
JB183-EAP7.0-en-2-20180124 37
Chapter 6. Creating REST Services
expected media type. Make sure students are comfortable setting both JSON and XML as the
types.
Guided Exercise
Tell your students to turn to the guided exercise in their books. When the students have
completed the exercise, discuss the activity and solution.
Summary
A JAX-RS RESTful web service consists of one or more classes utilizing the JAX-RS annotations
to create a web service.
Objectives
• Create a client application that can invoke REST APIs remotely.
Presentation Notes
Introduction
This section explores how to consume REST services. This topic is useful for students,
however it is not required for students to actually create their own consumers.
Lecture
Students should have a good understanding of REST services at this point in the course. This
section describes the process for consuming REST services programatically. This topic is very
useful for students to have an idea about how this is done, but it is not an exam objective or
a requirement for them to be able to create a consumer. This section, rather, explains how to
leverage the available APIs to create the consumer.
Make sure students are very familiar with the HTTP status codes as these are used
throughout the course when deciphering service responses. Primarily, make sure they
understand 200, 400, 403, and 404 and when they would expect receive these types of status
codes.
Quiz
Tell your students to turn to the quiz in their books. Once they complete it, discuss the
answers.
Summary
A consumer is programatically defined using WebTarget and Response objects.
38 JB183-EAP7.0-en-2-20180124
Lab
Lab
Have your students turn to the Lab in their books. When they have finished, discuss the
exercise and solution with them.
Wrap Up
Turn to the Summary section in the Student Guide and review bullets with the students.
Address any learner questions or comments and review the benefits with the students.
Review Questions
What are the benefits to using a REST service oriented application architecture?
This is an open-ended question.
References
Here is a consolidated list of references from the chapter in the student guide.
References
JSR-311 Java API for RESTful Web Services 2.0
http://www.jcp.org/en/jsr/detail?id=311
References
Further information is available in the Developing Web Services Guide for Red Hat
JBoss EAP 7; at
https://access.redhat.com/documentation/en-us/
red_hat_jboss_enterprise_application_platform/
References
Further information is available in the Developing Web Services Guide for
Red Hat JBoss EAP 7; at
https://access.redhat.com/documentation/en-us/
red_hat_jboss_enterprise_application_platform/
JB183-EAP7.0-en-2-20180124 39
Chapter 6. Creating REST Services
References
JSR-311 Java API for RESTful Web Services 2.0
http://www.jcp.org/en/jsr/detail?id=311
References
Further information is available in the Developing Web Services Guide for Red Hat
JBoss EAP 7 at
https://access.redhat.com/documentation/en-us/
red_hat_jboss_enterprise_application_platform/
40 JB183-EAP7.0-en-2-20180124
TRAINING
CHAPTER 7
JB183-EAP7.0-en-2-20180124 41
Chapter 7. Implementing Contexts and Dependency Injection
Chapter Information
Overview
In this chapter, provide an overview of Context Dependency Injection.
Schedule
ILT/VT Schedule
Section Title Presentation & Time
Engagement Methods (minutes)
Introduction 3
1 Contrasting Dependency Injection P: Lecture 25
and Resource Injection A: Guided Exercise 25
2 Applying Contextual Scopes P: Lecture 15
A: Guided Exercise 15
Lab Implementing Contexts 25
and Dependency
Injection
Conclusion 2
Chapter Introduction
Introduction
This chapter formally introduces CDI basics as well as more advanced topics such as qualifiers
and producers.
Objectives
• Describe resource injection, dependency injection, and the differences between them.
42 JB183-EAP7.0-en-2-20180124
Presentation Notes
Presentation Notes
Introduction
This section formally introduces CDI as a topic, although many aspects of CDI are used by
students at this point in the course. When instructing this section, refer to previous exercises
as a reference.
Lecture
Introduce the benefits of CDI and how dependency injection is typically used in application.
Describe contexts and dependency injection as two separate aspects of CDI. Describe the
requirements for using dependency injection and what injecting a resource looks like in
Java code. Remind students that they have seen examples of this before. Further, illustrate
the differences between dependency injection and resource injection, such as the fact that
resource injection is not type safe like CDI.
Explain the issue of ambiguous implementations when injecting an interface and how
qualifiers can resolve this issue. Emphasize the dependency injection is a big advantage
because it delays decisions about implementation, but that can introduce several design
issues if developers aren't careful.When introducing producers, emphasize that a producer
is used to inject traditionally non-injectable objects injectable. This is particularly useful for
resource such as entity managers.
Finally, make sure students do not become confused by the differences between EJB and CDI.
The final paragraphs in this section highlights the differences between the two.
Guided Exercise
Tell your students to turn to the guided exercise in their books. When the students have
completed the exercise, discuss the activity and solution.
Summary
CDI is able to inject regular Java classes directly, while resource injection cannot inject regular
classes and instead refers to the resource by JNDI names.
Objectives
• Applying scopes to beans appropriately.
Presentation Notes
Introduction
This section explores the "context" portion of Context Dependency Injection.
JB183-EAP7.0-en-2-20180124 43
Chapter 7. Implementing Contexts and Dependency Injection
Lecture
This short section introduces students to the different types of contexts that are available
to be applied to CDI beans. Make sure that students thoroughly understand the different
scopes and when to use each scope. Provide examples to know when to use each scope.
Briefly introduce the @Named annotation as a way to expose beans for JSF and other front end
libraries. Do not spend too much time on this part of the section as front end development is
outside the scope of this course.
Guided Exercise
Tell your students to turn to the guided exercise in their books. When the students have
completed the exercise, discuss the activity and solution.
Summary
The @Named annotation provides a mechanism for EJBs to be referenced using expression
language (EL) found in front-end libraries, such as Java Server Faces (JSF) pages.
Lab
Have your students turn to the Lab in their books. When they have finished, discuss the
exercise and solution with them.
Wrap Up
Turn to the Summary section in the Student Guide and review bullets with the students.
Address any learner questions or comments and review the benefits with the students.
Review Questions
Which scope maintains users data for the duration of the application's deployment?
Application Scope
References
Here is a consolidated list of references from the chapter in the student guide.
References
JSR 346 Contexts and Dependency Injection for Java
https://www.jcp.org/en/jsr/detail?id=346
44 JB183-EAP7.0-en-2-20180124
References
References
Further information is available in the CDI chapter of the Development Guide for
Red Hat JBoss EAP:
https://access.redhat.com/documentation/en/red-hat-jboss-enterprise-
application-platform/7.0/
References
Further information is available in the CDI chapter of the Development Guide for
Red Hat JBoss EAP:
https://access.redhat.com/documentation/en/red-hat-jboss-enterprise-
application-platform/7.0/
JB183-EAP7.0-en-2-20180124 45
46
TRAINING
CHAPTER 8
CREATING MESSAGING
APPLICATIONS WITH JMS
JB183-EAP7.0-en-2-20180124 47
Chapter 8. Creating Messaging Applications with JMS
Chapter Information
Overview
In this chapter, introduce messaging concepts and describe how to create a JMS client and
MDB.
Schedule
ILT/VT Schedule
Section Title Presentation & Time
Engagement Methods (minutes)
Introduction 3
1 Describing Messaging Concepts P: Lecture 15
A: Matching Quiz 5
2 Describing JMS Architecture P: Lecture 25
A: Matching Quiz 5
3 Creating a JMS Client P: Lecture 10
A: Demo 10
A: Guided Exercise 20
4 Creating MDBs P: Lecture 20
A: Guided Exercise 30
Lab Creating Messaging 30
Applications with JMS
Conclusion 2
Chapter Introduction
Introduction
This chapter introduces messaging concepts and provides a basic introduction to
programming MDBs and messaging clients.
48 JB183-EAP7.0-en-2-20180124
Objectives
• Describe the JMS API and name the objects used in sending and receiving messages.
Presentation Notes
Introduction
This section is primarily a high level discussion about messaging concepts and the JMS API.
Lecture
Introduce the JMS API and how messaging fits into the architecture of JEE applications. Use
examples to explain the benefits of a messaging system and how designing asynchronous
and decoupled applications can pose some challenges. Outline the basic concepts of
a messaging system, such as queues and topics. Make sure students understand the
differences between both and when to use a topic or a queue.
Quiz
Tell your students to turn to the quiz in their books. Once they complete it, discuss the
answers.
Summary
By enabling asynchronous processing between loosely-coupled systems, messaging allows
developers to build applications that are more efficient, more easily scaled, and more reliable.
Objectives
• Describe the components that make up the JMS API.
Presentation Notes
Introduction
This section explores the JMS architecture and take a closer look at aspects of the JMS API.
Lecture
Introduce the JMS API as the way to use messaging in an application deployed on EAP 7. This
section goes into some detail regarding configuring message in EAP, however this is not a
requirement of the course. One aspect, however, that is required is being able to decipher the
JNDI name for a queue or topic from the server configuration file. Be sure that students are
able to recognize the full JNDI name for the queue from within the standalone.xml.
Using the provided sample code for each aspect of the API, explain how the Destination,
Connection, etc. all fit into the messaging system. Similarly, review the components of a JMS
message and be sure students understand how to acquire the contents of a message.
JB183-EAP7.0-en-2-20180124 49
Chapter 8. Creating Messaging Applications with JMS
Quiz
Tell your students to turn to the quiz in their books. Once they complete it, discuss the
answers.
Summary
There are three parts to the basic structure of a JMS message: headers, properties, and a
body.
Objectives
• Create a JMS client that produces and/or consumes messages using the JMS API.
Presentation Notes
Introduction
This section explores how to create a JMS client to interact with a messaging system.
Lecture
In this section, introduce the concept of JMS clients and how to programatically create them.
Be sure students understand how to both inject administered objects such as queues and
topics and make sure they understand that these objects must be referenced by their JNDI
name, NOT just by the queue name. Further, explain the use for the JMS Context and the JMS
Connection Factory in order to create a client.
Explain the requirements and necessary programming to create both a producer and a
consumer. Students should feel comfortable creating both. Use both the demonstration and
code example to explain how each line is necessary to produce and consume messages.
Demo
Tell your students to turn to the demo in their books and follow along as you demonstrate
how to configure a JMS client.
Guided Exercise
Tell your students to turn to the guided exercise in their books. When the students have
completed the exercise, discuss the activity and solution.
Summary
There are three parts to the basic structure of a JMS message: headers, properties, and a
body.
50 JB183-EAP7.0-en-2-20180124
Instructional strategies for Creating MDBs
Objectives
• Create, package, and deploy a Message Driven Bean.
Presentation Notes
Introduction
This section introduces the concept of MDBs and explains how to create and deploy an MDB.
Lecture
In this section, students are introduced to message driven beans, which are beans that
listen on specific queues to asynchronously process messages received on those queues.
Use the code example to explain how to create an MDB and show typical behavior for
an onMessage() method. Be sure that students understand how to use the necessary
annotations to create the MDB and that the destination lookup for the queue refers to the
queue's JNDI name. Review all of the different properties when discussing the JMS activation
annotations.
Guided Exercise
Tell your students to turn to the guided exercise in their books. When the students have
completed the exercise, discuss the activity and solution.
Summary
Message-driven beans (MDBs) enable asynchronous consumption of messages from a JMS
destination.
Lab
Have your students turn to the Lab in their books. When they have finished, discuss the
exercise and solution with them.
Wrap Up
Turn to the Summary section in the Student Guide and review bullets with the students.
Address any learner questions or comments and review the benefits with the students.
Review Questions
What are the differences between a queue and a topic?
This is an open-ended question.
References
JB183-EAP7.0-en-2-20180124 51
Chapter 8. Creating Messaging Applications with JMS
Here is a consolidated list of references from the chapter in the student guide.
References
Further information is available in the JMS chapter of the Development Guide for
Red Hat JBoss EAP 7 at
https://access.redhat.com/documentation/en/red-hat-jboss-enterprise-
application-platform/
References
JMS 2.0 JSR
https://jcp.org/en/jsr/detail?id=343
References
Further information is available in the JMS chapter of the Development Guide for
Red Hat JBoss EAP 7; at
https://access.redhat.com/documentation/en/red-hat-jboss-enterprise-
application-platform/
References
Further information is available in the JMS chapter of the Configuring Messaging
guide for Red Hat JBoss EAP 7; at
https://access.redhat.com/documentation/en/red-hat-jboss-enterprise-
application-platform/
Creating MDBs
References
Further information is available in the JMS chapter of the Configuring Messaging
guide for Red Hat JBoss EAP 7; at
https://access.redhat.com/documentation/en/red-hat-jboss-enterprise-
application-platform/
52 JB183-EAP7.0-en-2-20180124
TRAINING
CHAPTER 9
SECURING JAVA EE
APPLICATIONS
JB183-EAP7.0-en-2-20180124 53
Chapter 9. Securing Java EE Applications
Chapter Information
Overview
In this chapter, students learn how to secure Java EE applications and REST services.
Schedule
ILT/VT Schedule
Section Title Presentation & Time
Engagement Methods (minutes)
Introduction 3
1 Describing the JAAS Specification P: Lecture 20
A: Matching Quiz 5
2 Configuring a Security Domain in P: Lecture 15
JBoss EAP A: Guided Exercise 15
3 Securing a REST API P: Lecture 20
A: Demo 10
A: Guided Exercise 20
Lab Securing Java EE 35
Applications
Conclusion 2
Chapter Introduction
Introduction
This chapter introduces security concepts for EAP and application development.
Objectives
• Describe the JAAS specification.
54 JB183-EAP7.0-en-2-20180124
Presentation Notes
Presentation Notes
Introduction
This section introduces the JAAS specification and describes how to configure security
declaratively and programatically.
Lecture
Introduce students to security at a high level. Use the provided diagram to demonstrate
how security fits in the architecture of Java EE applications. Describe JAAS and how it is
used to configure security within Java EE applications. Be sure that students understand
authentication versus authorization.
Describe declarative security to students and illustrate the point by using the sample code
provided for the web.xml file. Be sure that students understand the meanings of all of the
security annotations and when they are used. For programmatic security, use the EJB code
example that demonstrates programmatic security as a way to explain how the EJBContext
code is used to restrict access to certain users. While it is useful for students to know how to
perform programmatic security constraints, it is not required for this course.
Quiz
Tell your students to turn to the quiz in their books. Once they complete it, discuss the
answers.
Summary
Java Authentication and Authorization Service (JAAS) is a security API that is used to
implement user authentication and authorization in Java applications.
Objectives
• Configure a security domain in the JBoss EAP application server.
Presentation Notes
Introduction
This section explores the EAP security domain and describes how to configure security within
the server.
Lecture
This topic may be difficult for students because it delves closer to the administrative side
of Java EE development. While it is worthwhile to explain security realms and security
domains, students are not required to be able to fully configure these in EAP. Rather, it is
more important that students understand how to set up the property files and understand
the JAAS modules at a high level. Be sure students understand how to view the configuration
in the EAP server.
JB183-EAP7.0-en-2-20180124 55
Chapter 9. Securing Java EE Applications
Guided Exercise
Tell your students to turn to the guided exercise in their books. When the students have
completed the exercise, discuss the activity and solution.
Summary
In EAP, a security domain defines a set of JAAS declarative security configurations.
Objectives
• Secure a REST API with authentication and role-based authorization.
Presentation Notes
Introduction
This section explores how to secure a REST API.
Lecture
This section describes the concepts and requirements for enabling declarative security in
REST services. Students must be able to configure the context-param to enable role based
security, configure the web.xml and use the RESTEasy annotations to restrict access. The
annotations should be familiar, but be sure that students understand how the annotations
are used to restrict particular endpoints to certain roles. In addition, be careful to explain
how the restrictions impact the paths that are available based on the role that is currently
authenticated.
Demo
Tell your students to turn to the demo in their books and follow along as you demonstrate
how enable security in a REST service.
Guided Exercise
Tell your students to turn to the guided exercise in their books. When the students have
completed the exercise, discuss the activity and solution.
Summary
To use the RESTEasy security annotations, add the resteasy.role.based.security context
parameter to the application's web.xml file.
Lab
56 JB183-EAP7.0-en-2-20180124
Wrap Up
Have your students turn to the Lab in their books. When they have finished, discuss the
exercise and solution with them.
Wrap Up
Turn to the Summary section in the Student Guide and review bullets with the students.
Address any learner questions or comments and review the benefits with the students.
Review Questions
What is the procedure for configuring authentication and authorization in a REST service?
This is an open-ended question.
References
Here is a consolidated list of references from the chapter in the student guide.
References
JSR-196 Java Authentication Service Provider Interface for Containers
https://www.jcp.org/en/jsr/detail?id=196
References
Further information is available in the Security chapter of the Development Guide for
Red Hat JBoss EAP 7 at
https://access.redhat.com/documentation/en/red-hat-jboss-enterprise-
application-platform/
References
Further information is available in the Login Module Reference Guide for Red Hat
JBoss EAP 7 at
https://access.redhat.com/documentation/en/red-hat-jboss-enterprise-
application-platform/
References
Further information is available in the Security chapter of the Development Guide for
Red Hat JBoss EAP 7 at
https://access.redhat.com/documentation/en/red-hat-jboss-enterprise-
application-platform/
JB183-EAP7.0-en-2-20180124 57
Chapter 9. Securing Java EE Applications
References
Further information is available in the Developing Web Services Applications guide for
Red Hat JBoss EAP 7 at
https://access.redhat.com/documentation/en/red-hat-jboss-enterprise-
application-platform/
58 JB183-EAP7.0-en-2-20180124
TRAINING
CHAPTER 10
COMPREHENSIVE REVIEW:
RED HAT APPLICATION
DEVELOPMENT I:
PROGRAMMING IN JAVA EE
JB183-EAP7.0-en-2-20180124 59
Chapter 10. Comprehensive Review: Red Hat Application Development I: Programming in Java EE
Chapter Information
Overview
In this chapter, students will review most of the learning objectives of Red Hat Application
Development I: Programming in Java EE.
Schedule
ILT/VT Schedule
Section Title Presentation & Time
Engagement Methods (minutes)
1 Comprehensive Review P: Lecture 5
Lab: Creating an API using JAX-RS A: Review Lab 75
Lab: Persisting Data with JPA A: Review Lab 75
Lab: Securing the REST API with JAAS A: Review Lab 60
Conclusion 5
Chapter Introduction
This chapter will provide the students time to review the core learning objectives of this
course.
Introduce this chapter by explaining that this part of the course is a self-paced hands-on
review of the course material. Encourage students to feel free to review content, exercises,
and labs previously covered in the course in addition to the exercises in this chapter.
60 JB183-EAP7.0-en-2-20180124
Conclusion
Conclusion
Conclude the course. Answer any final student questions, ensure that students are reminded
to complete any requested feedback surveys, and thank the students for their attendance.
JB183-EAP7.0-en-2-20180124 61
62









