Cover image for JBoss at Work: A Practical Guide

Book description

Consisting of a number of well-known open source products, JBoss is more a family of interrelated services than a single monolithic application. But, as with any tool that's as feature-rich as JBoss, there are number of pitfalls and complexities, too.

Most developers struggle with the same issues when deploying J2EE applications on JBoss: they have trouble getting the many J2EE and JBoss deployment descriptors to work together; they have difficulty finding out how to get started; their projects don't have a packaging and deployment strategy that grows with the application; or, they find the Class Loaders confusing and don't know how to use them, which can cause problems.

JBoss at Work: A Practical Guide helps developers overcome these challenges. As you work through the book, you'll build a project using extensive code examples. You'll delve into all the major facets of J2EE application deployment on JBoss, including JSPs, Servlets, EJBs, JMS, JNDI, web services, JavaMail, JDBC, and Hibernate. With the help of this book, you'll:

  • Implement a full J2EE application and deploy it on JBoss

  • Discover how to use the latest features of JBoss 4 and J2EE 1.4, including J2EE-compliant web services

  • Master J2EE application deployment on JBoss with EARs, WARs, and EJB JARs

  • Understand the core J2EE deployment descriptors and how they integrate with JBoss-specific descriptors

  • Base your security strategy on JAAS

Written for Java developers who want to use JBoss on their projects, the book covers the gamut of deploying J2EE technologies on JBoss, providing a brief survey of each subject aimed at the working professional with limited time.

If you're one of the legions of developers who have decided to give JBoss a try, then JBoss at Work: A Practical Guide is your next logical purchase. It'll show you in plain language how to use the fastest growing open source tool in the industry today. If you've worked with JBoss before, this book will get you up to speed on JBoss 4, JBoss WS (web services), and Hibernate 3.

