41
Marius Bogoevici Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework Kit Edition 2.0.0

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

  • Upload
    buidieu

  • View
    217

  • Download
    3

Embed Size (px)

Citation preview

Page 1: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

Marius Bogoevici

Red Hat JBoss Web FrameworkKit 2Snowdrop Sportsclub Example

for use with JBoss Web Framework KitEdition 2.0.0

Page 2: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example

for use with JBoss Web Framework KitEdition 2.0.0

Marius BogoeviciRed [email protected]

Edited byLaura BaileyRed [email protected]

Rebecca NewtonRed [email protected]

Page 3: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

Legal Notice

Copyright © 2011 Red Hat, Inc.

This document is licensed by Red Hat under the Creative Commons Attribution-ShareAlike 3.0 UnportedLicense. If you distribute this document, or a modified version of it, you must provide attribution to RedHat, Inc. and provide a link to the original. If the document is modified, all Red Hat trademarks must beremoved.

Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section4d of CC-BY-SA to the fullest extent permitted by applicable law.

Red Hat, Red Hat Enterprise Linux, the Shadowman logo, JBoss, MetaMatrix, 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.

Java ® is a registered trademark of Oracle and/or its affiliates.

XFS ® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United Statesand/or other countries.

MySQL ® is a registered trademark of MySQL AB in the United States, the European Union and othercountries.

Node.js ® is an official trademark of Joyent. Red Hat Software Collections is not formally related to orendorsed by the official Joyent Node.js open source or commercial project.

The OpenStack ® Word Mark and OpenStack Logo are either registered trademarks/service marks ortrademarks/service marks of the OpenStack Foundation, in the United States and other countries andare used with the OpenStack Foundation's permission. We are not affiliated with, endorsed orsponsored by the OpenStack Foundation, or the OpenStack community.

All other trademarks are the property of their respective owners.

Abstract

This book provides a walkthrough of the JBoss Snowdrop Sportsclub example. It illustrates several usecases for integrating the JBoss Enterprise Platforms with the Spring Framework.

Page 4: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Table of Contents

Preface1. Document Conventions

1.1. Typographic Conventions1.2. Pull-quote Conventions1.3. Notes and Warnings

2. Getting Help and Giving Feedback2.1. Do You Need Help?2.2. Give us Feedback

Chapter 1. Introduction1.1. Sportsclub example variants1.2. Building the application1.3. Preparing your JBoss Enterprise Platform1.4. Deploying the application1.5. Sportsclub and JBoss Developer Studio

Chapter 2. Understanding the Application Structure2.1. The Application Structure and its Use Cases2.2. A comparative look of the project modules

Chapter 3. Using JBoss and Spring together3.1. JBoss/Spring integration use cases3.2. The domain model3.3. Persistence implementation: JPA and Hibernate

3.3.1. The Hibernate implementation3.3.2. The JPA implementation3.3.3. Unit testing the repositories

3.4. Service Layer3.4.1. The Spring-based service layer3.4.2. The EJB service layer

3.4.2.1. The Spring Deployer3.4.2.2. Injection into EJBs

3.5. Presentation Layer3.5.1. Subscriptions: JSF and Spring3.5.2. Reservations: JSF/Spring integration3.5.3. Reservations-Webflow: Conversation-based reservations (Spring 3 and Spring 3.1 variantsonly)3.5.4. Invoicing: Spring MVC and EJB3.5.5. A problem of reusing content

3.6. Enterprise Integration Features3.6.1. Payment processing: JMS integration through JCA3.6.2. Aspects and auditing3.6.3. Configuring Spring beans through JMX3.6.4. Payment processing: exposing a JAX-WS web service3.6.5. Implementing a Spring Web Services web service

3.7. Secure invoicing: JBoss-preauthenticated security

Revision History

33345556

777899

121212

141416181820202121212222222323

25262930303132343436

38

Table of Contents

1

Page 5: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example

2

Page 6: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

Preface

1. Document ConventionsThis manual uses several conventions to highlight certain words and phrases and draw attention tospecific pieces of information.

In PDF and paper editions, this manual uses typefaces drawn from the Liberation Fonts set. TheLiberation Fonts set is also used in HTML editions if the set is installed on your system. If not, alternativebut equivalent typefaces are displayed. Note: Red Hat Enterprise Linux 5 and later include the LiberationFonts set by default.

1.1. Typographic ConventionsFour typographic conventions are used to call attention to specific words and phrases. Theseconventions, and the circumstances they apply to, are as follows.

Mono-spaced Bold

Used to highlight system input, including shell commands, file names and paths. Also used to highlightkeys and key combinations. For example:

To see the contents of the file my_next_bestselling_novel in your current workingdirectory, enter the cat my_next_bestselling_novel command at the shell promptand press Enter to execute the command.

The above includes a file name, a shell command and a key, all presented in mono-spaced bold and alldistinguishable thanks to context.

Key combinations can be distinguished from an individual key by the plus sign that connects each part ofa key combination. For example:

Press Enter to execute the command.

Press Ctrl+Alt+F2 to switch to a virtual terminal.

The first example highlights a particular key to press. The second example highlights a key combination:a set of three keys pressed simultaneously.

If source code is discussed, class names, methods, functions, variable names and returned valuesmentioned within a paragraph will be presented as above, in mono-spaced bold. For example:

File-related classes include filesystem for file systems, file for files, and dir fordirectories. Each class has its own associated set of permissions.

Proportional Bold

This denotes words or phrases encountered on a system, including application names; dialog-box text;labeled buttons; check-box and radio-button labels; menu titles and submenu titles. For example:

Choose System → Preferences → Mouse from the main menu bar to launch MousePreferences. In the Buttons tab, select the Left-handed mouse check box and clickClose to switch the primary mouse button from the left to the right (making the mousesuitable for use in the left hand).

To insert a special character into a gedit file, choose Applications → Accessories →

Preface

3

Page 7: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

Character Map from the main menu bar. Next, choose Search → Find… from theCharacter Map menu bar, type the name of the character in the Search field and clickNext. The character you sought will be highlighted in the Character Table. Double-clickthis highlighted character to place it in the Text to copy field and then click the Copybutton. Now switch back to your document and choose Edit → Paste from the gedit menubar.

The above text includes application names; system-wide menu names and items; application-specificmenu names; and buttons and text found within a GUI interface, all presented in proportional bold and alldistinguishable by context.

Mono-spaced Bold Italic or Proportional Bold Italic

Whether mono-spaced bold or proportional bold, the addition of italics indicates replaceable or variabletext. Italics denotes text you do not input literally or displayed text that changes depending oncircumstance. For example:

To connect to a remote machine using ssh, type ssh [email protected] at a shellprompt. If the remote machine is example.com and your username on that machine isjohn, type ssh [email protected] .

The mount -o remount file-system command remounts the named file system. Forexample, to remount the /home file system, the command is mount -o remount /home.

To see the version of a currently installed package, use the rpm -q package command. Itwill return a result as follows: package-version-release.

Note the words in bold italics above: username, domain.name, file-system, package, version and release.Each word is a placeholder, either for text you enter when issuing a command or for text displayed bythe system.

Aside from standard usage for presenting the title of a work, italics denotes the first use of a new andimportant term. For example:

Publican is a DocBook publishing system.

1.2. Pull-quote ConventionsTerminal output and source code listings are set off visually from the surrounding text.

Output sent to a terminal is set in mono-spaced roman and presented thus:

books Desktop documentation drafts mss photos stuff svnbooks_tests Desktop1 downloads images notes scripts svgs

