professional blazedsdownload.e-bookshelf.de/download/0000/5765/75/l-g... · 2013. 7. 23. · use...

30
Wrox Programmer to Programmer™ Join the discussion @ p2p.wrox.com Shashank Tiwari Creating Rich Internet Applications with Flex ® and Java ® Professional BlazeDS BlazeDS

Upload: others

Post on 25-Jan-2021

5 views

Category:

Documents


0 download

TRANSCRIPT

  • wrox.comProgrammer ForumsJoin our Programmer to Programmer forums to ask and answer programming questions about this book, join discussions on the hottest topics in the industry, and connect with fellow programmers from around the world.

    Code Downloads Take advantage of free code samples from this book, as well as code samples from hundreds of other books, all ready to use.

    Read More Find articles, ebooks, sample chapters and tables of contents for hundreds of books, and more reference resources on programming topics that matter to you.

    Wrox Programmer to Programmer™Join the discussion @ p2p.wrox.comUse BlazeDS to create exceptional rich applications with Flex and Java

    Shashank Tiwari $54.99 USA $65.99 CAN

    BlazeDS is a popular, open source web application that can successfully be deployed into a Java application server, making it an ideal option for Flex and Java integration. With this comprehensive resource, you’ll walk through the process of creating Rich Internet Applications (RIA) using BlazeDS. After a look at BlazeDS basics, the book then moves on to explain how to configure, customize, and extend BlazeDS in order to integrate with new and existing Java data sources and applications with Flex-based RIA.

    • Explains how to install BlazeDS from source as well as its compiled distributions

    • Demonstrates ways to make user interfaces engaging and effective

    • Introduces techniques for intercepting for control and management

    • Features tips for configuring a remoting service and a destination

    • Reviews remoting communication flow and remoting related classes, components, and modules

    • Includes coverage of testing and debugging Flex and BlazeDS applications

    • Shows how to extend BlazeDS with custom adapters and factories to connect to enterprise Java resources.

    • Discusses methods for leveraging JPA and Hibernate with Flex

    • Delves into the topic of communicating real-time via messages

    Shashank Tiwari is a technology entrepreneur, speaker, author, and innovator. He is currently a managing partner & CTO at Treasury of Ideas (http://www.treasuryofideas.com), a technology-driven innovation and value optimization company.

    Wrox Professional guides are planned and written by working programmers to meet the real-world needs of programmers, developers, and IT professionals. Focused and relevant, they address the issues technology professionals face every day. They provide examples, practical solutions, and expert education in new technologies, all designed to help programmers do a better job.

    Programming Languages / Java

    Creating Rich Internet Applications with Flex® and Java®

    Professional

    BlazeDSBlazeD

    S

    Tiwari

    Professional

  • Get more out of WROX.com

    Programmer to Programmer™

    InteractTake an active role online by participating in our P2P forums

    Wrox Online LibraryHundreds of our books are available online through Books24x7.com

    Wrox Blox Download short informational pieces and code to keep you up to date and out of trouble!

    Chapters on DemandPurchase individual book chapters in pdf format

    Join the CommunitySign up for our free monthly newsletter at newsletter.wrox.com

    BrowseReady for more Wrox? We have books and e-books available on .NET, SQL Server, Java, XML, Visual Basic, C#/ C++, and much more!

    Contact Us. We always like to get feedback from our readers. Have a book idea? Need community support? Let us know by e-mailing [email protected]

    Related Wrox Books

    Adobe AIR: Create - Modify - ReuseISBN: 978-0-470-18207-9This book walks you through eleven fully implemented AIR applications with source code that you can use as they currently exist or customize. Each project begins with a discussion of architecture and design, followed by code implementation. You’ll get hands-on knowledge of AIR application design and development that you can then use to build dynamic RIAs.

    Beginning Adobe AIR: Building Applications for the Adobe Integrated RuntimeISBN: 978-0-470-22904-0This guide is a perfect mix of tutorials and hands-on coding, and provides the resources you need to build AIR applications quickly. Adobe expert Rich Tretola discusses the different programming languages and tools you can use for development and presents multiple methods for storing data, including within the file system and embedded database as well as storage on remote servers.

    Professional Adobe Flex 3ISBN: 978-0-470-22364-2Understand the potential of the Flex 3 platform through practical examples and hands-on advice on topics like desktop deployment, developing applications in MXML, creating custom flex components, charting, targeting AIR, and data interconnectivity.

    Professional CairngormISBN: 978-0-470-49726-5This book provides a much-needed reference on Cairngorm, the oldest and most widely used Flex framework, by showing you how Cairngorm facilitates team development, encourages best practices for building Flex-based RIAs, and works well with medium- to large-scale projects in which code needs to be separated and organized.

  • Professional BlazeDS

    Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiIntroduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxiiiChapter 1: Flex for Java Developers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Chapter 2: Introducing BlazeDS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41Chapter 3: Using BlazeDS as a Server-Side Proxy . . . . . . . . . . . . . . . . . . . . . . . . . . . 65Chapter 4: Remoting between Flex and POJOs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83Chapter 5: Accessing Spring Beans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113Chapter 6: Communicating Real-Time via Messages . . . . . . . . . . . . . . . . . . . . . . 137Chapter 7: Leveraging JPA and Hibernate with Flex . . . . . . . . . . . . . . . . . . . . . . . . 169Chapter 8: Testing and Debugging Flex and BlazeDS Applications . . . . . . . . . 215Chapter 9: Extending BlazeDS with Custom Adapters . . . . . . . . . . . . . . . . . . . . . 253Chapter 10: Making BlazeDS Applications Scalable . . . . . . . . . . . . . . . . . . . . . . . 271Chapter 11: CRUD Applications and More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293Appendix A: Introducing Flex 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337

  • Professional

    BlazeDS

  • Professional

    BlazeDS

    Creating Rich Internet Applications with Flex® and Java®

    Shashank Tiwari

    Wiley Publishing, Inc.

  • Professional BlazeDS: Creating Rich Internet Applicationswith Flex® and Java®Published byWiley Publishing, Inc.10475 Crosspoint BoulevardIndianapolis, IN 46256www.wiley.com

    Copyright © 2009 by Wiley Publishing, Inc., Indianapolis, Indiana

    Published simultaneously in Canada

    ISBN: 978-0-470-46489-2

    Manufactured in the United States of America

    10 9 8 7 6 5 4 3 2 1

    No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by anymeans, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, orauthorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 RosewoodDrive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should beaddressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201)748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.

    Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties withrespect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, includingwithout limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales orpromotional materials. The advice and strategies contained herein may not be suitable for every situation. This workis sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professionalservices. If professional assistance is required, the services of a competent professional person should be sought.Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization orWeb site is referred to in this work as a citation and/or a potential source of further information does not mean thatthe author or the publisher endorses the information the organization or Web site may provide or recommendationsit may make. Further, readers should be aware that Internet Web sites listed in this work may have changed ordisappeared between when this work was written and when it is read.

    For general information on our other products and services please contact our Customer Care Department within theUnited States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

    Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not beavailable in electronic books.

    Library of Congress Control Number: 2009932709

    Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dressare trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States andother countries, and may not be used without written permission. Flex is a registered trademark of Adobe SystemsIncorporated. Java is a registered trademark of Sun Microsystems, Inc. All other trademarks are the property of theirrespective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.

    http://www.wiley.comhttp://www.wiley.com/go/permissions

  • My efforts on this book are dedicated to my wife Caren and sons Ayaan and Ezra. Thanks for alwaysencouraging and supporting me in my endeavors, like writing this book or starting the new venture.

    Without your support and love I could have never completed this book.

  • About the Author

    Shashank Tiwari is a technology entrepreneur, speaker, author, and inno-vator. He is currently a Managing Partner & CTO at Treasury of Ideas(http://www.treasuryofideas.com), a technology-driven innovation andvalue optimization company. As an experienced software developer andarchitect, he is adept in a multitude of technologies. He is an internationallyrecognized speaker, author, and mentor. As an expert group member on anumber of JCP (Java Community Process) specifications, he has been activelyparticipating in shaping the future of Java. He is also an Adobe Flex Cham-pion and a common voice in the RIA community. Currently, he passionatelybuilds rich, high-performance scalable applications and advises many onRIA and SOA adoption. His clients range from large financial service corpo-rations to brilliant startups, for whom he helps translate cutting edge ideasinto reality. He is also actively engaged in training and mentoring developers

    and architects in leading edge technology. He is the author of a number of books and articles, includingAdvanced Flex 3 (Apress, 2008). He lives with his wife and two sons in New York. More information abouthim can be accessed at his website: http://www.shanky.org.

    http://www.shanky.org

  • CreditsAcquisitions EditorScott Meyers

    Project EditorTom Dinse

    Technical EditorYakov Fain

    Production EditorEric Charbonneau

    Copy EditorFoxxe Editorial Services

    Editorial DirectorRobyn B. Siesky

    Editorial ManagerMary Beth Wakefield

    Production ManagerTim Tate

    Vice President and ExecutiveGroup PublisherRichard Swadley

    Vice President and ExecutivePublisherBarry Pruett

    Associate PublisherJim Minatel

    Project Coordinator, CoverLynsey Stanford

    ProofreaderJen Larsen, Word One

    IndexerJohnna VanHoose Dinse

    Cover Photo©Thinkstock/Punchstock

  • Acknowledgments

    This book represents the efforts of many people and I sincerely thank them for their contribution.

    Many thanks to the entire team at Wrox/Wiley. You made this book possible! Scott Meyers took thisbook from a proposal to a real project. Tom Dinse diligently and patiently reviewed the manuscript andmanaged the schedule. Many others worked seamlessly behind the scenes to make things happen.

    Thanks much to Yakov Fain for meticulously reviewing and validating the manuscript for its technicalcorrectness. He deserves special praise for his attention to detail and valuable insight.

    I sincerely appreciate all of you (everyone at Wiley and Yakov) for working extra hard against tighttimelines to make things happen on schedule.

    Special thanks to the folks at Adobe. Thanks to Jeff Vroom for his early encouragement and support.Thanks to James Ward for the encouraging words he wrote in the forward to this book. Many thanks toJeremy Grelle, the lead of the Spring BlazeDS project at SpringSource, for his help.

    Thanks to Jerry Bezdikian for my About the Author photo.

    Above all, thanks to my friends and family for their assistance and encouragement. My wife, Caren,and sons, Ayaan and Ezra, were extremely loving and accommodating while I took out time on manyevenings, early mornings, and nights in the last many months to finish the book. They were very involvedin the project. My five year old, Ayaan, continuously knew how I was progressing through the book,often encouraging me to finish a chapter sooner than I would otherwise have. My three year old, Ezra,was quieter than his normal naughty self when I was working hard typing away on my keyboard. Mywife, Caren, planned the last many weekdays and weekends solely around my writing schedule. She fedme with delicious food as she always does and helped me stay focused all along, even when the tasklooked too difficult. Without their affection, I would have never been able to write this book.

    Thanks also to my parents (Mandakini and Suresh), my in-laws (Cissy and Frank), and all other near anddear ones for their continuing support and encouragement.

    My sincere thanks and gratitude to all of you who contributed towards this book.

  • Contents

    Foreword xxiIntroduction xxiii

    Chapter 1: Flex for Java Developers 1

    Introducing Flex through Its Controls and Containers 1Tip to Remember 3

    Getting to Know the Controls 5Laying Out the Controls 19

    Leveraging Services to Access External Data 27Using Simple HTTP and REST Style Invocations 28Communicating via Web Services 30Making Remote Procedure Calls 32

    Making User Interfaces Engaging and Effective 33Exploring Effects 33Validating User Input 34Customizing the Look and Feel 35

    Extending Flex 36Creating Custom Components 36Creating and Propagating Custom Events 38

    Summary 39

    Chapter 2: Introducing BlazeDS 41

    An Overview of BlazeDS 41Viewing Integration from 30,000 feet 43Viewing Integration from 10,000 feet 45Viewing It Closely from 1,000 Feet 45

    Getting and Installing BlazeDS 47Downloading BlazeDS 47Installing the Compiled Distributions 49Compiling from Source 53

    Surveying the Configuration Options 54First Look at services-config.xml 55Remoting, Proxy and Messaging Configuration 57

    Yet Another Hello to the World 58Summary 64

  • Contents

    Chapter 3: Using BlazeDS as a Server-Side Proxy 65

    HTTP Service Proxy 66An HTTP Proxy Service Example 69Advanced Configuration Options of an HTTP Proxy Adapter 70Intercepting for Control and Management 73

    Web Service Proxy 76Configuring a Web Service Proxy 79

    Summary 80

    Chapter 4: Remoting between Flex and POJOs 83

    Essentials of Remoting 84Remoting Communication Flow 84Remoting-Related Classes, Components, and Modules 86

    Configuring a Remoting Service and a Destination 89Securing Destinations 91Intercepting and Logging Calls to a Remoting Service 94Talking AMFX 96Using HTTPS 96

    Diving into Serialization — AS3 to Java and Back 98Running through a Complete Example 102

    Java-Based Data Service 104Client-Side Flex Code 107

    Value Additions for Simple Remoting 108Custom Security Implementation 108An Interceptor for the JavaAdapter 110

    Summary 111

    Chapter 5: Accessing Spring Beans 113

    Basic Bootstrapping 113Using BlazeDS MessageBroker with the Spring DispatcherServlet 114Serving Flex and Non-Flex Clients 117

    Remoting to Spring Beans 119Message Service Integration 124

    Native BlazeDS AMF Messaging 124JMS Messaging Using Spring-Specific JMS Components 126Using the Special Integration Adapter 129

    Leveraging Spring Security 131Securing Remote Spring Bean Access 133

    Using Custom Adapters 134Summary 135

    xvi

  • Contents

    Chapter 6: Communicating Real-Time via Messages 137

    Data Push Essentials 138Data Push Usage Scenarios 138The Alternatives 138

    Messaging Domains 142Point-to-Point 143Publish-Subscribe 143

    JMS 145JMS Architecture 145JMS Programming Model and the API 146

    A BlazeDS-Powered Messaging Application 148The Application Use Case 148The First Few Steps 149Sprucing Up the Client Code 153The Simulated Feed Program 156

    The Chat Window 159The Simple Chat Application 160

    The Adapters at Work 163The ActionScriptAdapter 163The JMSAdapter 164

    Advanced Extensions to BlazeDS Data Push 164Comet Inclusion with BlazeDS in Jetty 7 165

    Summary 167

    Chapter 7: Leveraging JPA and Hibernate with Flex 169

    Object Relational Mismatch 170Coarse-Grained or Fine-Grained 170The Cases of Inheritance and Polymorphism 171Entity Relationships 172What Defines Identity? 174

    Introducing JPA 174Primary Key 175Entity Relationships 176Interacting with a Persistence Context 178Hibernate EntityManager 3.4.0.GA Distribution 179Set Up the Database 180Create an Eclipse JPA project 180Program the Entities and specify metadata 185

    Bare Essentials of Hibernate 188A Rudimentary Approach to Integration with JPA and Hibernate 191

    Setting Up 191Programming the Flex and JPA/Hibernate Application 195

    xvii

  • Contents

    Flex and Hibernate Integration Expectations 199BlazeDS Adapter for JPA and Hibernate 201Aspect-Oriented Programming (AOP) 203JPA and Hibernate Adapters for BlazeDS 204

    dpHibernate 204Gilead 208

    Managed Entities for Flex Applications 211Summary 212

    Chapter 8: Testing and Debugging Flex and BlazeDS Applications 215

    Testing 215FlexUnit 216JUnit 224Functional and Interface Testing 227

    Debugging 243Logging 243Profiling 246

    Summary 251

    Chapter 9: Extending BlazeDS with Custom Adapters 253

    Contextual Overview 253The API 255A Sample Custom Adapter 259Custom Factories 264Extending the Messaging Adapter 268Advanced Strategies for Custom Adapter Creation 269Summary 270

    Chapter 10: Making BlazeDS Applications Scalable 271

    Clustering 271Channel Failover 272Clustering Powered by JGroups 274

    Data Compression 276Data Format Optimization 278Robust Connection 280Service Orientation 282

    Concurrent Contracts 282Cross-Domain Utility Layer 283Functional Decomposition 283

    xviii

  • Contents

    Rules Centralization 283State Repository 283

    Caching 283Signed Framework RSL 285

    Resource Pooling 287JDBC Connection Pooling 287JMS Resource Pooling 289Bind Messaging to the Beans Using Camel 290Using Spring’s Support for Message Listener Containers 291

    Workload Distribution 291Summary 292

    Chapter 11: CRUD Applications and More 293

    CRUD with Flash Builder 4 294CRUD with RESTful Endpoints 294Generating Client Code for WebService Consumption 300Generating CRUD with Remoting Service Destinations 303

    Generating AS3 Model Objects 312Using Gas3 312Auto-Populating AS3 Model Objects with XML Based on an XSD 320

    Summary 323

    Appendix A: Introducing Flex 4 325

    What Is Flex 4? 325What’s New? 326Flex 4 and Before 327

    Leveraging the New Framework 331Development Workflows 331Flex 4 Says Hello 332

    Summary 335

    Index 337

    xix

  • Foreword

    As with many interactions between developers these days, I first met Shashank Tiwari online via hisblog. He was writing thoughtfully about Java and Flex back in the days when this was mostly unchartedterritory where only a handful of brave developers had ventured. Through those interactions we beganmaking plans to lead more Java developers to the blissful world of Java and Flex.

    Having been a professional software developer for more than ten years, I’ve met developers from awide variety of backgrounds, including hackers, scientists, teachers, plumbers, and athletes. There isno better way to know what a developer is like than to write code and articles with them. Over thepast few years Shashank and I have co-authored a number of articles and code samples together. Fromthese experiences, I know that Shashank is a top notch Java developer and a Flex master. What makesShashank’s books stand out, however, is that he is not only a superb developer but also an excellentteacher.

    I was very excited when I heard that Shashank was working on a new book focused on integrating Javaand Flex through BlazeDS. So many Java developers I interact with want to build better software butare reluctant to learn a new technology stack. Flex and BlazeDS provide a great path for Java developersto build better software that users love to use. The wealth of out-of-the-box and community-built Flexcomponents enables developers to rapidly assemble great applications. But there is a learning curvefor the typical Java developer who must understand and navigate the intricacies of a thick-client UIframework, data marshalling mechanisms, and a new tool chain. Shashank makes that learning curvesmooth and fun.

    This book provides much needed practical knowledge for assembling production applications usingJava and Flex. The extensions Shashank has built to BlazeDS, his examples of real-world Spring inte-gration, and his detailed explanations regarding Hibernate data access provide readers with end-to-endinstructions for building great UIs on Java back-ends.

    I’ve had the great privilege of working with and learning from Shashank. He has helped me to be a betterdeveloper and to gain a more complete understanding of new technologies. I’m sure that ProfessionalBlazeDS will do the same for you.

    James Wardwww.jamesward.com

    Co-author of First Steps in Flex with Bruce Eckelwww.firststepsinflex.com

  • I n t roduc t ion

    Java easily ranks among the most popular enterprise computing platforms. Adobe Flex is a leading RichInternet Application (RIA) development framework. The combination of Java and Flex is one of the mostcompelling propositions for enterprises to create rich and engaging applications to enhance productivityand increase customer satisfaction.

    An effective integration of Java and Flex implies that you can leverage robust scalable Java server sideapplications in conjunction with the superior rendering capabilities of the Flash player. It also meansthat your investments in Java server back-ends can be reused and leveraged in your new generationapplications.

    Looking at the integration from the other side, an effective combination of Java and Flex means that yourclunky old web 1.0 interfaces and old-style interaction models can be replaced with their more effectivenew-generation counterparts.

    In addition to all the benefits listed above, an effective plumbing between Java and Flex promises Flex’sreach to all enterprise resources, including databases, enterprise resource planning systems, authentica-tion systems and organization-wide messaging systems.

    Java and Flex integration is achieved with the help of a number of products and tools, including LifeCycleData Services (LCDS) and BlazeDS from Adobe. LCDS is a commercial product and BlazeDS is an opensource alternative to LCDS.

    This book is all about combining Java and Flex. The book covers the integration story with BlazeDS asthe protagonist. It explores all aspects of BlazeDS and explains its extension points that allow it to bestretched beyond its off-the-shelf capabilities.

    This is one of the first few books that addresses the topic of Java and Flex integration using BlazeDS.From the very first draft proposal I have seen a lot of excitement around this topic and this book (at leastamong all involved in its creation). As I was writing this book over the last few months, BlazeDS andFlex saw a lot of rapid changes and inclusion of newer features and capabilities. It was also the timeSpring BlazeDS emerged as a SpringSource and Adobe supported initiatives to integrate Spring and Flexusing BlazeDS. I have made every attempt to keep the content up-to-date and relevant. However, someof the pieces of software are in beta phase and will continue to evolve as we work hard to make this bookavailable in your hands. Even though this makes the book susceptible to being outdated on a few rareinstances, I am confident the content remains useful and relevant through the next versions of the Flexframework, Java, and BlazeDS.

    The book at all times attempts to balance between theory and practice, giving you enough visibility intothe underlying concepts and providing you with the best practices and practical advice that you canapply at your workplace right away.

  • Introduction

    Who This Book Is ForThis book is best suited for those developers and architects who leverage Java and Flex to create richinternet applications. Such developers are likely to come from either the Java or the Flex backgrounds, orfrom a background that includes neither of the two technologies.

    For those who are Java experts the book teaches the details of BlazeDS and its applicability in using it toplumb Java and Flex applications together. I understand that some such experts may not have sufficientknowledge of the Flex framework. Therefore I explicitly introduce Flex 3 in Chapter 1 and provide a peekinto the upcoming Flex 4 version in the appendix.

    For those who are Flex developers and architects the book provides explanations and examples of howthey can effectively include BlazeDS in their application stack. I assume much of the conceptual contentwould be accessible to such developers. It’s possible though that some advanced topics on persistence,Spring integration and custom extensions could be difficult for a developer who has little or no knowl-edge of Java. This book does not attempt to teach Java fundamentals, which is outside its scope. Tools forlearning the essentials of Java are widely available and I encourage you take advantage of them to getthe most out of this book.

    I advise that you read the book from start to finish for an initial understanding and then return to specificchapters to apply detailed and specific recommendations.

    What This Book CoversThis book covers Java version 5 and above, Flex version 3.x, BlazeDS version 3.x and 4 beta and FlashBuilder version 3.x and 4 beta. The book also introduces Flex 4 beta minimally. The content in this bookshould be relevant through Flex 4, BlazeDS 4 and Flash Builder 4.

    Version 1.0 of Spring BlazeDS and FlexMonkey, JMS 1.1 and Hibernate 3.3.2.GA are covered.

    How This Book Is StructuredThis book consists of 11 chapters and an appendix. The 11 chapters gradually start from the fundamentalsand progress to cover increasingly complex topics. The first chapter introduces the Flex 3 framework. Theappendix minimally introduces Flex 4 beta. The rest of the chapters cover the different aspects of BlazeDS,its existing features, and its custom extensions. A majority of the chapters illustrate the proxy, remoting,and messaging capabilities of BlazeDS. For a holistic treatment, chapters on testing and scalability arealso included.

    As mentioned previously, I recommend that you read the book sequentially from the first to the lastchapter. That way your learning curve will be smooth and gradual.

    Chapter by chapter, this book covers:

    ❑ Flex for Java Developers (Chapter 1) — A brief primer to Flex for Java developers. The chapterteaches Flex fundamentals, providing a few examples in context.

    ❑ Introducing BlazeDS (Chapter 2) — This chapter gently introduces BlazeDS. It explains theBlazeDS architecture, its core features, configuration files and the deployment infrastructure.In addition, the chapter explains the installation processes and peeks into the underlying core.

    xxiv

  • Introduction

    ❑ Using BlazeDS as a Server-side Proxy (Chapter 3) — Flex applications can access data andweb services from remote destinations if the remote destinations define an appropriate securitydefinition, in a file called crossdomain.xml. The Flash player debars access from sources thatlack such a security definition. However, BlazeDS provides server side proxy capabilities toaccess these sources. The focus here is on the role of BlazeDS as a server-side proxy.

    ❑ Remoting between Flex and POJOs (Chapter 4) — This chapter illustrates the details of remoteprocedure calls between Flex and Java objects and explains how objects can be streamed betweenthe two using a binary protocol called AMF (Action Message Format).

    ❑ Accessing Spring Beans (Chapter 5) — SpringSource, the makers of the Spring Framework, andAdobe, makers of Flex, combined efforts to create Spring BlazeDS that helps integrate Spring andFlex applications using BlazeDS effectively. This chapter covers the features of this new integra-tion project.

    ❑ Communicating Real-time via Messages (Chapter 6) — BlazeDS supports real-time messagingand data push. In this chapter I start with the essentials of messaging between Flex and Java andhighlight the important aspects like AMF long polling and the JMS adapter.

    ❑ Leveraging JPA and Hibernate with Flex (Chapter 7) — Hibernate is the most popular Java per-sistence framework and JPA is the standard that defines Java EE persistence architecture. Boththe product (Hibernate) and the associated specification (JPA) bring benefits of Object relationalmapping to the world of Java. This chapter explains how the same features can be extended toFlex applications using BlazeDS.

    ❑ Testing and Debugging Flex and BlazeDS Applications (Chapter 8) — This chapter explainsthe nuts and bolts of logging, testing, and debugging Flex and BlazeDS applications.

    ❑ Extending BlazeDS with Custom Adapters (Chapter 9) — BlazeDS is a great product off-the-shelf, but the most valuable aspect of its design is that it can be extended easily to adapt to variedserver side resources. This chapter will explain the available API and the approach to creating,deploying and using custom adapters.

    ❑ Making BlazeDS Applications Scalable (Chapter 10) — This chapter explains how you couldscale BlazeDS using the concepts that involve clustering, data compression, data format opti-mization, robust connection, service orientation, caching, resource pooling, and workload distri-bution.

    ❑ CRUD Applications and More (Chapter 11) — This chapter illustrates CRUD application gener-ation using Flash Builder 4 beta. It also illustrates the use of Gas3 for automatic translation fromJava to AS3 and auto-population of AS3 objects based on XML content that support XML schemadefinitions.

    ❑ Introducing Flex 4 (Appendix) — The appendix introduces the fundamentals of Flex 4, the nextversion of the Flex framework. Currently, Flex 4 is in beta. It will be released only in early 2010.The appendix provides a sneak peek into what’s brewing.

    What You Need to Use This BookThis book requires that you have the following software installed on your machine:

    ❑ JRE version 5 or above

    ❑ Flex SDK version 3

    ❑ BlazeDS version 3 or above

    xxv

  • Introduction

    ❑ Flex Builder version 3 (not a necessity but convenient)

    ❑ Flash Builder 4 beta (especially to follow along the directions in Chapter 11)

    ❑ JBoss AS or Tomcat (when using Tomcat, please install an external JMS provider like ActiveMQ)

    In addition, for specific chapters, you will need the following:

    ❑ Spring BlazeDS

    ❑ FlexMonkey

    ❑ JMS provider (like ActiveMQ)

    ❑ Hibernate

    ❑ JGroups

    ❑ Ruby and FunFX

    ConventionsTo help you get the most from the text and keep track of what’s happening, we’ve used a number ofconventions throughout the book.

    Boxes like this one hold important, not-to-be forgotten information that is directlyrelevant to the surrounding text.

    Notes, tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.

    As for styles in the text:

    ❑ We highlight new terms and important words when we introduce them.

    ❑ We show keyboard strokes like this: Ctrl+A.❑ We show file names, URLs, and code within the text like so: persistence.properties.

    ❑ We present code in two different ways:

    We use a monofont type with no highlighting for most code examples.We use gray highlighting to emphasize code that is of particular importance inthe present context.

    Source CodeAs you work through the examples in this book, you may choose either to type in all the code manually orto use the source code files that accompany the book. All of the source code used in this book is availablefor download at www.wrox.com. Once at the site, simply locate the book’s title (either by using the Searchbox or by using one of the title lists) and click the Download Code link on the book’s detail page to obtainall the source code for the book.

    xxvi

  • Introduction

    Because many books have similar titles, you may find it easiest to search by ISBN; this book’s ISBN is978-0-470-46489-2.

    Once you download the code, just decompress it with your favorite compression tool. Alternately, youcan go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to seethe code available for this book and all other Wrox books.

    ErrataWe make every effort to ensure that there are no errors in the text or in the code. However, no one isperfect, and mistakes do occur. If you find an error in one of our books, like a spelling mistake or faultypiece of code, we would be very grateful for your feedback. By sending in errata you may save anotherreader hours of frustration and at the same time you will be helping us provide even higher qualityinformation.

    To find the errata page for this book, go to www.wrox.com and locate the title using the Search box or oneof the title lists. Then, on the book details page, click the Book Errata link. On this page you can view allerrata that has been submitted for this book and posted by Wrox editors. A complete book list includinglinks to each book’s errata is also available at www.wrox.com/misc-pages/booklist.shtml.

    If you don’t spot ‘‘your’’ error on the Book Errata page, go to www.wrox.com/contact/techsupport.shtml and complete the form there to send us the error you have found. We’ll check the information and,if appropriate, post a message to the book’s errata page and fix the problem in subsequent editions ofthe book.

    p2p.wrox.comFor author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a Web-basedsystem for you to post messages relating to Wrox books and related technologies and interact with otherreaders and technology users. The forums offer a subscription feature to e-mail you topics of interest ofyour choosing when new posts are made to the forums. Wrox authors, editors, other industry experts,and your fellow readers are present on these forums.

    At http://p2p.wrox.com you will find a number of different forums that will help you not only as youread this book, but also as you develop your own applications. To join the forums, just follow these steps:

    1. Go to p2p.wrox.com and click the Register link.2. Read the terms of use and click Agree.3. Complete the required information to join as well as any optional information you wish to

    provide and click Submit.

    4. You will receive an e-mail with information describing how to verify your account and com-plete the joining process.

    You can read messages in the forums without joining P2P but in order to post your own messages, youmust join.

    xxvii

  • Introduction

    Once you join, you can post new messages and respond to messages other users post. You can readmessages at any time on the Web. If you would like to have new messages from a particular forume-mailed to you, click the Subscribe to this Forum icon by the forum name in the forum listing.

    For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers toquestions about how the forum software works as well as many common questions specific to P2P andWrox books. To read the FAQs, click the FAQ link on any P2P page.

    xxviii