28 June 2010
This article is Part 2 of a series of articles and tutorials centered on a sales dashboard application built using Flex and the Adobe Flash Platform. The individual articles in the series are designed to stand on their own, so you can read all of them or just the ones that interest you, in whatever order you like.
This part steps you through the process of setting up the server application for the DigiPri Widget sample application. For an overview of the application, see Part 1: Overview. For a closer look at the application and its architecture, see Part 3: Understanding the dashboard application. For a more in-depth look at the code, see Part 4: Exploring the code in Flash Builder.
The DigiPri Widgets sales dashboard uses BlazeDS, the server-based Java remoting and web messaging technology, to connect the Adobe Flex front end to the back-end server application. In developing the dashboard, the focus was on developing an application that illustrated Flex and BlazeDS independent of the server-side technology used. With this in mind, the main goals in building the server application were to keep it simple, straightforward, and easy to understand so that it could be adapted to another language, application server, or database. As a result, the server-side implementation does not include any additional frameworks—such as Spring and Hibernate—that one might employ when building a production-ready or mission-critical application.
In the spirit of simplicity, the server software is based on easy-to-set-up and free software packages so you can set up and deploy the application on your own development workstation. These software packages include MySQL 5.1 RDBMS, J2SE 5.0 (Java Platform Standard Edition 5.0), and the latest production release of BlazeDS (the turnkey download contains a ready-to-use version of Tomcat, currently version 6.0.14).
To get started, you'll need to download the following software packages:
This article explains how to install and configure each software package in order to deploy and test the server application. You'll need to install the software packages in the order presented here to avoid configuration problems.
After downloading the MySQL 5.1 binary distribution for your particular operating system, follow the instructions included with the download to install the software.
Next, download and install the MySQL Administrator and MySQL Query Browser tools, which you'll need to follow the steps below. If you are familiar with the MySQL command line and prefer to work with it, you should be able to make the necessary configurations based on the following instructions.
First, you'll need to create the database schema for the CRM server application. Instead of creating a new database and each table manually, you can use the restore feature in the MySQL Administrator tool to create the schema and populate the database from the backup file, adobeCRM_backup.sql, which is included with this article's sample files.
Follow these steps to create the database:
On Mac OS X you'll see the adobeCRM database schema ready to be restored. On Windows, you have to perform an extra step to ensure the backup file is ready for the restore operation.
After restoring the database schema you need to create a user account for accessing the database used by the application.
Note: You can configure the user name and password used to access the data source later by editing the META-INF/context.xml file when the application is deployed. The default configuration uses adobeCRM for both by default.
After you have created the user, you need to grant schema privileges to the adobeCRM user account.
On Mac OS X, however, you first have to associate a host (that is, location) from which the adobeCRM user account can connect to the database. To do this, click the Add Host button located in the lower left-hand corner of the MySQL Administrator tool (see Figure 6) and select localhost in the dialog box that appears.
Note: Depending on how you choose to configure your instance of the MySQL 5.1 database server, you may see the schema name as adobecrm (note the name is lowercased). This should not have any impact on the application accessing the database, but it is worth noting the discrepancy.
You now need to select the appropriate privileges for the adobeCRM user. Since the application is a sample and not an application intended for production use, it can use a shotgun approach for granting user privileges (that is, you will be granting all privileges to the adobeCRM user.)
Note: If you were building a mission-critical or production-use application, you would most certainly want to grant only the privileges necessary for the adobeCRM user to get the data it needs. Granting all privileges to a user is not common practice and is strongly discouraged.
After you have assigned the schema privileges to the adobeCRM user, your database is ready to be used by the server application.
The BlazeDS turnkey download includes a preconfigured, fully functioning version of Apache Tomcat, an open source servlet container.
After downloading the BlazeDS turnkey distribution, extract the files to C:/blazeds on Windows or Applications/blazeds on Mac OS X. In order to run the DigiPri Widgets dashboard application, you must have access to this directory so you can start and stop Tomcat.
Once you have BlazeDS with Apache Tomcat installed, you need to download and install the MySQL Connector/J Java application archive (JAR file), which is used by the Java application to connect to the MySQL database server:
Note: The version number (5.1.12) may change; it's OK if the version you download has higher numbers.
It is important to note if you started from a standalone Tomcat installation (instead of the turnkey BlazeDS version) you would have more configuration steps to do. For example, you would have to build and deploy both a web.xml file and a context.xml file, which are responsible for defining various aspects of the Java server application. A detailed explanation of these two files is outside the scope of this article, but for the purposes of the DigiPri Widgets sample application you need not edit them; they are already preconfigured.
Now that you've configured Tomcat and the MySQL database connector is in its proper location, you need deploy the DigiPri Widgets dashboard web application itself:
If everything is set up correctly, you should see the DigiPri Widgets sales dashboard application with data being returned from the server and showing up in the various report views. If you do not see data being populated in the charts, here is a list of items to troubleshoot.
Now that you have the application up and running, you can read the DigiPri Widgets overview in Part 1 (if you haven't already done so) or proceed to Part 3, Understanding the Dashboard Application, to learn more about Flex 4 integration with the server-side implementation. Alternatively, you can skip to Part 4 to explore the client-side code.