Source-code listings are also set in mono-spaced roman but add syntax highlighting as follows:

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example

4

Page 8: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

package org.jboss.book.jca.ex1;

import javax.naming.InitialContext;

public class ExClient{ public static void main(String args[]) throws Exception { InitialContext iniCtx = new InitialContext(); Object ref = iniCtx.lookup("EchoBean"); EchoHome home = (EchoHome) ref; Echo echo = home.create();

System.out.println("Created Echo");

System.out.println("Echo.echo('Hello') = " + echo.echo("Hello")); }}

1.3. Notes and WarningsFinally, we use three visual styles to draw attention to information that might otherwise be overlooked.

Note

Notes are tips, shortcuts or alternative approaches to the task at hand. Ignoring a note shouldhave 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 thecurrent session, or services that need restarting before an update will apply. Ignoring a boxlabeled “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.

2. Getting Help and Giving Feedback

2.1. Do You Need Help?If you experience difficulty with a procedure described in this documentation, visit the Red Hat CustomerPortal at http://access.redhat.com. Through the customer portal, you can:

search or browse through a knowledgebase of technical support articles about Red Hat products.

submit a support case to Red Hat Global Support Services (GSS).

access other product documentation.

Preface

5

Page 9: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

Red Hat also hosts a large number of electronic mailing lists for discussion of Red Hat software andtechnology. You can find a list of publicly available mailing lists at https://www.redhat.com/mailman/listinfo.Click on the name of any mailing list to subscribe to that list or to access the list archives.

2.2. Give us FeedbackIf you find a typographical error, or know how this guide can be improved, we would love to hear fromyou. Submit a report in Bugzilla against the product JBoss Web Framework Kit and the component doc-Snowdrop_Sportsclub_Example. The following link will take you to a pre-filled bug report forthis product: http://bugzilla.redhat.com/.

Fill out the following template in Bugzilla's Description field. Be as specific as possible whendescribing the issue; this will help ensure that we can fix it quickly.

Document URL:

Section Number and Name:

Describe the issue:

Suggestions for improvement:

Additional information:

Be sure to give us your name so that you can receive full credit for reporting the issue.

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example

6

Page 10: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

Chapter 1. IntroductionThe Sportsclub application provides a real-world-inspired example of integrating Spring with the JBossEnterprise Platforms. It consists of three web applications, which illustrate several use cases throughvarious combinations of components and technologies. It also illustrates how to use the Snowdroplibraries to provide JBoss-specific features, such as creating a standalone deployment of an ApplicationContext and injecting beans from that application context into non-Spring componentslike Enterprise Java Beans (EJBs).

This book aims to illustrate the mechanics of using Spring with different Java EE 6 components in thespecific context of the JBoss Enterprise Platforms, and to recommend methods of achieving certainintegration goals.

The Sportsclub example is not intended as a guide to creating a domain model. Detailing the variouslayers of application and UI design is outside the scope of this document. As such, the exampleapplication has been designed to illustrate integration use cases, rather than to demonstrate a domainmodel that strictly follows principles of object-oriented and domain-driven design.

The Sportsclub example uses RichFaces as a component library for JavaServer Faces (JSF). Consultthe RichFaces documentation for RichFaces-specific information.

1.1. Sportsclub example variantsThe Sportsclub example is provided in several variants, with similar structures and functions. Thevariants differ due to the version of Spring being used, and the availability of certain modules, as follows:

The Spring 2.5 variant uses Spring Security 2.0.x and does not have a Spring Webflow module (seeSection 3.5.3, “Reservations-Webflow: Conversation-based reservations (Spring 3 and Spring 3.1variants only)” for details)

The Spring 3 and Spring 3.1 variants uses Spring Webflow 2.3.x and Spring Security 3.0.x (seeSection 3.5.3, “Reservations-Webflow: Conversation-based reservations (Spring 3 and Spring 3.1variants only)” for details).

1.2. Building the applicationThis step explains building the application. The Sportsclub example uses Maven, so it is built by running:

mvn clean package

This will produce two EAR files, both named sportsclub.ear, located under sportsclub-ear/target and sportsclub-jpa-ear/target. They have the same functionality, but theunderlying implementation of the persistence layer is different (one is using Hibernate, and another oneuses JPA).

Important

The built application has a profile, messaging, which builds a JMS-enabled variant of theapplication.

The messaging profile will be used for enabling and disabling JMS integration. When running inenvironments where messaging is not enabled, like the Web Profile of JBoss EAP, it can be disabled byrunning:

Chapter 1. Introduction

7

Page 11: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

mvn clean package -P!messaging or mvn clean package -P-messaging

1.3. Preparing your JBoss Enterprise PlatformThe JBoss Enterprise Platform needs to be set up to run your application. This step involves:

setting up the Spring deployer

creating a Destination for JMS-related features

creating a security domain

As explained in the prerequisites, the Spring deployer is set up by extracting the Snowdrop and Springmodules and copying them to the $JBOSS_HOME/modules directory and adding the Snowdropsubsystem to the target profile. Refer to the Spring deployer section of the Snowdrop User Guide fordetails.

For creating the required JMS destination, add the highlighted definition to the messaging subsystem, in $JBOSS_HOME/standalone/configuration/standalone.xml:

<subsystem xmlns="urn:jboss:domain:messaging:1.2"> ... <hornetq-server> ... <jms-destinations> ... <!-- Code to be added starts here --> <jms-queue name="sportsclub"> <entry name="queue/sportsclub"/> </jms-queue> <!-- Code to be added ends here --> </jms-destinations> </hornetq-server> </subsystem>

For creating the security domain, add the indicated highlighted definition to the security subsystem:

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example

8

Page 12: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

<subsystem xmlns="urn:jboss:domain:security:1.2"> <security-domains> ... <!-- Code to be added starts here --> <security-domain name="employees"> <authentication> <login-module code="Database" flag="required"> <module-option name="dsJndiName" value="java:jboss/datasources/ExampleDS"/> <module-option name="principalsQuery" value="select passwd from SPORTSCLUB_USERS where username=?"/> <module-option name="rolesQuery" value="select userRoles,'Roles' from SPORTSCLUB_ROLES where username=?"/> </login-module> </authentication> </security-domain> <!-- Code to be added ends here --> </security-domains> </subsystem>

1.4. Deploying the applicationCopy one of the two EARs produced by the build to the deploy folder of your JBoss Enterprise Platform: $JBOSS_HOME/standalone/deployments. The two alternative build files are:

sportsclub-ear/target/sportsclub.earHibernate-based implementation

sportsclub-jpa-ear/target/sportsclub.earJPA-based implementation, using Hibernate as the underlying provider

1.5. Sportsclub and JBoss Developer StudioSportsclub is a Maven-based project, so you can import it into JBoss Developer Studio.

1. Go to Import .... → Maven → Existing Maven Projects2. Select sportsclub and then the version of Spring to use.

Result

The top-level poms are shown as well as the module subpoms.

At this point, it is important to choose if you would like to include the messaging profile in the application.This needs to be done before the import process is complete, otherwise the selection will contain thedefault set of profiles (including messaging). You can change the profiles later from the contextual menuof the project (right-click Maven followed by a dependency update), but this will need to be done forevery project in your workspace.

There are slight differences between the context definitions that apply in various configurations (spring-3, spring-2), and some definitions may not be included (as is the case with the messaging profile). Thismeans that the poms of several modules include alternative locations for web resources, which areadded by Maven at build time.

Chapter 1. Introduction

9

Page 13: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

Web resources can be added to a project by opening its properties and selecting DeploymentAssembly → Add ... → Folder. The contents of the selected folder will be added automatically in thedocument root of the application.

