Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

JBoss AS 7 Development
JBoss AS 7 Development
JBoss AS 7 Development
Ebook636 pages3 hours

JBoss AS 7 Development

Rating: 0 out of 5 stars

()

Read preview

About this ebook

In Detail

JBoss Application Server meets high standards of reliability, efficiency, and robustness, and is used to build powerful and secure Java EE applications. It supports the most important areas of Java Enterprise programming including EJB 3.1, Contexts and Dependency Injection, JAX-WS and JAX-RS web services, the security framework, and more. Getting started with JBoss application server development can be challenging; however, with the right approach and guidance, you can easily master it and this book promises that.

Written in an easy-to-read style, this book will take you from the basics of JBoss AS-such as installing core components and plugins-to the skills that will make you a JBoss developer to be reckoned with, covering advanced topics such as developing applications with the JBoss messaging service, JBoss web services, clustered applications, and more.

You will learn the necessary steps to install a suitable environment for developing enterprise applications on JBoss AS. You will also learn how to design Enterprise applications using Eclipse, JBoss plugins, and Maven to build and deploy your applications. Readers will learn how to enable distributed communication using JMS. Storing and retrieving objects will be made easier using the Java Persistence API. The core section of the book will take you into the programming arena with tested, real-world examples. The example programs have been carefully crafted to be easy to understand and useful as starting points for your applications.

This practical guide will show you how to gain hands-on experience rapidly on Java EE development using JBoss AS with easy-to-understand and practical programming examples.

Approach

This book will kick-start your productivity and help you to master JBoss AS development. The author's experience with JBoss enables him to share insights on JBoss AS development in a clear and friendly way. By the end of the book, you will have the confidence to apply all the newest programming techniques to your JBoss applications.

Who this book is for

If you are a Java architect or developer who wants to get the most out of the latest release of the JBoss application server, then this book is for you. You are not expected to have accumulated experience on the application server though you must know the basic concepts of Java EE.

LanguageEnglish
Release dateJun 24, 2013
ISBN9781782161356
JBoss AS 7 Development
Author

Francesco Marchioni

