ONJava.com -- The Independent Source for Enterprise Java  
oreilly.comSafari Books Online.Conferences.
 

A Tour Through WebLogic Workshop 8.1: Westside Auto Sales

by Scott Semyan
10/17/2003
Content provided by BEA Systems

The new WebLogic Workshop 8.1 contains many new features and is a huge step forward from the earlier product. Now, in addition to Web services, you can build many other types of J2EE applications. As a way of introducing this new version, this article will show how to build an enterprise application incorporating many of the new features found in WebLogic Workshop 8.1.

This article assumes a basic understanding of J2EE (Java 2 Enterprise Edition).

The application we will build in this article is "Westside Auto Sales" — an end-to-end automotive sales tool. This application has several pieces illustrated in the diagram below. The core modules of the application are 1) the Web application front end, 2) the Web service for ordering more cars, and 3) the manufacturer's Web service for processing the order for more cars. These modules, in turn, call Java controls and EJBs (Enterprise Java Beans) that perform application-level tasks. The basic architecture is illustrated below.

The data flow for our application is as follows: a user comes to the Westside Auto Sales (WAS) site and views the inventory (via a NetUI grid control on a JSP populated by a database control in a Page Flow). When they see a car they like, they can buy it but they must first sign in (via integrated security). The car they purchase is then set to "Sold" status (via an Entity EJB called from a custom control), and another car of the same type is added to the database with a status of "On Order" (again, via an Entity EJB). Finally, a message is sent to the Java Messaging Service (JMS) topic (via a JMS control) to initiate ordering another car from the manufacturer. The user gets a confirmation for their purchase and then can continue shopping.

Meanwhile, a message-driven EJB sees the message arrive in the WAS JMS topic and calls a method on the WAS Web service to initiate the process of ordering another car from the manufacturer. The WAS Web service first builds an "OrderCar" XML package via XMLBeans to send to the manufacturer. A request for a new car is sent to the manufacturer's Web service with the help of a Web service control. The manufacturer first decodes the XML using XMLBeans (and for Hondas, XQuery). They then add the order to their database and immediately return an order number. Later, when the car is shipped, the manufacturer's Web service calls the callback on the WAS Web service and sends the details of the car being shipped, including the final price. The WAS Web service finally uses an entity EJB to set the vehicle's actual price and mark it as available for sale.

We will go through the steps of building this application from scratch, discussing how each of the parts work along the way.

Data Store

Before we start building our application, we first need to create our database and tables and add a connection pool and JMS message topic to our WebLogic Server domain. For this project, I am using Microsoft SQL Server 2000, but you can use any JDBC-compliant database. Create a new database on your database server called "WASdb" and run the following SQL script to create the necessary tables, stored procedures, and default data. Note: this script is for Microsoft SQL; you may need to modify it to work on your database.

------------------------------------
-- Westside Auto Sales Tables & View
------------------------------------

create table Cars
(
    CarID   int identity primary key,
    Make    varchar(50) not null,
    Model   varchar(50) not null,
    Description varchar(800) not null
)
go

create table Inventory
(
    SKU     int identity primary key,
    CarID   int not null,
    Price   int not null,
    Status  varchar(50) 
)
go

create view CarInventory
as
	select c.CarID, Make, Model, Description, SKU, Price, Status
	from Cars c, Inventory i where c.CarID = i.CarID
go

----------------------------------
-- Sample Data
----------------------------------

insert Cars select "Volkswagen", "New Beetle", 
"The 2003 New Beetle is a 2-door, 4-passenger family coupe, or sports coupe, 
available in 8 trims, ranging from the GL 2.0L to the Turbo S 1.8L."

insert Cars select "Mini", "Cooper", 
"The new Mini Cooper is more fun than a carnival ride. Both models handle 
like sports cars and the Mini Cooper S can accelerate from 0 to 60 mph in 
less than seven seconds."

insert Cars select "Mercedes-Benz", "SL-Class", 
"The 2003 SL-Class is a 2-door, 2-passenger luxury convertible, or convertible 
sports car, available in two trims, the SL500 Roadster and the SL55 
AMG Roadster."

insert Cars select "Land Rover", "Range Rover", 
"The 2003 Range Rover is a 4-door, 5-passenger luxury sport-utility, 
available in one trim only, the HSE."

insert Cars select "Honda", "Civic Coupe", 
"The 2003 Civic Coupe is a 2-door, 5-passenger family coupe, available 
in 16 trims, ranging from the DX 5-spd MT to the EX 4-spd AT w/ 
Front Side Airbags."

insert Inventory select 1, 18999, "Available"

insert Inventory select 2, 17597, "Available"

insert Inventory select 3, 92399, "Available"

insert Inventory select 4, 71200, "Available"

insert Inventory select 5, 12110, "Available"

------------------------------------------
-- Manufacturer Web Service Tables 
------------------------------------------

create table ManufacturerOrders
(
    OrderNumber int identity primary key,
    SKU     int not null,
    Make    varchar(50) not null,
    Model   varchar(50) not null,
    Price   int not null,
    Status varchar(20) not null
)
go

Create table BasePrices
(
    Make    varchar(50) not null,
    Model   varchar(50) not null,
    Price   int not null,
    primary key (Make, Model)
)
go

------------------------------------------
-- Manufacturer Web Service Tables 
------------------------------------------

create procedure AddOrder (@SKU int, @Make varchar(50), @Model varchar(50), 
@Price int, @Status varchar(20))
as
	set nocount on;
     
     	insert ManufacturerOrders
	select @SKU, @Make, @Model, @Price, @Status

	select @@identity as "ID"
go

create procedure UpdateOrder (@OrderNum int)
as
	set nocount on

	update ManufacturerOrders set Status = "Shipped" where 
	OrderNumber = @OrderNum;

 	SELECT SKU, Price FROM ManufacturerOrders
	WHERE OrderNumber = @OrderNum
go

------------------------------------------
-- Manufacturer Web Sample Data
------------------------------------------

insert BasePrices select "Volkswagen", "New Beetle", 18000
insert BasePrices select "Mini", "Cooper", 1700
insert BasePrices select "Mercedes-Benz", "SL-Class", 85000
insert BasePrices select "Honda", "Civic Coupe", 12000
insert BasePrices select "Land Rover", "Range Rover", 65000

Pages: 1, 2, 3, 4, 5, 6

Next Pagearrow