Depending on the selected profiles, additional directories need to be added as shown in the followingtable:

Table 1.1. Addit ional resource folders per module and profile

Module Active profile Additional folder

sportsclub-invoicing-webmvcmessaging src/main/webapp-messaging

Note

Additional resources need to be added even if active profiles are not explicitly indicated. This isbecause the application will activate the messaging profile by default.

The application is ready to run.

1. On the Servers view, choose a JBoss EAP 6 server.

2. Add one of the two EAR projects:

sportsclub-ear

sportsclub-jpa-ear

3. Start the project.

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example

10

Page 14: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

Note

The access URLs for the Sportsclub Example deployed through JBoss Developer Studio aredifferent to the URLs when deployed via the command line.

InvoicingCommand Line

http://localhost:8080/sportsclub/invoicing

JBoss Developer Studiohttp://localhost:8080/sportsclub-invoicing-webmvc

SubscriptionsCommand Line

http://localhost:8080/sportsclub/subscriptions

JBoss Developer Studiohttp://localhost:8080/sportsclub-subscriptions-web

ReservationsCommand Line

http://localhost:8080/sportsclub/reservations

JBoss Developer Studiohttp://localhost:8080/sportsclub-reservations-webflow

Chapter 1. Introduction

11

Page 15: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

Chapter 2. Understanding the Application StructureThis chapter describes the business use cases covered by the application, and how the functionality isdistributed across the modules.

2.1. The Application Structure and its Use CasesThe Sportsclub example consists of three different applications sharing the same domain model,packaged, and deployed together. This is done for simplicity and to demonstrate different technologiesand configuration options working side by side.

The business domain of the application is a Sports Club. The employees of the club need to be able toperform the following scenarios:

maintaining information about subscribers, creating new subcriptions and closing existing accounts;

creating, modifying and removing equipment reservations for subscribers;

viewing the current balance of an account, issuing invoices for accounts that do not have a currentinvoice and updating the account whenever a payment has been received.

Each of these scenarios is covered by a separate web application, and all three applications arepackaged in a single EAR file.

All three applications share a common domain model and a common DAO/repository layer, implementedusing Spring. The application includes both Hibernate and JPA implementations for the repository layer(using the Hibernate and JPA support provided by JBoss Enterprise Application Platform, respectively).The application is built in two different variants, each using one of the two DAO implementationalternatives.

Apart from that, each web application uses a different combination of technologies, illustrating one ormore integration use cases.

The Subscriptions application uses an EJB-based service layer and a JSF-based front-end, usingRichfaces components.

The Invoicing application uses the following stack:

UI layer implemented using Spring MVC and JSP

Business layer implemented using EJB

Persistence layer implemented using Spring-based DAOs (Hibernate/JPA)

In all three cases, the persistence layer is implemented using Spring. In fact there are two alternativeimplementations: one using Hibernate directly and one using JPA (and Hibernate as the provider).Building the application creates two different EAR files, one using the JPA-based DAOs and one usingthe Hibernate-based DAOs.

2.2. A comparative look of the project modulesThe modules (Maven artifacts) of the project are outlined in the following table:

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example

12

Page 16: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

Table 2.1. Modules of the Sportsclub project

Maven Module Functionality Module Type

sportsclub-bom No functionality, centralizes thedependencies of the project.

pom

sportsclub-domain Domain classes and repositoryinterfaces.

jar

sportsclub-hibernate-dao Hibernate implementations forrepositories and Spring beandefinitions using them.

jar

sportsclub-jpa-dao JPA implementations forrepositories and Spring beandefinitions using them.

jar

sportsclub-invoicing-ejb Business logic for the Invoicingapplication

ejb

sportsclub-reservations-spring Business logic for theReservations application

jar

sportsclub-subscriptions-ejb Business logic for theSubscriptions application

ejb

sportsclub-invoicing-webmvc UI layer for the Invoicingapplication. Includes processingof JMS messages via Spring (forpayment notifications)

war

sportsclub-reservations-web UI layer for the Reservationsapplication.

war

sportsclub-reservations-webflow

UI layer for the Reservationsapplication, implemented usingSpring webflow (present inSpring 3 and Spring 3.1 variantsonly)

war

sportsclub-subscriptions-web UI layer for the Subscriptionsapplication

war

sportsclub-ear EAR aggregator module usingthe Hibernate-basedimplementation

ear

sportsclub-jpa-ear EAR aggregator module usingthe JPA-based implementation

ear

sportsclub-staticwebcontent Static web content for theapplication (not deployedseparately, but included at build-time in the web layers)

war

sportsclub-test-infrastructure Infrastructure module for unittesting

jar

Chapter 2. Understanding the Application Structure

13

Page 17: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

Chapter 3. Using JBoss and Spring togetherThis chapter describes the various Spring and JBoss integration use cases covered by the applicationand how they are implemented in the various application modules.

As a Spring application that consists of multiple modules, the main strategy of constructing the globalSpring configuration is to provide Spring bean definition fragments in each artifact produced by a module,leaving the upper layer components to aggregate them by importing. This strategy allows the separationof concerns between components; the Spring wiring of certain components is left at the level where thecomponents are defined, so that it can be changed easily if the implementations change.

3.1. JBoss/Spring integration use casesThe Sportsclub application covers a number of JBoss and Spring integration use cases. The scenariosselected for this example are focused on using the Java EE 6 services provided by JBoss EnterprisePlatforms in Spring applications.

The use cases are grouped in categories as follows:

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example

14

Page 18: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

Table 3.1. Use case list overview

Category Use case How does this involve JBossEnterprise Platforms

Persistence Spring/Hibernate integration The application uses a Spring-configured HibernateSessionFactory, using JTAtransaction management andJTA-bound sessions. TheHibernate library is the oneprovided by JBoss EnterprisePlatforms.

Spring/JPA integration The Persistence Unit isdeployed by JBoss EnterprisePlatform and retrieved from JNDIto be injected into Spring beans.PersistenceContext is sharedwith surrounding EJBs (if any)

Testing Unit-testing components thathave managed infrastructuredependencies

The DataSource andEntityManager are managed byJBoss and acquired from JNDIby Spring when the applicationis running. In the case of JBossEnterprise Platforms,developers can test their codein isolation using Spring-specificreplacements that 'simulate' theJBoss Enterprise Platformenvironment.

Business Logic Spring-based service beans The business services areSpring-managed and wrappedinto transactions managed bySpring's interceptors. TheTransactionManager in use isthe JTATransactionManagerusing JBoss Transactionsprovided in JBoss EnterprisePlatforms.

EJBs injected with Spring Beans The application uses JBoss-deployed EJBs which areinjected with Spring beansacquired from an applicationcontext bootstrapped by theSpring Deployer. Transactionsare managed by EJBs.

User Interface JSF/RichFaces and Springintegration

The application uses the JBossEnterprise Platforms-providedJSF support, and RichFacescomponents. The businessservices and UI-backinginstances are Spring beans.

Spring MVC and EJB integration The application uses Spring

Chapter 3. Using JBoss and Spring together

15

Page 19: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

MVC and the business logic isimplemented using JBoss-deployed EJBs, which areinjected into the Springcontrollers.

Conversation-oriented webapplication

The application uses SpringWeb Flow for defining aconversational process forcreating a reservation

JMS/JCA integration JMS/Spring integration usingJCA

Spring-configured messagelisteners are used forprocessing JMS messages fromJBoss Enterprise Platforms-managed destinations. Theapplication uses the Spring /JCAintegration for receivingmessages.

