201
Chapter 7
Integrating Flex with Java Using Services
by Shashank Tiwari
Flex and Java are complementary. Flex is a leading technology for building rich, engaging interfaces, while
Java is an established player on the server side. Using them together, you can build enterprise-grade
applications that are rich, robust, and scalable. Java’s ability to serve as a platform for a variety of
languages and to integrate with multiple tools and technologies lets Flex make remote calls to multiple
languages and to reach out to diverse enterprise systems.
Adobe realized the potential of this synergy and created its data services to support Java. Data services
provide a ready-made, robust infrastructure for Flex and Java integration. The concepts behind data
services and its API are explained in Chapter 8. Although very beneficial, it isn’t necessary to use data
services for effective Flex and Java integration. In fact, in some cases, integration is better without it.
This chapter covers those contexts where Flex and Java are loosely coupled without any data services. It
illustrates situations where service orientation and server-agnostic user interfaces are very important and
form the fundamental tenet of the underlying application architecture.
The integration of Flex and Java can be approached in several ways, depending on the use case and the
degree of association. Let’s take a look at this in terms of a couple of 22 matrices. Figure 7-1 analyzes
the integration possibilities using two scales: strong typing requirements and data update frequency. It
indicates that if you care about the exact data types and how they are translated between a Java server
and a Flex client, and you need frequent data updates, you have a case for tight integration using remote
procedure calls and messaging. It also recommends that if the situation is the exact opposite (little need
for strong typing and only sporadic need to access or refresh data), you should use simple HTTP-based
data interchange. If you are confused and wondering why data typing is important at all, consider the
difference between treating a Person object as an object with possibly name, id, and address as
attributes and isPolite as a behavior-introspecting method, versus treating it as a generic collection of
name-value pairs.
CHAPTER 7
202
Figure 7-1. Flex and Java integration analyzed via a 22 matrix that measures situations on strong typing
requirements and data update frequency scales.
Figure 7-2 analyzes the same situation using a different set of scales—payload size and server-side
refactoring complexity. Refactoring legacy server-side applications to work with rich clients can be a fairly
complicated undertaking. In such cases, it’s worthwhile to simply wrap the legacy functionality with a
service layer and expose HTTP endpoints to access data. In other instances, the complexity isn’t great
and refactoring the server-side to work with remoting and messaging destinations is possibly a better
choice. When starting from scratch, you always have the choice to design and architect a rich client’s
server-side counterparts with data services in mind. In most cases of large payload size, tighter coupling
helps—unless, of course, the effort in refactoring the server-side is so great that the costs involved
outweigh any benefits from the tighter coupling.

Get AdvancED Flex 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.