Francesco Marchioni is a Red Hat Certified JBoss Administrator (RHCJA) and a Sun Certified enterprise architect working as a freelancer in Rome, Italy. He started learning Java in 1997, and since then, he has followed the path to the newest application program interfaces released by Sun. In 2000, he joined the JBoss community, when the application server was running the release 2.X. He has spent many years as a software consultant, wherein he envisioned many successful software migrations from vendor platforms to open source products such as JBoss AS, fulfilling the tight budget requirements of current times. Over the past 5 years, he has been authoring technical articles for OReilly Media and running an IT portal focused on JBoss products (http://www.mastertheboss.com). In December 2009, he published JBoss AS 5 Development, which describes how to create and deploy Java Enterprise applications on JBoss AS (http://www.packtpub.com/jboss-as-5-development/book). In December 2010, he published his second title, JBoss AS 5 Performance Tuning, which describes how to deliver fast and efficient applications on JBoss AS (http://www.packtpub.com/jboss-5-performance-tuning/book). In December 2011, he published yet another title, JBoss AS 7 Configuration, Deployment, and Administration, which covers all the aspects of the newest application server release (http://www.packtpub.com/jboss-as-7-configuration-deploymentadministration/book). In June 2013, he authored a new title, JBoss AS 7 Development, which focuses on developing Java EE 6 API applications on JBoss AS 7 (https://www.packtpub.com/application-development/jboss-7-development).

Read more from Francesco Marchioni

Related to JBoss AS 7 Development

Related ebooks

Enterprise Applications For You

View More

Related articles

Reviews for JBoss AS 7 Development

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    JBoss AS 7 Development - Francesco Marchioni

    Table of Contents

    JBoss AS 7 Development

    Credits

    About the Author

    About the Reviewers

    www.PacktPub.com

    Support files, eBooks, discount offers and more

    Why Subscribe?

    Free Access for Packt account holders

    Preface

    What this book covers

    What you need for this book

    Who this book is for

    Conventions

    Reader feedback

    Customer support

    Downloading the example code

    Errata

    Piracy

    Questions

    1. Getting Started with JBoss AS 7

    An overview of Java EE and JBoss AS 7

    Welcome to Java EE 6

    JavaServer Faces (JSF) 2.0

    Enterprise JavaBeans (EJB) 3.1

    Java Persistence API (JPA) 2.0

    Contexts and Dependency Injection for Java

    Java Servlet API 3.0

    Java API for web services (JAX-RS and JAX-WS)

    Java API for XML-based web services (JAX-WS)

    Java architecture for XML Binding (JAXB) 2.2

    New features in JBoss AS 7

    Installing the server and client components

    Installing Java SE

    Testing the installation

    Installing JBoss AS 7

    Starting up JBoss AS

    Connecting to the server with the Command Line Interface

    Stopping JBoss

    Locating the shutdown script

    Stopping JBoss on a remote machine

    Restarting JBoss

    Installing the Eclipse environment

    Installing JBoss Tools

    Alternative development environments

    Installing Maven

    Testing the installation

    Summary

    2. What's New in JBoss AS 7

    AS 7 core concepts

    The AS 7 filesystem

    Managing the application server

    Managing JBoss AS 7 with the web interface

    Launching the web console

    Deploying your first application to JBoss AS 7

    Advanced Eclipse deployment options

    Managing deployments with the web console

    Changing the deployment scanner properties

    Deploying applications using the CLI

    Deploying applications to a domain

    Summary

    3. Beginning Java EE 6 – EJBs

    EJB 3.1 – new features

    Developing singleton EJBs

    Configuring the project object module (pom.xml)

    Coding our EJB application

    Controlling bean concurrency

    Using bean-managed concurrency

    Cooking session beans

    Adding a stateless bean

    Adding a stateful bean

    Deploying the EJB application

    Creating a remote EJB client

    Configuring the client's project object module

    Coding the EJB client

    Adding EJB client configuration

    Running the client application

    Adding user authentication

    Using the EJB timer service

    Programmatic timer creation

    Scheduling timer events

    Adding asynchronous methods to our EJBs

    Using fire-and-forget asynchronous calls

    Returning a Future object to the client

    Summary

    4. Learning Context Dependency Injection

    Introducing Context and Dependency Injection

    Named beans

    CDI scopes

    JBoss AS CDI implementation

    Rethinking your ticketing system

    Adding the required dependencies

    Coding the beans

    Building the view

    JSF 2 facet suggestions

    Getting ready to run the application

    Combining the scheduler into our application

    Installing RichFaces

    Making your application rich

    Running the application

    Are EJBs and JSF Managed Beans obsolete?

    Summary

    5. Combining Persistence with CDI

    Data persistence meets a standard

    Working with JPA

    Adding persistence to our application

    Setting up the database

    Installing the JDBC driver on JBoss AS 7

    Using the command-line interface to create a new data source

    Creating the Maven project

    Adding Maven configuration

    Cooking entities

    Adding JavaBeans Validation

    Configuring persistence

    Adding producer classes

    Coding queries for your application

    Adding services to your application

    Adding a controller to drive user requests

    Coding the JSF view

    Running the example

    Summary

    6. Testing Your Applications

    Unit testing and integration testing

    Instruments for testing

    Getting started with Arquillian

    Writing an Arquillian test

    Configuring the pom.xml file

    Writing your first Arquillian test

    Running Arquillian TicketTest

    Running Arquillian TicketTest with a managed container

    Enhancing your Arquillian test

    Additional information

    Summary

    7. Developing Applications with JBoss JMS Provider

    A short introduction to JMS

    The building blocks of JMS

    The JBoss messaging subsystem

    Creating and using connection factories

    Using JMS destinations

    Adding message-driven beans to your application

    Cooking message-driven beans

    Adding the JMS producer

    Compiling and deploying the application

    Optimizing JMS connections

    Specifying which message to receive using selectors

    Using JMS to integrate with external systems

    A real-world example – HornetQ and ActiveMQ integration

    Installing the ActiveMQ resource adapter

    Consuming ActiveMQ messages

    Summary

    8. Adding Web Services to Your Applications

    Developing SOAP-based web services

    Strategies for building SOAP web services

    JBoss SOAP web services stack

    A brief look at the JAX WS architecture

    Coding SOAP web services with JBoss AS 7

    Developing a POJO web service

    Inspecting the web service from the console

    Testing our simple web service

    EJB3 Stateless Session Beans (SLSB) web services

    Developing a web service consumer

    Compiling the example

    Developing REST-based web services

    Accessing REST resources

    JBoss REST web services

    Activating RESTEasy

    Adding REST to our Ticket example

    Consuming our REST service

    Compiling our Ticket example

    Choosing between SOAP and REST services

    Summary

    9. Managing the Application Server

    Entering the JBoss Command Line Interface (CLI)

    Launching the CLI

    Connecting from remote hosts

    Using the CLI in the graphical mode

    Constructing the CLI commands

    Determining the resource address

    Performing operations on resources

    Using the tab completion helper

    Deploying applications using the CLI

    Deploying applications to a JBoss AS 7 domain

    Deploy to all server groups

    Deploy to a single server group

    Creating CLI scripts

    Deploying an application to several JBoss AS 7 nodes

    Restarting servers in a domain

    Installing a datasource as a module

    Adding JMS resources

    Using advanced languages to create powerful CLI scripts

    Using scripting languages to wrap CLI execution

    Using the raw management API to manage the application server

    Reading management model descriptions via the raw management API

    Creating your resource watches using the detyped API

    Summary

    10. Clustering JBoss AS 7 Applications

    Clustering basics

    JBoss AS 7 clustering

    Starting a cluster of standalone nodes

    Starting a cluster of domain nodes

    The domain controller configuration

    Host configurations

    Deploying clustered applications

    Clustering EJBs

    Creating HA Stateful Session Beans

    Clustering the Ticket example

    Turning your cache into a distributed cache

    Coding the cluster-aware remote client

    Deploying and testing high availability

    Web application clustering

    Load balancing your web applications

    Installing mod_cluster

    Clustering your web applications

    Programming considerations to achieve HA

    Achieving HA in JSF applications

    Summary

    11. Securing JBoss AS 7 Applications

    Approaching the Java security API

    JBoss AS 7 security subsystem

    Setting up your first login module

    Using the login module in the Ticket web application

    Switching to FORM-based security

    Creating a Database login module

    Encrypting passwords

    Using the Database login module in your application

    Securing EJBs

    Securing web services

    Securing the transport layer

    Enabling the Secure Socket Layer on JBoss AS

    Certificate management tools

    Securing the HTTP communication with a self-signed certificate

    Securing HTTP communication with a certificate signed by a CA

    Securing EJB communication

    Generating the server and client certificates

    Creating an SSL-aware security realm

    Creating an SSL-aware security realm

    Summary

    A. Rapid Development Using JBoss Forge

    Installing Forge

    Starting Forge

    Creating your first Java EE 6 application with JBoss Forge

    Building and deploying the application

    Your forge-demo application in action

    Index

    JBoss AS 7 Development


    JBoss AS 7 Development

    Copyright © 2013 Packt Publishing

    All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

    Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

    Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

    First published: December 2009

    Second edition: June 2013

    Production Reference: 1170613

    Published by Packt Publishing Ltd.

    Livery Place

    35 Livery Street

    Birmingham B3 2PB, UK.

    ISBN 978-1-78216-134-9

    www.packtpub.com

    Cover Image by Suresh Mogre (<suresh.mogre.99@gmail.com>)

    Credits

    Author

    Francesco Marchioni

    Reviewers

    Peter Johnson

    Martin Večeřa

    Acquisition Editor

    James Jones

    Lead Technical Editor

    Azharuddin Sheikh

    Technical Editors

    Vrinda Amberkar Bhosale

    Nitee Shetty

    Copy Editors

    Insiya Morbiwala

    Alfida Paiva

    Aditya Nair

    Project Coordinator

    Arshad Sopariwala

    Proofreaders

    Stephen Copestake

    Lucy Henson

    Clyde Jenkins

    Indexer

    Hemangini Bari

    Graphics

    Ronak Dhruv

    Abhinash Sahu

    Production Coordinator

    Aditi Gajjar

    Cover Work

    Aditi Gajjar

    About the Author

    Francesco Marchioni is a Sun Certified Enterprise Architect employed for an Italian company based in Rome. He started learning Java in 1997 and since then has followed the path to the newest application program interfaces released by Sun. He joined the JBoss community in 2000, when the application server was running release 2.x.

    He has spent many years as a software consultant, where he has envisioned many successful software migrations from vendor platforms to open source products such as JBoss AS, fulfilling the tight budget requirements of current times.

    Over the past 5 years, he has been authoring technical articles for OReilly Media and is running an IT portal focused on JBoss products (http://www.mastertheboss.com).

    He has authored the following titles:

    JBoss AS 5 Development, Packt Publishing (December 2009), which describes how to create and deploy Java Enterprise applications on JBoss AS (http://www.packtpub.com/jboss-as-5-development/book)

    AS 5 Performance Tuning, Packt Publishing (December 2010), which describes how to deliver fast and efficient applications on JBoss AS (http://www.packtpub.com/jboss-5-performance-tuning/book)

    JBoss AS 7 Configuration, Deployment, and Administration, Packt Publishing (December 2011), which covers all the aspects of the newest application server release (http://www.packtpub.com/jboss-as-7-configuration-deployment-administration/book)

    He has also co-authored the book Infinispan Data Grid Platform, Packt Publishing (August 2012), with Manik Surtani, which covers all the aspects related to the configuration and development of applications using the Infinispan Data Grid Platform (http://www.packtpub.com/infinispan-data-grid-platform/book).

    I'd like to thank Packt Publishing for sharing the vision of this 
new book and for all the effort they put into it. I'd like also to 
thank my family for always being by my side; in particular, I'd 
like to thank my wife for letting me follow my book author ambitions and my father for buying me a C-64 instead of a motorcycle when I was young.

    About the Reviewers

    Peter Johnson has over 32 years' enterprise computing experience. He has been working with Java since the past 15 years, and for the last 10 years, has been heavily involved with Java performance tuning. He is a frequent speaker on Java performance topics at various conferences, including the Computer Measurement Group annual conference, JBoss World, and Linux World. He is a moderator for the build tools and JBoss forums at Java Ranch. He is also the co-author of the book JBoss in Action, First Edition, Manning Publications, and has been a reviewer on numerous books on topics ranging from Java to Windows PowerShell.

    Martin Večeřa is a JBoss Quality Assurance Manager within a division of Red Hat. He is interested in bleeding-edge projects and technologies. His main area of interest is Java middleware and SOA, in which he has almost 10 years' experience. Previously, he has developed information systems for power plants and medical companies. He publishes articles on Java middleware to various international and local web magazines.

    He is the co-author of a blog on the PerfCake Performance Testing Framework.

    www.PacktPub.com

    Support files, eBooks, discount offers and more

    You might want to visit www.PacktPub.com for support files and downloads related to your book.

    Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at for more details.

    At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

    http://PacktLib.PacktPub.com

    Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books.

    Why Subscribe?

    Fully searchable across every book published by Packt

    Copy and paste, print and bookmark content

    On demand and accessible via web browser

    Free Access for Packt account holders

    If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.

    A thought to my loving family, who care about me, and to all the people who are striving to make our country a better place for our children. As somebody said, If you have time to whine and complain about something, you have the time to do something about it.

    Preface

    The JBoss Application Server is a certified platform for Java EE for developing and deploying Java Enterprise applications. The JBoss Application Server provides the full range of Java EE 1.6 features as well as extended Enterprise services, including clustering, caching, and persistence. This book will show Java EE developers how to develop their applications using the JBoss Application Server and the widely used Eclipse environment combined with the Maven framework, which will greatly increase your productivity. The whole learning process is arranged through a common theme application, the Ticket Booking application, that progressively increases in complexity as new topics are introduced.

    What this book covers

    Chapter 1, Getting Started with JBoss AS 7, discusses installing the core application server distribution and all the required tools for running it and for developing Java EE applications (JVM, Eclipse, and Maven).

    Chapter 2, What's New in JBoss AS 7, provides a crash course on JBoss AS 7. It introduces the new filesystem structure, the application's configuration, and the dichotomy between standalone servers and domain servers.

    Chapter 3, Beginning Java EE 6 – EJBs, discusses the new features introduced by EJB 3.1, including Singleton EJB, Asynchronous EJB, and EJB Timer Service. We will develop our Ticket Booking application, which will be the main theme of the book.

    Chapter 4, Learning Context Dependency Injection, introduces Context Dependency Injection, comparing its features with the older EJB and JSF programming models. We will show how to enhance out ticket system using CDI annotations.

    Chapter 5, Combining Persistence with CDI, discusses the Java Persistence API, showing how we can persist data on a relational database. We will then combine the JPA API with the example developed in the earlier chapters.

    Chapter 6, Testing Your Applications, introduces Arquillian, showing how to use it for testing your application using a running application server instance or by managing its own server instance.

    Chapter 7, Developing Applications with JBoss JMS Provider, discusses the Java Message Service, showing how you can configure some core JMS elements (such as factories and destinations) on your server. Next, we will enhance our Ticket example by adding a JMS producer and consumer. The last part of this chapter deals with advanced concepts, such as consuming messages from an external JMS provider.

    Chapter 8, Adding Web Services to Your Applications, talks about the two core web services stacks: SOAP-based web services and RESTful web services; it provides concrete examples and highlights the differences between the two approaches.

    Chapter 9, Managing the Application Server, talks about the core concepts of the Command Line Interface and how it can improve your productivity. The next part of this chapter dives deep into writing CLI scripts using other languages such as Jython.

    Chapter 10, Clustering JBoss AS 7 Applications, is all about the world of clustered applications. We will learn how to use the robust clustering features of JBoss AS applied to some of the examples discussed in this book.

    Chapter 11, Securing JBoss AS 7 Applications, will show how to use security domains to perform required authorization and authentication checks. The next part of this chapter discusses securing the data that is transmitted from the client to the server and vice versa.

    Appendix, Rapid Development Using JBoss Forge, is the last section of this book; it is about the JBoss Forge framework. It shows how you can use this framework to generate a basic CRUD (Create/Read/Update/Delete) application.

    What you need for this book

    This is a developer's guide; for this reason, it is highly recommended that you read this book with a computer beside you, where you can try the examples and open, compile, and test the provided projects. Besides this, it's also required that you have an Internet connection where you can download the core server and additional libraries used in the examples.

    Good programming skills are required to easily understand the examples presented in this book. Most of the chapters complement the covered topics with a set of executable Maven projects. A basic understanding of Maven, Java, and JUnit is also required.

    Who this book is for

    If you are a Java architect or a developer who wants to get the most out of the latest release of the JBoss Application Server, this book is for you. You are not expected to have accumulated a lot of experience on the application server, though you must know the basic concepts of Java EE.

    Conventions

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

    Code words in text are shown as follows: The users are stored in a properties file called mgmt-users.properties under standalone/configuration or domain/configuration depending on the running mode of the server.

    A block of code is set as follows:

    @WebServlet(/test)

    public class TestServlet extends HttpServlet {     

      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        PrintWriter out = response.getWriter();

        out.println(Hello World JBoss AS 7);

        out.close();

      }

      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {   

      }

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

    @SessionScoped @Named

     

    public class TheatreBookerBean implements Serializable {

    }

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

    mvn install jboss-as:deploy –Dhostname=localhost –Dport=9999

    New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: Click on Finish to continue.

    Note

    Warnings or important notes appear in a box like this.

    Tip

    Tips and tricks appear like this.

    Reader feedback

    Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

    To send us general feedback, simply send an e-mail to <feedback@packtpub.com>, and mention the book title via the subject of your message.

    If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors .

    Customer support

    Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

    Downloading the example code

    You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

    Errata

    Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

    Piracy

    Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

    Please contact us at <copyright@packtpub.com> with a link to the suspected pirated material.

    We appreciate your help in protecting our authors, and our ability to bring you valuable content.

    Questions

    You can contact us at <questions@packtpub.com> if you are having a problem with any aspect of the book, and we will do our best to address it.

    Chapter 1. Getting Started with JBoss AS 7

    In this book, we will learn how to develop applications on the JBoss Application Server Release 7, which marks a giant leap from previous application server releases. The

    Enjoying the preview?
    Page 1 of 1