Aspect-oriented programming Spring-based weaving of POJOaspects

This use case does not haveany JBoss Enterprise Platforms-specific functionality.

JMX Spring beans are exposed asJMX beans

The JBoss Enterprise PlatformsMBean Server is used forregistering the Spring-exportedJMX beans. Consequently, theSpring beans can be managedfrom a management console.

Web Services JAX-WS defined web-servicesare injected with Spring beans

The application uses JBossEnterprise Platforms' support forJAX-WS through JBoss WS, butalso Spring to define theunderlying business logic, whichis injected into the JBoss WS-deployed services.

A Spring Web Services-basedvariant of the JAX-WS example

The application implements aweb service based on SpringWeb Services.

Security Application-server pre-authentication

The application uses SpringSecurity for authorizing accessto resources. Authentication isprovided by the applicationserver.

3.2. The domain modelThe Sportsclub-domain module is the only module of the application that does not integrate with Springdirectly. However, it is used further in the application as it provides:

the entities that the application will interact with;

the repository interfaces that provide persistence services for the application;

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example

16

Page 20: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

Note

The term 'repository' is used for the components that retrieve objects from persistence and savethem. This is done to indicate that the design of the application is emulating the concepts behindDomain-Driven Design, where objects that are used for providing the persistence and entitylookup functions are part of the domain, rather than simple persistence implementation strategies.

Figure 3.1. Domain entit ies of the application and their connections

Figure 3.1, “Domain entities of the application and their connections” shows the domain entities of theapplication. Figure 3.2, “The Account and Person entities” shows a more detailed overview of the entitiesinvolved in the Account/Person relationship, including the non-entity domain objects.

Chapter 3. Using JBoss and Spring together

17

Page 21: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

Figure 3.2. The Account and Person entit ies

3.3. Persistence implementation: JPA and HibernateThe persistence modules: sportsclub-hibernate-dao and sportsclub-jpa-dao are alternativeimplementations of the application's persistence strategy. This means that each module will provide:

implementations for the repository interfaces defined in the Sportsclub-domain module;

Spring context definition fragments that can be reused elsewhere in the application

Effectively, the Spring configuration fragments will expose a bean implementation for each repositoryinterface defined in the model. This means that the implementations can be swapped at build-timewithout any change in the business layer. This is the basis for the build process creating two differentbuilds, each based on a different persistence implementation - including a different repositoryimplementation jar and leaving everything else in the component stack unchanged.

Each module produces a set of beans that can be injected further into the business services of theapplication.

3.3.1. The Hibernate implementationThe Hibernate-based repository implementation defines a generic superclass defining all the commonrepository operations that the repository implementations will parametrize by specifying the entity typeand primary key type.

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example

18

Page 22: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

public abstract class HibernateRepository<T, I extends Serializable> implements Repository<T, I>{ protected SessionFactory sessionFactory;

Class<T> clazz;

public HibernateRepository(Class<T> clazz) { this.clazz = clazz; }

public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; }

protected Session getCurrentSession() { return this.sessionFactory.getCurrentSession(); } public T findById(I id) { return (T)getCurrentSession().get(clazz, id); }

public T save(T object) { return (T) getCurrentSession().merge(object); }

public void delete(T object) { getCurrentSession().delete(object); }

public List<T> findAll() { return getCurrentSession().createCriteria(clazz).list(); }

public long countAll() { return (Integer)getCurrentSession().createCriteria(clazz).setProjection(Projections.count("id")).uniqueResult(); }

public Criteria applyRange(Criteria criteria, Range range) { return criteria.setFirstResult(range.getMinIndex()).setMaxResults(range.length()); }}

It is important to notice that this implementation and its subclasses are not Spring-based. The onlySpring-related component of this module is the configuration which consists of the following files:

Chapter 3. Using JBoss and Spring together

19

Page 23: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

sportsclub-hibernate-dao/src/main/resources/dao-context.xml

Contains:

the Spring bean definitions for the repository implementations

the Spring-based SessionFactory definition (a LocalSessionFactoryBean), and;

the wiring of session factories into Spring beans.

sportsclub-hibernate-dao/src/main/resources/infrastructure.xml

Contains:

the definitions for infrastructure-related Spring beans, namely the data source to be used forthe Hibernate SessionFactory, and;

the transaction manager.

Separating the infrastructure context definition file from the rest of the bean definitions allows swapbetween the infrastructure definition for unit testing. For example, the Hibernate SessionFactory isconfigured to use JTA transactions, and allows the Session to be shared with a layer of EJBs thatdelegate to it.

3.3.2. The JPA implementationThe JPA implementation is similar to the Hibernate implementation. It provides a parametrizedsuperclass that is Spring-agnostic as well (except for the usage of the autowiring annotation, which canbe replaced by a simple setter if any reference to Spring needs to be removed). Besides the fact that it isusing the JPA API - for example, an EntityManager instead of the SessionFactory - the JPA PersistenceUnit (and subsequent EntityManager) are created by the application server and not by Spring (theEntityManager is injected by Spring, but acquired from JNDI). The persistence unit is deployed fromwithin the JPA repository jar, in order to allow the spring-domain jar to be deployed in non-JPA scenarios(for example, Hibernate) without triggering a persistence unit deployment.

The Spring application context configuration fragments are very similar to the ones encountered in theHibernate module:

sportsclub-jpa-dao/src/main/resources/dao-context.xml

Contains the Spring bean definitions for the repository implementations, assuming an EntityManager bean is defined in the global application context definition.

sportsclub-jpa-dao/src/main/resources/infrastructure.xml

Contains the definitions for infrastructure-related Spring beans, namely the entityManger beanto be wired into JpaRepository class and the transaction manager.

3.3.3. Unit testing the repositoriesGiven that the infrastructure is tied tightly to the Application Platform, the repositories should be tested inisolation before integrating them with the rest of the application. If the services that the JBoss ApplicationPlatform provides will be used at deployment time, use an embedded database, Spring's ability to createLocalSessionFactories, LocalEntityManagerFactories, and its local transaction management abilities.

To do this, use the sportsclub-test-infrastructure module, which is a test-scoped dependency. This

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example

20

Page 24: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

module contains the modules used for setting up an embedded database. This is done by producing aDataSource that can be injected into the LocalSessionFactoryBean, andLocalContainerEntityManagerFactoryBean respectively. The localized SessionFactory andEntityManager defintions are located in the sportsclub-hibernate-dao, and sportsclub-jpa-dao modules,respectively.

The unit tests that are located in the respective modules use the local infrastructure files and the dao-context.xml files, as in the following example:

@ContextConfiguration(locations = {"classpath:test-db-infrastructure.xml", "classpath:TEST-jpa-infrastructure.xml", "classpath:dao-context.xml"})@RunWith(SpringJUnit4ClassRunner.class)public class TestJpaAccountRepository{ /* */}

This configuration reuses the 'application-specific' context configuration fragment, as well as two test-specific (or local) context configuration fragments in order to create a Spring context in isolation. Thisway, the functionality provided by the repositories can be tested outside the running application.

3.4. Service LayerOn top of the domain and persistence layer sits the service layer of the application. Its role is tocoordinate the domain objects and repositories in order to perform higher level operations. This is alsothe layer which provides transaction demarcation. One consideration for which transaction demarcationshould be done at service level is to ensure that the changes made by service operations are atomic.Otherwise, concurrent operations may leave the application data in an inconsistent state. Demarcatingtransactions at the repository/DAO level should be done carefully, taking into consideration that multiplerepository/DAO invocations that are not surrounded by a wrapping transactions will execute in separatetransactional contexts.

