Part 2: Building Conforming J2EE and Web Service-Enabled Applications


Chapter List

Chapter 4: Building Presentation Logic with WebSphere Studio
Chapter 5: Building the Business Logic with WebSphere Studio
Chapter 6: J2EE Application Assembly and Deployment
Chapter 7: EIS Integration and Messaging
Chapter 8: Enabling Business Logic for Web Services

We are often asked about how to build applications that can be ported easily to (or from) other application servers. Doing so requires that you confine yourself to the standard programming model defined by J2EE. This part of the book will take you through the major elements of the J2EE programming model for web, enterprise, and service-oriented components. The emphasis in this part of the product is on creating conforming applications that can be ported easily to and from other conforming application servers.

One of our objectives for this book has been to be more than just a J2EE primer. We want to help you understand the relationship between your application and the underlying WebSphere runtime. We believe that doing so will lead you to build more efficient and durable components. This part of the book is no exception, as we show you how the application server functions in the presence of different design practices. In particular, we highlight how you can apply quality-of-service policies to your standard components to cause runtime management of your components in a way that maximizes through-put and minimizes resource consumption.

We spend some time in this part of the book delving into the relationship of J2EE applications with other information-system technologies that are likely to exist in your enterprise. We focus some attention on Java Messaging Services and Java 2 Connectors, and how these can be used both to address asynchronous information flow, and to leverage legacy application functions employed elsewhere in your system.

Web services are quickly proving to be a critical component in distributed computing. The fundamental premise for web services is to enable loosely-coupled integration between distributed parts of the information system. This is essential for bridging the disparity of technologies, time, and organizations that has always stood as an obstacle to broad-based business integration. WebSphere is one of the first J2EE products to support the newly emerging Java standards for web services implementation and deployment. While these standards are not literally required to conform to the J2EE specification at this time, we believe that web services will hold such an important role in application serving, that we have decided to treat them in this part of the book – in anticipation of these becoming a natural part of the J2EE specification and the center-piece for all conforming application servers in the future.

All of the principles discussed in this part of the book are based on the J2EE 1.3 standard and only leverage features of the base WebSphere Application Server runtime and WebSphere Studio Application Developer tool.

When you get done with this part of the book you will have a good understanding of how to build a conforming J2EE application, including the role that web services may play in your distributed computing environment. More importantly, you will understand the inter-relationship between your application and the underlying application-server runtime and the things the runtime does to manage the information infrastructure on which your application is hosted – so that you don't have to.

About the Plants-By-WebSphere Sample

This part of the book makes heavy use of the Plants-By-WebSphere sample application. The Plants-By-WebSphere application is a sample shipped in the WebSphere Application Server, along with source code, to demonstrate a classic J2EE application implementation.

We have substantially modified the Plants-By-WebSphere sample in this book to demonstrate aspects of the J2EE programming model and web services concepts that were not covered in the original example provided by IBM. You will want to use the version of the sample shipped with this book if you are going to follow the discourse in the book.

Important

If you are using the WebSphere Application Server, be sure to uninstall the Plants-By-WebSphere example application that ships with WebSphere. Also, you need to remove the data sources that are pre-installed with WebSphere for the Plants-By-WebSphere example. The examples in this book will walk you through creating data sources that are appropriate for the modified example presented here, and the data sources shipped with WebSphere will interfere with those created in this book. Refer to Chapter 14 for more information on un installing applications and removing data sources.

The Plants-By-WebSphere application represents a mail-order storefront for plants, trees, and garden tools:

click to expand

