This article explains the essentials of leveraging the Spring BlazeDS project to integrate Spring based JMS systems with Flex powered rich internet applications (RIAs). The fundamental concepts involved in the integration of Spring and Flex are explained and the role of the Spring BlazeDS project and its mechanics are illustrated. In addition to a theoretical explanation, a simple example is included to show how such a stack can be setup and used.
Spring is a popular open source enterprise Java framework for building robust and scalable applications whereas Adobe Flex is an open source framework for creating rich and engaging interfaces. Adobe BlazeDS is an open source application that allows Flex applications to connect with Java server side applications via remote procedure calls and message exchanges.
Flex applications can connect with Spring server sides, using any of the following four mechanisms:
• HTTP based requests and responses
• Web Services
• Remote procedure calls
• Message Exchanges
The first two of the above listed four options, namely HTTP based requests and responses and web services, are agnostic to the server side technology and so the integration of Flex and Spring using these techniques involves no special considerations beyond the standard support for HTTP and the web services protocol and the availability of data through these endpoints. Usually text based payload exchanges, especially XML, are common when HTTP services and web services are used. When using HTTP service or web service, BlazeDS or any such intermediary is not required, unless the security restrictions do not allow you to fetch data from the remote sources. Considering the relevance of BlazeDS is limited when using these two methods, I will not discuss the use of these methods any further in this article.
For remote procedure calls to server side objects and message exchanges, BlazeDS and similar intermediary products, play a critical role. These types of interactions and specifically message based exchanges are the focus of this article.
Prior to the existence of the Spring BlazeDS project, an Adobe supported SpringSource project, using BlazeDS to connect with Spring based Java servers involved use of a custom factory to access the Spring Beans. This is because Spring Beans and the objects instantiated by standard BlazeDS reside in separate namespaces. Not only did one need a custom factory, one could not use Spring style configuration to wire-up the BlazeDS artifacts. One had to use the BlazeDS specific xml based configurations to set it up. With Spring BlazeDS integration much of the tedious coupling between Spring and BlazeDS has been reduced to simple uniform configuration and first class support for Spring Beans as remoting destinations. Besides, Spring messaging related goodies like the JMSTemplate and the Message Driven POJOs, Spring security and the rest of its framework components become available as server side counterparts for Flex applications.
In the next few sections, I will explain how you could use Spring BlazeDS to integrate Flex and Spring based JMS systems. As I do that I will assume that you have essential knowledge of the Spring framework, Flex framework and even BlazeDS. If these assumptions don’t hold true for you, you may benefit from getting yourself up to speed with the fundamentals of Spring, Flex and BlazeDS, before you proceed further. That way you will get the most out of this article.
A few recommended resources for quick knowledge acquisition on the basics of Spring (especially Spring MVC based web application development), Flex and BlazeDS are:
- Developing a Spring Framework MVC application step-by-step
- Using Spring BlazeDS Integration 1.0
- An introduction to Spring BlazeDS Integration
- BlazeDS Developer Guide
Downloading and Setting Up the Software Stack
To get started download, install and configure all the following required pieces of software:
- Java 5+
- ActiveMQ 5.x (or any other JMS provider)
- JBoss AS 5.x (or any other application server that includes a Servlet container and can host or integrate with a JMS provider)
- Spring Framework 2.5+
- Eclipse 3.4 +
- Adobe Flex 3.x (preferably Flex Builder, which is now called Flash Builder, but the Flex SDK at a minimum. Use the Eclipse plugin version instead of the standalone version)
- Spring BlazeDS Version 1.0.0.Release (also known as Spring-flex)
The list of software to install is long but I assume you will have a few of these already setup. At minimum I assume you will have the JDK installed on your machine. If not, then that’s the first piece of software you need to get.
Once Java is installed, go ahead and download ActiveMQ, JBoss AS, Spring Framework, Eclispe, Flex Builder Eclipse Plugin and the Spring-flex distribution. Go to the URL listed against the name of the software, in the list above, to get to the specific website. In each of the cases you will easily be able to locate the link to download the latest release build for the particular software. All pieces of software in the list, except the Flex Builder Eclipse plug-in are open source. You can get a 60-day trial version of the Flex Builder Eclipse plug-in, if you choose to get familiar with the tool before you plan to buy it. The preferred versions of the tools are listed against their respective names. It’s advised that you stick to those versions to avoid any additional configuration and integration complexities.
Walking through the installation and configuration of each of these pieces of software is beyond the scope of this article but you will find ample resources online to help you out in this regard. Here, I will point to a few important installation steps and configuration details only. You will have to piece the rest of it together, although I don’t anticipate you should have much trouble doing that.
Once you have JBoss AS and ActiveMQ downloaded and installed, which on most platforms translates to expanding the archive file to a folder, you should spend a little while configuring the two to work together. A great resource that explains the fundamental nuances of JBoss AS and ActiveMQ integration in a step-by-step manner is available online at http://activemq.apache.org/integrating-apache-activemq-with-jboss.html. The explanation is for version 4.x of ActiveMQ but it applies to the versions 5.x as well. The only step missing in this document is the inclusion of the core spring framework JAR file in the activemq-ra.rar folder that resides in the “deploy” folder of the JBoss AS. If this statement is not making much sense now, follow along the step-by-step instructions to integrate JBoss AS and ActiveMQ and then add the spring framework JAR file as a step before you run your tests to confirm that the integrated setup.
The next step should be to setup the IDE, namely Eclispe and the Flex Builder plug-in. Eclipse can be installed simply by expanding the archive distribution. The Flex Builder plugin-in installs with the help of a step-by-step wizard. If you choose to use Flex Builder 3.x use Eclispe 3.4. With Flash Builder 4 Beta (the new version of Flex Builder) you could use either Eclispe 3.4 or 3.5.
Last of all, download the Spring framework and Spring Flex distributions and expand the downloaded archive file to a folder in your file system. You will need a few JAR files from these distributions to make Flex work with Spring JMS.