In the Sportsclub application, there are two variants of implementing the service layer:

using Spring (Reservations, parts of Invoicing)

using EJB (Subscriptions, Invoicing)

Note

It is possible to define transactions at the repository level, avoiding another indirection to thepersistence layer for simple persistence operations (finding an object, persisting an object).

3.4.1. The Spring-based service layerThe Spring-based service layer exposes a number of service beans that can be consumed by the UI,which are injected with the beans defined in the persistence layer. This is the level where transactiondemarcation is provided by the use of the appropriate Spring annotations.

3.4.2. The EJB service layerA common scenario in Spring/EJB integration is the wrapping of Spring Beans in EJBs. This is often

Chapter 3. Using JBoss and Spring together

21

Page 25: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

done in order to get advantage of the services provided by the EJB container (security, declarativetransaction management), while keeping some of the objects they collaborate with as simple POJOs. Inthis scenario, the EJBs form the outermost layer of the business logic, the one that is exposed to therest of the application (UI). In this scenario, the EJB services are injected with the Spring-basedrepositories.

JBoss has its own native support for Spring/EJB integration, in the form of the Spring Deployer andspecial annotations for injection of Spring beans into EJBs.

3.4 .2.1. The Spring DeployerThe Spring Deployer is a JBoss-specific deployer that can be used to bootstrap a SpringApplicationContext and register it into JNDI. The configuration files for bootstrapping the applicationcontext are defined at the EAR level, and the Spring ApplicationContext is shared to all the components.The definition file is simple, and just imports the contexts defined in the JPA jars.

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<description>BeanFactory=(SpringDao)</description>

<import resource="classpath*:dao-context.xml"/> <import resource="classpath*:infrastructure.xml"/>

</beans>

3.4 .2.2. Injection into EJBsOnce the ApplicationContext is created, the beans defined there can be injected into EJBs. So, in thiscase, the Spring repositories will be injected into EJBs as follows:

@Stateless@Interceptors(SpringLifecycleInterceptor.class)public class BillingServiceImpl implements BillingService{ @Spring(bean = "invoiceRepository", jndiName = "SpringDao") private InvoiceRepository invoiceRepository;

/* rest of the class definition ommitted */}

The injection task is undertaken by the SpringLifecycleInterceptor. Once it encounters a field or setterannotated with @Spring, it will look for the JNDI-bound application context and inject the correspondingSpring bean.

3.5. Presentation LayerThe three web applications which compose the Sportsclub package illustrate different ways ofintegrating Spring and Java EE technologies in the presentation layer:

JSF/EJB with an underlying Spring layer (Subscriptions)

JSF/Spring (Reservations)

Spring MVC/EJB (Invoicing)

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example

22

Page 26: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

3.5.1. Subscriptions: JSF and SpringThe Subscriptions application uses RichFaces and JSF for the presentation layer and EJB for thebusiness layer, so this part of the application is not Spring-related.

3.5.2. Reservations: JSF/Spring integrationThe Reservations application is an example of using Spring in an application that uses RichFaces andJSF. Here, Spring beans are used as business services for the application, as well as backing beans forthe JSF pages. In the latter case, Spring beans replace the managed beans and other web artifactsused by JSF.

The Spring application context is bootstrapped by the ContextLoaderListener defined in /WEB-INF/web.xml. The Spring configuration file in use is /WEB-INF/spring-beans.xml, which:

imports the context definition fragments included in the other JARs of the application (that is, theJARs that contain the business logic)

defines a number of Spring beans that are used directly in the web tier by the JSF pages or by theRichFaces components;

The Spring configuration file imports the Spring business beans and infrastructure definitions as follows:

<import resource="classpath*:reservations-service.xml"/>

<import resource="classpath*:infrastructure.xml"/>

The following bean is used for backing JSF pages. Please note that Spring beans defined in the weblayer may use scopes, and a significant number of the Spring beans used in Reservations applicationare session-scoped (like the one in the following example). Spring provides a request scope as well, butit is not used in this example.

<bean id="reservationCreate" class="org.jboss.snowdrop.samples.sportsclub.jsf.beans.ReservationCreate" scope="session" init-method="init"> <property name="reservationService" ref="reservationService"/> <property name="accountService" ref="accountService"/> <property name="accountFilter" ref="accountFilterCreate"/> <property name="equipmentFilter" ref="equipmentFilterCreate"/> <property name="reservationSearch" ref="reservationSearch"/></bean>

In order to make the Spring beans visible to JSF pages, a special VariableResolver has to be defined in /WEB-INF/faces-config.xml.

<application> <!-- other definitions --> <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver></application>

The Spring bean defined above can be used directly in a JSF page, as in the following excerpt from createReservation.xhtml:

Chapter 3. Using JBoss and Spring together

23

Page 27: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

<rich:panel> <f:facet name="header">Select Account</f:facet> <h:form id="AccountSelectForm"> <rich:extendedDataTable id="accountsTable" value="#{accountFilterCreate}" var="account" selectionMode="single" selection="#{accountFilterCreate.selection}" enableContextMenu="true" height="250px" rows="5"> <a4j:ajax event="selectionchange" listener="#{reservationCreate.updateSelectedAccount}" render="reservationDetails" />

<rich:column label="Id" width="7%"> <f:facet name="header"> <h:outputText value="Id" /> </f:facet> <h:outputText value="#{account.id}" /> </rich:column>

<rich:column label="First Name"> <f:facet name="header"> <h:outputText value="First Name" /> </f:facet> <h:outputText value="#{account.subscriber.name.firstName}" /> </rich:column>

<rich:column label="Last Name"> <f:facet name="header"> <h:outputText value="Last Name" /> </f:facet> <h:outputText value="#{account.subscriber.name.lastName}" /> </rich:column>

<rich:column label="City"> <f:facet name="header"> <h:outputText value="City" /> </f:facet> <h:outputText value="#{account.subscriber.address.city}" /> </rich:column>

<rich:column label="Country"> <f:facet name="header"> <h:outputText value="Country" /> </f:facet> <h:outputText value="#{account.subscriber.address.country}" /> </rich:column>

<f:facet name="footer"> <rich:dataScroller id="scrollerAccount" for="accountsTable" maxPages="5" page="#{accountFilterCreate.currentPage}" /> </f:facet> </rich:extendedDataTable> </h:form></rich:panel>

All the EL variables that are used in the previous example, including the ones referenced in theRichFaces elements are Spring beans. They can be used either as backing beans for retrieving andsetting values, as well as for invoking methods corresponding to JSF events.

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example

24

Page 28: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

3.5.3. Reservations-Webflow: Conversation-based reservations (Spring 3 andSpring 3.1 variants only)The Spring 3 and Spring 3.1 versions of the Sportsclub package include an alternate version of thereservations application, which uses Spring Webflow. As with the previous example, the main viewtechnology is JSF2, using Richfaces as a component library, and Spring, which is used for managing thebacking beans for JSF pages and business services.

JSF2 and Spring Webflow

JSF2 is supported only in Spring Webflow version 2.1 and higher, all of which require Spring 3.Because the example demonstrates the usage of JSF2, the Spring 2.5 variant of the exampledoes not contain a Spring Webflow module.

However, unlike the previous example where the interaction is form-based, this application uses aconversation-based model for driving the user interaction. A reservation is created in a sequence ofsteps that represents a conversation - a distinct scope which spans multiple requests, but less broadthan a session. The input data (selected account, selected equipment and date) are preserved for theduration of the conversation, and discarded automatically after the conversation has ended. TheSportsclub application uses Spring Webflow for implementing conversation-based multi-step dialogues.