Table of Contents

  1. Special Upgrade Offer
  2. A Note Regarding Supplemental Files
  3. About the Author
  4. Preface
    1. Audience
    2. About This Book
    3. Assumptions This Book Makes
    4. Conventions Used in This Book
    5. Using Code Examples
    6. Safari Enabled
    7. Comments and Questions
    8. Acknowledgments
      1. Tom’s Acknowledgments
      2. Scott’s Acknowledgments
  5. 1. Getting Started with JBoss
    1. 1.1. Why “JBoss at Work”?
    2. 1.2. Why JBoss?
    3. 1.3. The Example: JAW Motors
    4. 1.4. The Tools
      1. 1.4.1. Installing Java
      2. 1.4.2. Installing Ant
      3. 1.4.3. Installing XDoclet
    5. 1.5. Installing JBoss
      1. 1.5.1. Touring the JBoss Directory Structure
      2. 1.5.2. Server Configurations
      3. 1.5.3. Touring the Server Configuration Directory Structure
    6. 1.6. Deploying Applications to JBoss
    7. 1.7. Looking Ahead...
  6. 2. Web Applications
    1. 2.1. The Servlet Container
    2. 2.2. Three-Tier Applications
    3. 2.3. Exploring the Presentation Tier
    4. 2.4. Building the View Cars Page
      1. 2.4.1. Iteration 1: HTML
      2. 2.4.2. Iteration 2: JSP and JSTL
      3. 2.4.3. Iteration 3: CSS
      4. 2.4.4. Deploying the Application as a WAR File
      5. 2.4.5. A Deeper Examination of the WAR
      6. 2.4.6. Ant
    5. 2.5. Adding a Model and Controller
      1. 2.5.1. The Model
      2. 2.5.2. The Controller
    6. 2.6. Looking Ahead...
  7. 3. Building and Deploying an EAR
    1. 3.1. WARs Versus EARs
    2. 3.2. Application.xml
    3. 3.3. Common JAR
      1. 3.3.1. Exploring the New Directory Structure
        1. 3.3.1.1. The common sub-project
        2. 3.3.1.2. The webapp sub-project
        3. 3.3.1.3. The master build
        4. 3.3.1.4. Ant EAR task
    4. 3.4. Deploying the EAR
    5. 3.5. Adding a DAO
    6. 3.6. Using XDoclet
    7. 3.7. Looking Ahead...
  8. 4. Databases and JBoss
    1. 4.1. Persistence Options
    2. 4.2. JDBC
    3. 4.3. JNDI
    4. 4.4. JNDI References in web.xml
    5. 4.5. JBoss DataSource Descriptors
    6. 4.6. JDBC Driver JARs
    7. 4.7. Database Checklist
    8. 4.8. Accessing the Database Using Ant
    9. 4.9. Creating JDBCCarDAO
    10. 4.10. Looking Ahead...
  9. 5. Hibernate and JBoss
    1. 5.1. The Pros and Cons of ORMs
    2. 5.2. Hibernate Mapping Files
    3. 5.3. Hibernate MBean Service Descriptor
    4. 5.4. Creating a HAR
    5. 5.5. Adding the HAR to the EAR
    6. 5.6. Creating a JNDI Lookup
    7. 5.7. Hibernate Checklist
    8. 5.8. HibernateCarDAO
    9. 5.9. Adding a Car
    10. 5.10. Editing a Car
    11. 5.11. Deleting a Car
    12. 5.12. Looking Ahead...
  10. 6. Stateless Session Beans
    1. 6.1. Issues with EJBs
    2. 6.2. Should I Use EJB or Not?
    3. 6.3. Business Tier
    4. 6.4. Enterprise JavaBeans
    5. 6.5. Our Example
    6. 6.6. Iteration 1—Introduce a Session Bean
      1. 6.6.1. Modifying the CAR Table
      2. 6.6.2. Upgrading the CarDTO with a Status Field
      3. 6.6.3. Adding filterByStatus() to the HibernateDAO
    7. 6.7. Calling the Session Bean from the Controller Servlet
      1. 6.7.1. Factoring Out the JNDI Calls
    8. 6.8. EJB-Based JNDI References in Web-Based Deployment Descriptors
      1. 6.8.1. Automating EJB-Related JNDI Settings in Web-Based Deployment Descriptors
    9. 6.9. Session Bean Types
    10. 6.10. Session Beans
    11. 6.11. Remote Versus Local EJB Calls
      1. 6.11.1. Exploring the New Directory Structure
        1. 6.11.1.1. The ejb sub-project
    12. 6.12. Local and Remote Interfaces
      1. 6.12.1. Local Interface
      2. 6.12.2. Remote Interface
    13. 6.13. Home Interfaces
      1. 6.13.1. Local Home Interface
      2. 6.13.2. Remote Home Interface
      3. 6.13.3. The Bean Class
      4. 6.13.4. EJB Deployment Descriptors
      5. 6.13.5. EJB Transaction Settings
      6. 6.13.6. Difficulties Using EJB
      7. 6.13.7. Automating Stateless Session Bean Deployment Using XDoclet Tags
      8. 6.13.8. Ant Build Script Using XDoclet
      9. 6.13.9. EJB JAR File
      10. 6.13.10. Ant Task for Creating EJB JAR
      11. 6.13.11. Adding an EJB JAR to the EAR
    14. 6.14. Reviewing Iteration 1
    15. 6.15. Testing Iteration 1
    16. 6.16. Iteration 2—Move Business Logic Out of the Controller
      1. 6.16.1. Refactoring the Business Logic
      2. 6.16.2. Hibernate 3 and CMT
    17. 6.17. Reviewing Iteration 2
    18. 6.18. Testing Iteration 2
    19. 6.19. Iteration 3—Buy a Car
      1. 6.19.1. Upgrade the Web Site: Adding a “Buy Car” Link
      2. 6.19.2. Creating the ACCOUNTING Table
    20. 6.20. The AccountingDTO
    21. 6.21. Developing the HibernateAccountingDAO
    22. 6.22. Adding buyCar() to the InventoryFacadeBean
    23. 6.23. Reviewing Iteration 3
    24. 6.24. Testing Iteration 3
    25. 6.25. Final Thoughts on Session Beans
    26. 6.26. Looking Ahead ...
  11. 7. Java Message Service (JMS) and Message-Driven Beans
    1. 7.1. Sending Messages with JMS
    2. 7.2. Upgrade the Site: Running a Credit Check
    3. 7.3. JMS Architecture Overview
    4. 7.4. JMS Messaging Models
      1. 7.4.1. Choosing a Messaging Model
    5. 7.5. Creating a Message
    6. 7.6. Sending the Message
    7. 7.7. Core JMS API
    8. 7.8. Sending a JMS Message
      1. 7.8.1. JMS Unified Client API
      2. 7.8.2. Factoring Out the JNDI Calls
    9. 7.9. JMS-Based JNDI References in Web-Based Deployment Descriptors
      1. 7.9.1. JMS and Its Relationship to J2EE Transactions
      2. 7.9.2. Automating JMS-Related JNDI Settings in Web-Based Deployment Descriptors
    10. 7.10. Deploying JMS Destinations on JBoss
    11. 7.11. JMS Checklist
    12. 7.12. Message-Driven Beans (MDBs)
      1. 7.12.1. Writing an MDB
      2. 7.12.2. MDB Transaction Settings
      3. 7.12.3. Deploying an MDB
      4. 7.12.4. Automating MDB Deployment with XDoclet
    13. 7.13. MDB Checklist
    14. 7.14. Testing the Credit Check
    15. 7.15. Looking Ahead ...
  12. 8. JavaMail
    1. 8.1. Running a Credit Check
    2. 8.2. Sending Email Messages with JavaMail
    3. 8.3. Upgrading the MDB to Send an Email Message
    4. 8.4. Sending an Email Message
      1. 8.4.1. JavaMail Sessions
      2. 8.4.2. Factoring out the JNDI Calls
    5. 8.5. JavaMail-Based JNDI References in EJB Deployment Descriptors
    6. 8.6. Automating JavaMail-Based JNDI References with XDoclet
    7. 8.7. Deploying JavaMail on JBoss
    8. 8.8. JavaMail Checklist
    9. 8.9. Testing the Credit Check Notification Email
    10. 8.10. Looking Ahead ...
  13. 9. Security
    1. 9.1. J2EE Security
    2. 9.2. Web-Based Security
      1. 9.2.1. Protecting the Administrative Pages
    3. 9.3. Restricting Access with web.xml
      1. 9.3.1. Web-Based Authentication
      2. 9.3.2. Form-Based Authentication
      3. 9.3.3. The Login Form
      4. 9.3.4. Automating Declarative Authentication and Authorization in web.xml
      5. 9.3.5. Creating a Security Realm
    4. 9.4. JAAS
      1. 9.4.1. LoginModule
    5. 9.5. Deploying a JAAS-Based Security Realm on JBoss
      1. 9.5.1. JBoss LoginModule Configuration
      2. 9.5.2. Custom LoginModule Configuration
      3. 9.5.3. JAAS Domain Settings in jboss-web.xml
      4. 9.5.4. Automating JAAS Domain Settings in jboss-web.xml
    6. 9.6. Testing Secure JSPs
    7. 9.7. Protecting the Administrative Actions
      1. 9.7.1. Are We Done with Web Security Yet?
      2. 9.7.2. Propagating Security Credentials from the Web Tier
      3. 9.7.3. Automating Security Credential Propagation in web.xml
      4. 9.7.4. Testing Web Security
    8. 9.8. Web Security Checklist
    9. 9.9. Integrating Web Tier and EJB Tier Security
    10. 9.10. EJB Security
      1. 9.10.1. JAAS Domain in jboss.xml
      2. 9.10.2. Automating JAAS Domain Settings in jboss.xml
      3. 9.10.3. Protecting EJBs with ejb-jar.xml
      4. 9.10.4. Automating EJB Security Settings with XDoclet
      5. 9.10.5. Testing Secure EJB Methods
    11. 9.11. EJB Security Checklist
    12. 9.12. Looking Ahead ...
  14. 10. Web Services
    1. 10.1. Web Services Architecture
    2. 10.2. JBoss 4.x and Web Services
    3. 10.3. J2EE 1.4 and Web Services
    4. 10.4. Implementing J2EE 1.4 Web Services
    5. 10.5. Service Endpoint Interface (SEI)
    6. 10.6. Modifying ejb-jar.xml
    7. 10.7. webservices.xml
    8. 10.8. JAX-RPC Mapping File
    9. 10.9. WSDL File
    10. 10.10. Set the Web Service URL
    11. 10.11. Modifying the InventoryFacadeBean EJB
      1. 10.11.1. Web Services Data Types
      2. 10.11.2. Web Services and Collections
    12. 10.12. Web Services Deployment
    13. 10.13. Automating Web Services Deployment
      1. 10.13.1. Web Services Ant Script
    14. 10.14. J2EE Web Services Checklist
    15. 10.15. Testing Web Services Deployment
    16. 10.16. Web Services Client
      1. 10.16.1. Exploring the New Directory Structure
        1. 10.16.1.1. The client sub-project
    17. 10.17. Implementing a Web Service Client
    18. 10.18. Web Service Client Checklist
    19. 10.19. Testing the Web Service Client
    20. 10.20. Final Thoughts on J2EE 1.4 Web Services
    21. 10.21. Conclusion
    22. 10.22. Congratulations!
  15. A. ClassLoaders and JBoss
    1. A.1. Namespaces
    2. A.2. Class Loading in the J2EE
    3. A.3. Class Loading with JBoss
    4. A.4. Common ClassLoader Issues
    5. A.5. ClassLoader Options
    6. A.6. Solving ClassLoader Issues
    7. A.7. Conclusion
  16. B. Logging and JBoss
    1. B.1. Jakarta Commons Logging (JCL) API
      1. B.1.1. Using the Apache JCL
      2. B.1.2. Using a Logging Implementation
      3. B.1.3. Property File
      4. B.1.4. Logging Levels
    2. B.2. Apache Log4J
      1. B.2.1. Log4J Core Concepts
      2. B.2.2. PatternLayout
      3. B.2.3. Log4J Configuration File
      4. B.2.4. Log4J Initialization
      5. B.2.5. Initialization Servlet
    3. B.3. Adding Application-Specific Properties to System Properties
    4. B.4. Configuring Log4J with a Configuration File
    5. B.5. Loading Resources from the CLASSPATH
    6. B.6. Logging Deployment
    7. B.7. Logging Checklist
    8. B.8. Testing Logging
    9. B.9. Conclusion
  17. C. JAAS Tutorial
    1. C.1. JAAS
      1. C.1.1. JAAS Core Concepts, Classes, and Interfaces
      2. C.1.2. LoginContext
      3. C.1.3. LoginModule
      4. C.1.4. Callback
      5. C.1.5. CallbackHandler
      6. C.1.6. JAAS LoginModule Configuration and Deployment
      7. C.1.7. LoginModule Configuration Flags
    2. C.2. Client-Side JAAS
      1. C.2.1. External Client Application that Uses JAAS
      2. C.2.2. Client-Side LoginModule Configuration
      3. C.2.3. J2SE Security Policy File
      4. C.2.4. Setting the Client CLASSPATH
    3. C.3. Conclusion
  18. Index
  19. About the Authors
  20. Colophon
  21. Special Upgrade Offer
  22. Copyright