The Plants-By-WebSphere sample in this book is composed of a set of JSP pages, servlets, and EJBs, which are listen below:

  • JSP pages

    • cart
      Presents the contents of the shopping cart; the contents of the shopping cart are got from the ShoppingCart EJB.

    • checkout
      Presents a form for gathering credit-card and shipping information; the contents of the checkout form, along with the contents of the shopping cart.

    • orderdone
      Presents confirmation of the completed order submission.

    • product
      Presents the a detailed view of the item selected from the main catalog pages.

    • salesitems
      Frames the component images of the main home-page logo for the store front.

    • showcatalog
      Lists the contents of the catalog; the contents of the catalog are taken from the catalog database retrieved through the Inventory EJB.

  • Other Pages

    • index.html
      This is the home page for the store; presenting the store front logo and providing navigation to the main features of the web site.

    • banner.html
      Presents the standard noteback tab metaphor for navigating the web site.

  • Servlets

    • ShoppingControllerServlet
      The main point of control for user input to the plant store web interface.

  • Model Wrappers

    • CartModel
      A wrapper to the ShoppingCart EJB.

    • CustomerModel
      A wrapper to the Customer EJB.

    • InventoryModel
      A wrapper to the Inventory EJB.

    • OrderModel
      A wrapper to the Order EJB.

  • EJBs

    • Catalog
      A stateless session bean that collects information from the store inventory that can be used to present a visual catalog to shoppers.

    • Customer
      A CMP entity bean representing customers that have purchased items from the store.

    • FulFillOrder
      A stateless session bean used to complete the order request processing.

    • Inventory
      A CMP entity bean that represents the inventory of items that are available for sale through the plant store. In addition to identifying and depicting the items in the store's catalog, it also retains the price and quantity of stock on hand for each item.

    • Order
      A CMP entity bean used to represent a particular customer order.

    • OrderIdGenerator
      A CMP entity bean that is responsible for creating unique order numbers.

    • OrderItem
      A CMP entity bean that captures the type and quantity of a specific product ordered. OrderItems are aggregated by an Order.

    • OrderSender
      A stateless session bean used to send a message when the order is complete.

    • OrderReceiver
      A message-driven bean that receives order messages and calls the FulFillOrder bean to complete the order processing.

    • ShoppingCart
      A stateful session bean that holds the contents of the shopping cart. The shopping cart is modeled as an EJB to allow it to be retained across different sessions with the user.

  • Helper classes

    • CustomerInfo
      A Java holder-object for the Customer bean.

    • InsufficientInventoryException
      This exception is thrown by the FulFillOrder bean if the order cannot be filled.

    • OrderInfo
      A holder object for the Order bean.

    • StoreItem
      A holder-object for the contents of an item in the Catalog. This holder-object is used to pass around the information about the Catalog item. It is used in many of the operations on the Catalog.

    • Util
      It supports a variety of helper functions used throughout the Plants-By-WebSphere application for various repeated activities, such as getting EJB homes, getting the initial JNDI context, and so on.

  • Web Services

    • PlantsByWebSphereCatalogService
      This is a web service representing the PlantsByWebSphereCatalog port-type with a SOAP binding. This service can be used to get product information from the Catalog.

The following diagram depicts the general structure of the Plants-By-WebSphere example produced in this part of the book:

click to expand

The JSP pages and servlets are developed in Chapter 4. The web application portion of this example is developed to use a set of wrappers to the EJBs in the EJB module. This technique allows the web application to be developed in parallel with the development of the EJBs – the model – wrappers are used as temporary stand-ins to the EJBs during the development of the web application. Later, when the EJBs are completed, these model objects can be mapped or delegated on to the actual EJBs.

The majority of EJBs are developed in Chapter 5. The EJBs in this part of the sample are largely taken from the original Plants-By-WebSphere example that ships with WebSphere, but have been extended to demonstrate the transactional coordination of updates to the database and JMS queues (as demonstrated in Chapter 7), and the use of relationships. To support the latter concept, the OrderItem bean has been introduced – an Order aggregates multiple OrderItems.

This much of the application is assembled and deployed in Chapter 6. To support commit coordination with JMS, the application is deployed in this chapter with XA data sources to the Cloudscape database that ships with WebSphere. For this reason, as the warning above indicates, it is very important that you remove the data sources that are configured by default with WebSphere – the default data sources do not support commit-coordination and therefore, will fail when you introduce the changes discussed in the Chapter 7.

The messaging EJBs, OrderSender and FulFillOrder, are developed in Chapter 7. This chapter discusses the basics of the Java 2 Connector Architecture but does not develop that into the Plants-By-WebSphere, primarily because doing so would require the introduction of a "sample legacy system" and that would be going into too much detail for this book.

Enabling the Catalog as a web service is developed in Chapter 8. This chapter introduces the PlantsByWebSphereCatalogService composed of the PlantsByWebSphere port type (derived from the Catalog bean) and SOAP binding.

The application will be developed further in Part 3 of the book.




Professional IBM WebSphere 5. 0 Applicationa Server
Professional IBM WebSphere 5. 0 Applicationa Server
ISBN: N/A
EAN: N/A
Year: 2001
Pages: 135

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net