The Spring business application context is bootstrapped by the ContextLoaderListener defined in /WEB-INF/web.xml. The Spring configuration file in use is /WEB-INF/spring-beans.xml, which:

imports the context definition fragments included in the other JARs of the application (that is, theJARs that contain the business logic)

defines a number of Spring beans that are used directly in the web tier by the JSF pages or by theRichfaces components;

For the UI and Spring Webflow integration, the application defines a DispatcherServlet in web.xml, in asimilar way to Spring MVC applications.

Chapter 3. Using JBoss and Spring together

25

Page 29: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices"> <webflow:flow-location path="/WEB-INF/flows/reservation/reservation-flow.xml" id="reservation"/></webflow:flow-registry>

<webflow:flow-executor flow-registry="flowRegistry" id="flowExecutor"> <webflow:flow-execution-listeners> <webflow:listener ref="facesWebFlowListener"/> </webflow:flow-execution-listeners></webflow:flow-executor>

<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter"> <property name="flowExecutor" ref="flowExecutor"/> <property name="ajaxHandler"> <bean class="org.springframework.faces.webflow.JsfAjaxHandler"/> </property></bean>

<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping"> <property name="flowRegistry" ref="flowRegistry"/> <property name="order" value="1"/></bean>

<faces:resources/>

<faces:flow-builder-services id="flowBuilderServices" development="true"/>

<bean id="facesWebFlowListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener"/>

The definitions above include:

a flow registry containing the flow definitions;

a flow executor which is the Spring Webflow engine;

a pair of FlowHandlerAdapter and FlowHandlerMapping beans which ensure that any requests thatare handled by the DispatcherServlet declared in web.xml are delegated to the Spring Webflowexecutor;

the flowBuilderServices and facesWebFlowListener beans are used for integrating Spring Webflowwith JSF. In other words, for using JSF views for rendering the view states.

The application is using a flow definition for creating a reservation, described in /WEB-INF/flows/reservation/reservation-flow.xml. The JSF pages used for rendering the flowviews are located in the same /WEB-INF/flows/reservation/ directory.

3.5.4. Invoicing: Spring MVC and EJBThe Invoicing application provides another example of interoperability between Spring and the Java EEservices provided by JBoss. If in the previous example, the business tier was implemented using Springand the web tier was using JSF, in this example the roles are reversed; the business tier is using EJBand the web tier is using Spring.

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example

26

Page 30: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

The Spring MVC beans are defined in the /WEB-INF/springmvc-servlet-context.xml file,referenced by the Spring MVC DispatcherServlet definition that is described WEB-INF/web.xml. Forthis implementation, the annotation-based configuration has been used, and the AccountController classthat implements the controller part of the configuration is injected with previously defined EJBs:

Chapter 3. Using JBoss and Spring together

27

Page 31: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

@Controllerpublic class AccountController{

@EJB(mappedName = "java:app/sportsclub-invoicing-ejb/BillingServiceImpl") BillingService billingService;

@EJB(mappedName = "java:app/sportsclub-subscriptions-ejb/SubscriptionServiceImpl") SubscriptionService subscriptionService;

/* some code ommitted */

@RequestMapping(value = "/accountDetail.do", method = RequestMethod.GET) ModelMap getAccountDetail(@RequestParam("id") String id) { Account account = subscriptionService.findAccountById(Long.parseLong(id));

List<Invoice> invoices = billingService.getInvoices(account);

boolean hasCurrentInvoice = false; Date currentDate = new Date();

for (Invoice invoice: invoices) { if (invoice.getBillingPeriod().contains(currentDate)) { hasCurrentInvoice = true; break; } }

List<Payment> payments = billingService.getPayments(account);

ModelMap model = new ModelMap(); model.addAttribute(account); model.addAttribute("invoices", invoices); model.addAttribute("payments", payments); model.addAttribute("hasCurrentInvoice",hasCurrentInvoice); return model; }

@RequestMapping(value = "/generateInvoice.do", method = RequestMethod.POST) ModelMap generateInvoice(@RequestParam("id") String id) { Account account = subscriptionService.findAccountById(Long.parseLong(id)); Invoice invoice = billingService.generateInvoice(account);

ModelMap model = new ModelMap(); model.addAttribute("id",id); model.addAttribute(invoice); return model; }

}

The @Controller annotation is detected by Spring, as it scans the classpath which is prompted byincluding the following line into /WEB-INF/springmvc-servlet-context.xml.

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example

28

Page 32: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

<context:component-scan base-package="org.jboss.snowdrop.samples.sportsclub.springmvc"/>

As a Spring-managed object, the bean is injected with the EJBs BillingService and SubscriptionService,as required by annotating the respective fields with the @EJB annotation.

The @RequestMapping-annotated methods are executed when the user is accessing the specified URLand HTTP method. The request parameters will be bound to method arguments. In the example above,invoking the URL http://localhost:8080/sportsclub/invoicing/accountDetail.do?id=1 will cause theinvocation accountController.getAccountDetail(1). The method will invoke the appropriate businessservices (in this case, exposed as EJBs) and will return a map of business object collections, indexed bytheir names. Spring MVC will take care of setting them on the request, so that they can be used forrendering the response.

By default, Spring MVC will try to find a view that has the name 'accountDetail', and will use the JSP file atWEB-INF/jsp/accountDetail.jsp, based on the view resolver definition from /WEB-INF/springmvc-servlet-context.xml. This JSP uses the Spring tag libraries for form processing, so that thecollections previously returned will be accessible using JSTL expressions, and the following declarationwill be found:

<form:form action="generateInvoice.do"> This account does not have an invoice for the current billing period.<p/> You can create one now: <input type="hidden" name="id" value="<c:out value="${account.id}"/>"> <input type="submit" value="Create invoice"/><br/> </form:form>

Clicking the Create Invoice button will result in a POST submission tohttp://localhost:8080/sportsclub/invoicing/generateInvoice.do?id=1 and the subsequent invocation of thegenerateInvoice method.

In order to be able to demonstrate a few Spring/JBoss integration features, the Invoicing application alsocontains a number of business services that are using Spring. They do not play any role in the SpringMVC/EJB integration.

3.5.5. A problem of reusing contentHaving three different web applications to be included in the same package raises the problem ofreusing some content. Most of the static content used by the Sportsclub application is defined in aseparate web module, Sportsclub-staticwebcontent, which is then included by Maven at build time asfollows:

<dependency> <groupId>org.jboss.snowdrop.samples.sportsclub</groupId> <artifactId>sportsclub-staticwebcontent</artifactId> <version>${project.version}</version> <type>war</type> <scope>runtime</scope></dependency>

Chapter 3. Using JBoss and Spring together

29

Page 33: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

Note

The groupID is dependent on which Spring variant is used. The corresponding groupIDs are:

org.jboss.snowdrop.samples.sportsclub.spring-2org.jboss.snowdrop.samples.sportsclub.spring-3org.jboss.snowdrop.samples.sportsclub.spring-3_1

Note

When working in an IDE that does not know how to apply Maven overlays correctly, the staticcontent may not be available when building and deploying the application. This does not affect thegeneral functionality of the application, but the look and feels may be affected.

3.6. Enterprise Integration FeaturesApart from the Spring/JSF/EJB integration, the Sportsclub application suite provides a few otherexamples of integrating Spring and JBoss. Since all the features are Spring-based, they have beenincluded as business services of the Invoicing web application. All the definitions for the followingexamples can be found in the /WEB-INF/spring-business-context.xml file, defined in the spring-invoicing-webmvc module.

3.6.1. Payment processing: JMS integration through JCAJMS integration can be enabled or disabled in the application, in order to allow it to run in environmentsthat do not have a message broker. Take, for example, the Web Profile of JBoss Enterprise ApplicationServer. For details on how to do that, please consult section Section 1.2, “Building the application” of thecurrent guide.

Besides displaying the current status of invoices and payments for a given account and generatinginvoices through the web interface, the Sportsclub application can also process payments for variousaccounts. The assumption of this scenario is that the system can receive payment notificationsasynchronously, through a JMS queue. When a payment has been received, it can be processed by amessage-driven component, which in this case is a Spring bean. In order to take full advantage of themanaged environment provided by the application server, the Spring bean will be invoked in a JCAcontext.

The component that processes JMS messages is a POJO:

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example

30

Page 34: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

@Componentpublic class PaymentNotificationProcessor{ private static final Log LOG = LogFactory.getLog(PaymentNotificationProcessor.class);

@Autowired private PaymentProcessor paymentProcessor;

public void processPaymentNotification(PaymentNotification paymentNotification) { LOG.info(paymentNotification + " received"); paymentProcessor.processPayment(paymentNotification.getAccountNumber(), paymentNotification.getAmount()); LOG.info(paymentNotification + " processed"); }

}

It delegates the actual processing of a PaymentNotification to a different component, thePaymentProcessor, which is injected in the PaymentNotificationProcessor. This is done in order tomaintain a degree of separation between the way data may be represented when exchanged over themessaging system (that is, encapsulated in a PaymentNotification object), and the contract of theinternal component which actually does the processing. The PaymentProcessor instance injected intothe PaymentNotificationProcessor is reused by the PaymentNotificationService web serviceimplementation (whose contract does not depend on the PaymentNotification entity).

The arrival of messages and their processing can be traced by examining the application log.

Spring will instantiate a bean named "paymentNotificationProcessor" which will be registered as aprocessor for JMS message as follows:

<jms:jca-listener-container resource-adapter="resourceAdapter" acknowledge="auto" activation-spec-factory="activationSpecFactory"> <jms:listener destination="/queue/sportsclub" ref="paymentNotificationProcessor" method="processPaymentNotification"/></jms:jca-listener-container>

This type of configuration uses the JCA infrastructure to deliver messages to the listener, as opposed tothe DefaultMessageListenerContainer which is effectively polling the destination for incoming messages.Using JCA will ensure better performance, as well as the ability to integrate with the JTA transactionmanager out of the box.

In order to be able to test this feature, messages have to be sent to the message queue. This can bedone by using a special MBean defined by the application, accessible from a management console. Thename of the bean is "sportsclub:name=paymentNotificationTrigger" and has an operation called'sendPaymentNotification' with two arguments:

a long value, which is the accountId for making the payment;

a double value, which represents the amount to be paid;

Once the JMX operation is invoked, a message is sent to the queue and a confirmation message will bedisplayed in the JBoss log.

3.6.2. Aspects and auditingPayments must be audited. Besides keeping a record of payments associated with an account, it is

Chapter 3. Using JBoss and Spring together

31

Page 35: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

possible to set up an auditing service that will audit every attempt of making a payment. In the simplestcase that information can just be logged, although in a real life scenario things may be moresophisticated. In order to do so, set up a PaymentAuditor aspect that intercepts every call made to thePaymentProcessor.

The aspect is a simple POJO:

public class PaymentAuditor{ /* code ommitted */

public void auditPayment(Long accountId, BigDecimal amount) { System.out.println("AUDIT ENABLED! A payment has been made to account " + accountId + " for the amount of " + amount); }}

The aspect is applied through the following definitions:

<aop:config> <aop:aspect ref="paymentAuditor"> <aop:pointcut id="processingPayment" expression="execution(* *..PaymentProcessor+.*(..)) &amp;&amp; args(accountId, amount)"/> <aop:before arg-names="accountId, amount" pointcut-ref="processingPayment" method="auditPayment"/> </aop:aspect></aop:config>

<bean id="paymentAuditor" class="org.jboss.snowdrop.samples.sportsclub.audit.PaymentAuditor"/>

The aspect is defined as a bean and applied as an aspect through the Spring aop namespace. Thepointcut definition is an AspectJ expression.

3.6.3. Configuring Spring beans through JMXJMX is an important tool for monitoring and configuring Java applications. Collecting information aboutthe system and the ability of making configuration at runtime are important administration features. Forthis example, the requirement is to be able to turn auditing on and off, at runtime, whenever required.Removing an aspect once it has been applied by Spring is not possible, so the solution in this case is todefine a flag property on the aspect, which controls whether the auditing functionality will be invoked ornot.

In order to be able to make changes at runtime, the Spring bean which implements the aspect will beconfigured as a JMX bean and registered in the MBean server of JBoss. In this example, annotations areused to define Spring-specific JMX metadata. The complete definition for the PaymentAuditor is:

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example

32

Page 36: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

@ManagedResource(objectName = "sportsclub:name=paymentAuditor", description = "Payment Auditor")@Componentpublic class PaymentAuditor{

private static final Log LOG = LogFactory.getLog(PaymentAuditor.class);

private boolean enabled = true;

@ManagedAttribute(description = "Audit enabled") public void setEnabled(boolean enabled) { LOG.info("Audit " + (enabled ? "enabled":"disabled")); this.enabled = enabled; }

@ManagedAttribute(description = "Audit enabled") public boolean getEnabled() { return this.enabled; }

public void auditPayment(Long accountId, BigDecimal amount) { if (this.enabled) { LOG.info("A payment has been made to account " + accountId + " for the amount of " + amount); } }}

The annotations ManagedResource and ManagedAttribute are used to indicate what classes andproperties are JMX-managed. In order to expose the bean through JMX, it must be exported usingSpring's MBean Exporter.

<bean id="attributeSource" class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource"/>

<bean class="org.springframework.jmx.export.MBeanExporter"> <property name="autodetectModeName" value="AUTODETECT_ASSEMBLER"/> <property name="ensureUniqueRuntimeObjectNames" value="true"/> <property name="namingStrategy"> <bean class="org.springframework.jmx.export.naming.MetadataNamingStrategy"> <property name="attributeSource" ref="attributeSource"/> </bean> </property> <property name="assembler"> <bean class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler"> <property name="attributeSource" ref="attributeSource"/> </bean> </property> <property name="server" ref="mbeanServer"/> </bean>

As a result, this functionality can be turned on and off directly from the JBoss Enterprise Platforms JMX

Chapter 3. Using JBoss and Spring together

33

Page 37: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

As a result, this functionality can be turned on and off directly from the JBoss Enterprise Platforms JMXadministration console, using the "sportsclub:name=paymentAuditor" bean to interact with the paymentauditor.

As explained in the JMS section, a separate MBean is set up for setting messages to the paymentnotifications message queue.

3.6.4. Payment processing: exposing a JAX-WS web serviceAnother way of interacting with external applications, is by exposing a web service. In this scenario,payment notifications may not arrive only as asynchronous events on a message queue, but also assynchronous web service invocations. For this purpose, the application will expose a Spring bean withJAX-WS annotations as a web service.

To that end, a JAX-WS annotated class is provided by the application:

@WebServicepublic class PaymentNotificationService extends SpringBeanAutowiringSupport{

@Autowired private PaymentProcessor paymentProcessor;

@WebMethod public Long notifyPayment(@WebParam(name="accountNumber") Long accountNumber, @WebParam(name="amount") BigDecimal amount) { return paymentProcessor.processPayment(accountNumber, amount); }

}

By extending SpringBeanAutowiringSupport, the class PaymentNotificationService will be injectedautomatically with the same PaymentProcessor instance that is used by the JMS notification processor,and defined in the application context created from WEB-INF/spring-business-context.xml. Thisis necessary, because no bean of the type PaymentNotificationService is defined in the applicationcontext. Instead, the web service is defined and mapped as a servlet in /WEB-INF/web.xml:

<servlet> <servlet-name>PaymentNotificationService</servlet-name> <servlet-class>org.jboss.snowdrop.samples.sportsclub.ws.PaymentNotificationService</servlet-class> </servlet>

<servlet-mapping> <servlet-name>PaymentNotificationService</servlet-name> <url-pattern>/ws/payment</url-pattern> </servlet-mapping>

As a result, the JAX-WS web service can be accessed athttp://localhost:8080/sportsclub/invoicing/ws/payment. The service can be tested using a free SOAPtesting tool such as SOAP UI.

3.6.5. Implementing a Spring Web Services web serviceSpring Web Services is focused on implementing contract-first web services, as opposed to thecontract-last approach taken in the JAX-WS example (although it should be noted that JAX-WS can

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example

34

Page 38: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

support contract-first web services too). In the contract-first development style, the WSDL andrequest/reply document schemas are produced first, and define the contract between the service clientand implementor. It is the responsibility of the service supplier to handle the request and replydocuments appropriately.

The structure of the Spring-WS based web service is similar to a Spring MVC application. The entrypoint is a distinct type of dispatcher servlet, backed by an application context definition, as follows(Spring 3-based applications may omit the VFS-ready application context declaration):

<servlet> <servlet-name>spring-ws-servlet</servlet-name> <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class> <init-param> <param-name>contextClass</param-name> <param-value>org.jboss.spring.vfs.context.VFSXmlWebApplicationContext</param-value> </init-param> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-ws-config.xml</param-value> </init-param></servlet>

<servlet-mapping> <servlet-name>spring-ws-servlet</servlet-name> <url-pattern>/spring-ws/payment</url-pattern></servlet-mapping>

The actual endpoint that handles the SOAP requests is defined as follows:

@Endpointpublic class PaymentNotificationHandler{ @Autowired private PaymentProcessor paymentProcessor;

@PayloadRoot(localPart = "notifyPayment", namespace = "http://ws.sportsclub.samples.snowdrop.jboss.org/") public PaymentResponse notifyPayment(PaymentRequest paymentNotification) { Long paymentId = paymentProcessor.processPayment(paymentNotification.getAccountNumber(), paymentNotification.getAmount()); return new PaymentResponse(paymentId); }

}

The @Endpoint annotation indicates that this class contains web service endpoint methods and allowsfor this component to be detected as a Spring bean through classpath scanning. The @PayloadRootanotation indicates that any SOAP request submitted to the dispatcher servlet will be routed to thenotifyPayment method if the root element of the payload is {http://ws.sportsclub.samples.snowdrop.jboss.org/}notifyPayment. The requestpayload will be automatically unmarshalled in a PaymentRequest object sent as argument to the method.The return value is a PaymentResponse object which will be automatically marshalled as XML content

Chapter 3. Using JBoss and Spring together

35

Page 39: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

and will become the payload of the SOAP response that gets sent back. The Spring Web Servicesconfiguration indicates that a JAXB marshaller should be used specifically in this case.

<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> <property name="classesToBeBound"> <list> <value>org.jboss.snowdrop.samples.sportsclub.ws.PaymentRequest</value> <value>org.jboss.snowdrop.samples.sportsclub.ws.PaymentResponse</value> </list> </property> </bean>

The detailed application context definition can be found in the src/webapp/WEB-INF/spring-ws-config.xmlfile of the context configuration.

3.7. Secure invoicing: JBoss-preauthenticated securityThe invoicing module also illustrates the usage of JBoss-based preauthentication and interaction withSpring Security. Access to the invoicing module is secured using the Java EE security mechanisms, asdescribed in web.xml:

<security-constraint> <web-resource-collection> <web-resource-name>All resources</web-resource-name> <description>Protects all resources</description> <url-pattern>/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>*</role-name> </auth-constraint> </security-constraint> <login-config> <auth-method>BASIC</auth-method> <realm-name>sportsclub-invoicing</realm-name> </login-config> <security-role> <role-name>ADMINISTRATOR</role-name> </security-role> <security-role> <role-name>EMPLOYEE</role-name> </security-role>

In this scenario, the security domain is set up externally (for example, for multiple applications) andlinked to the web application by the definition in jboss-web.xml

<jboss-web> <security-domain>java:/jaas/employees</security-domain></jboss-web>

In the scenario implemented by this application, the concept of an 'employee who can access theapplication' is external to the application itself (perhaps multiple applications can use the same securitydomain) and defined globally in the standalone configuration file or domain configuration (deployed in theserver setup phase).

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example

36

Page 40: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

<security-domain name="employees"> <authentication> <login-module code="Database" flag="required"> <module-option name="dsJndiName" value="java:jboss/datasources/ExampleDS"/> <module-option name="principalsQuery" value="select passwd from SPORTSCLUB_USERS where username=?"/> <module-option name="rolesQuery" value="select userRoles,'Roles' from SPORTSCLUB_ROLES where username=?"/> </login-module> </authentication> </security-domain>

Essentially, the login will be performed based on the data contained in the SPORTSCLUB_USERS andSPORTSCLUB_ROLES tables defined during database import(however, it is not the application thataccesses the database directly, but the JaaS login module):

INSERT INTO SPORTSCLUB_USERS VALUES ('admin','adminPass')INSERT INTO SPORTSCLUB_USERS VALUES ('employee','employeePass')INSERT INTO SPORTSCLUB_ROLES VALUES ('admin','ADMINISTRATOR')INSERT INTO SPORTSCLUB_ROLES VALUES ('admin','EMPLOYEE')INSERT INTO SPORTSCLUB_ROLES VALUES ('employee','EMPLOYEE')

The two users, admin and employee are used to illustrate the different authorization levels in theapplication. The application uses Spring Security for authorizing access to the invoicing application'scomponents (web pages and methods) as described in /WEB-INF/spring-security-context.xml. Of specific interest to this application is the filterSecurityInterceptor bean definition,which contains the access security metadata definitions:

<bean id="fsi" class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor"> <property name="authenticationManager" ref="authenticationManager"/> <property name="accessDecisionManager" ref="httpRequestAccessDecisionManager"/> <property name="securityMetadataSource"> <sec:filter-invocation-definition-source> <sec:intercept-url pattern="/generateInvoice.do" access="ROLE_ADMINISTRATOR"/> <sec:intercept-url pattern="/**" access="ROLE_EMPLOYEE"/> </sec:filter-invocation-definition-source> </property></bean>

Anyone who is an employee can access any section of the site, but only administrators (the admin user)can generate invoices.

A similar provision is made for payments. Application classes are scanned for security annotations, asrequested by the following bean definition:

<sec:global-method-security secured-annotations="enabled"/>

Chapter 3. Using JBoss and Spring together

37

Page 41: Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example€¦ ·  · 2013-12-17Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example for use with JBoss Web Framework

Revision HistoryRevision 1-0.4 05 Tue Dec 17 2013 Rüdiger Landmann

Rebuild with Publican 4.0.0

Revision 1-0 Fri Jun 22 2012 Rebecca NewtonPushing live for JBoss Web Framework Kit 2.0.0 GA.

Red Hat JBoss Web Framework Kit 2 Snowdrop Sportsclub Example

38