RIA With Flex & Java Using BlazeDS
Upcoming SlideShare
Loading in...5

RIA With Flex & Java Using BlazeDS



This session will provide details about how Flex applications can integrate with server side applications written Java using BlazeDS.

This session will provide details about how Flex applications can integrate with server side applications written Java using BlazeDS.



Total Views
Views on SlideShare
Embed Views



22 Embeds 314

http://www.slideshare.net 121
http://krisflexer.blogspot.com 55
http://krisflexer.blogspot.in 31
http://gowdhamanr.blogspot.com 31
http://chandpriyankara.blogspot.com 19
http://www.linkedin.com 12
http://gowdhamanr.blogspot.in 11
http://www.gowdhaman.in 7
http://gowdhamanr.blogspot.kr 4
http://krisflexer.blogspot.kr 4
https://www.linkedin.com 4
http://feeds.feedburner.com 2
file:// 2
http://krisflexer.blogspot.it 2
http://webcache.googleusercontent.com 2
http://gowdhamanr.blogspot.be 1
http://www.mefeedia.com 1
http://chandpriyankara.blogspot.ca 1
http://krisflexer.blogspot.de 1
http://translate.googleusercontent.com 1
http://gowdhamanr.blogspot.fr 1
http://static.slidesharecdn.com 1



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.


11 of 1

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    RIA With Flex & Java Using BlazeDS RIA With Flex & Java Using BlazeDS Presentation Transcript

    • 1 FLEX & JAVA USING BLAZEDS Hien Luu 2009 Silicon Valley Code Camp
    • About Me 2   Senior Software Engineer at Netflix   Many years with developing web-based applications with Java technologies   Instructor at UCSC-Extension school   RIA with Flex & Java   Spring Framework   Design Patterns
    • Flex & Java Using BlazeDS 3   Agenda   BlazeDS Overview   What & Why   BlazeDS Tour   BlazeDS Architecture   BlazeDS Services   Remoting   Messaging   Proxying   Demo
    • Flex & Java Using BlazeDS 4 Quick Survey
    • BlazeDS Overview 5   Open source project from Adobe – 12/07   Smaller cousin of Adobe LifeCycle Data Services Servlet Container BlazeDS Database Your Application
    • BlazeDS Overview 6   Alternatives Servlet Container Your Java Database application PHP/Python Granite, OpeAMF, Cinnamon,
    • AMF 7   AMF (Action Message Format)   Wire protocol   Fast, small – 10x over XML   AMF3 specification   Open Source AMF Implementation   AMFPHP   OpenAMF   rubyAMF   PyAMF
    • BlazeDS Tour 8   Download Turnkey version   Include Tomcat 6.x   BlazeDS sample applications   Flex 3 SDK   Unzip and start Tomcat and HSQL   Come with sample database – product and census data http://localhost:8400/
    • BlazeDS Architecture 9 BlazeDS Services Access to enterprise functionality RPC Service Let Flex clients communicate with each other Messaging Service asynchronously Proxy service to integrate multiple services with a Proxy Service single application
    • BlazeDS Architecture 10 Flex Client Architecture Flex Client J2EE Server BlazeDS Component BlazeDS RemoteObject HTTPService WebService HTTP Consumer Producer AMF/AMFX Channel Set M A F H P T T
    • BlazeDS Architecture 11 BlazeDS Server Architecture Message MessageBrokerServlet Broker Service Destination Adapter •  AMFEndPoint R RemotingService RemotingDestination • HTTPEndPoint O • StreamingAMFEndPoint U JavaAdapter HttpProxyService T HttpProxyDestination E HttpProxy MessageService Adapter M S MessageDestination G ActionScript Adapter Security JMS Check point Adapter
    • BlazeDS Configuration 12 Filename Description services-config.xml Top level configuration file. Contains security constraints definitions. Logging settings. Basically common configurations across services. remoting-config.xml Remoting service definitions, such as destination. proxy-config.xml Proxy service definitions for working with web services, HTTP. remoting-config.xml Messaging service for publish & subscribe
    • BlazeDS Channels & EndPoints 13   Channel set fallback mechanism Channel Endpoint Description AMFChannel AMFEndPoint Transport data over HTTP in binary AMF format. Use for Remoting. HTTPChannel HTTPEndPoint Transport data over HTTP in AMFX format. User for Remoting. StreamingAMFChannel StringAMFEndPoint Streams data in real time over HTTP in binary AMF format. User for Messaging. StreamingHTTPChannel StreamingHTTPEndPoint Streams data over HTTP in AMFX foramt.
    • BlazeDS Channels Behavior 14 Channel Description Non-polling AMF & HTTP channel Good for Remoting Piggybacking AMF & HTTP channel Enable queuing of messages along with responses to any messages from client. Polling AMF & HTTP channel Simple polling mechanism from client side to request messages Long polling AMF & HTTP channel To get pushed messages to client. Server parks the poll request until data arrives for client. Streaming channel Stream data in real-time. Available in HTTP 1.1 only. Make sure servers are capable of handling large concurrent connections
    • Remoting 15   Invoke methods of Java objects on server side   HTTP-based request/response data communication   Use AMFChannel   Advantages   AMF binary messaging protocol for exchanging data   Serialization/de-serialization are handled automatically   Natively supported by Flash Player   Gateway services make easier to expose server side services Why not use HTTPService or WebService?
    • Remoting 16   RemoteObject – client side component   destination– source of Remoting Service destination   result – when service call successfully returns   fault – when service call fails   concurrency – how to handle multiple calls   multiple – existing requests are not cancelled   single – one at a time, multiple requests generate fault   last – New request cancels any existing request
    • BlazeDS Architecture 17 BlazeDS Server Architecture Message MessageBrokerServlet Broker Service Destination Adapter •  AMFEndPoint R RemotingService RemotingDestination O U JavaAdapter T E M S G Security Check point
    • Remoting 18 <mx:Script> private function getProducts() : void { ro.getProducts(); } private function handleGetProdudctResult(event:ResultEvent) : void { } private function handleUpdateProdudctResult(event:ResultEvent) : void { } private function handleFault(event:FaultEvent) : void { Alert.show(event.fault.faultString); } </mx:Script> <mx:RemoteObject id="ro" destination="tutorial-product" showBusyCursor="true"> <mx:method name="getProducts" fault="handleFault(event)" result="handleGetProductsResult(event)" /> <mx:method name="updateProduct" fault="handleFault(event)" result="handleUpdateProductResult(event)" /> </mx:RemoteObject> <mx:Button label=“Get Products” click=“getProduct()” /> http://localhost:8400/samples/blazeds-debug/Census.html
    • Remoting 19 remoting-config.xml <destination id="tutorial-product"> <properties> <source>tutorial.ProductDAO</source> </properties> </destination> Java Class Java Class package tutorial; package tutorial; public class ProductDAO { public class Product { public List<Product> getProducts() { private int productId; // DB logic private String name; } private double price; private int qty; public void updateProduct(Product prod){ // DB logic // getters and setters for } // above member variables } }
    • Remoting 20 <mx:Script> [Bindable] private var products:ArrayCollection private function handleGetProductsResult(event:ResultEvent) : void { products = event.result as ArrayCollection; } private function handleFault(event:FaultEvent) : void { Alert.show(event.toString()); } </mx:Script> <mx:DataGrid dataProvider="{products}" width="100%" height="100%" id="dg" > <mx:columns> <mx:DataGridColumn headerText="Serial Number" dataField="productId" /> <mx:DataGridColumn headerText="Name" dataField="name" /> <mx:DataGridColumn headerText="Price" dataField="price" /> <mx:DataGridColumn headerText="Quantity" dataField="qty" /> </mx:columns> </mx:DataGrid>
    • Remoting 21   Destination scope   request – server creates an instance of Java class per request (Default)   application – one instance for entire application   session - one instance per session <destination id="tutorial-product"> <properties> <source>tutorial.ProductDAO</source> <scope>request</scope> </properties> </destination>
    • Remoting 22   Concurrency   multiple – existing requests are not canceled   Single – one at a time   last – latest request cancels any existing request <mx:RemoteObject id="ro" destination="tutorial-product" showBusyCursor="true"> <mx:method name="getProducts" fault="handleFault(event)" result="handleGetProductsResult(event)" concurrency=“multiple”/> </mx:RemoteObject>
    • Data Serialization 23 Servlet Container AS Java BlazeDS AS Java Your Application
    • Data Serialization 24   Serializing Between ActionScript & Java AS Type Java Array(dense) java.util.List Array(sparse) java.util.Map Boolean java.lang.Boolean Date java.util.Date int/uint java.lang.Integer Object java.util.Map Typed Object Typed Object [RemoteClass] XML org.w3c.dom.Document • Dense array – all numeric indexes are consecutive (no gap) • Sparse – gap between numeric indexes
    • Remoting 25   AS Serialization Rule   Public bean properties w/ getter/setter methods   Public variables   Private properties, constants are not serialized   Client side   Use [RemoteClass(alias=“ “)] to map directly to Java object   Custom Serialization package {   Iexternallizable interface [Bindable] [RemoteClass(alias="tutorial.Product")]   [Transient] public class Product { public var productId:int; public var name:String; public var price:Number; public var qty:int; } }
    • Remoting 26 java.util.ArrayList ActionScript ActionScript Array java.util.TreeSet ArrayCollection java.util.TreeSet public class ProductService { public void addProduct(java.util.Set products) {} public void addProduct(java.util.SortedSet products) {} public void addProduct(java.util.List products) {} }
    • Messaging 27   Publish-subscribe messaging   Among multiple Flex clients   Support bridging to JMS topics (only)   Server can push message to client on its own. Consumer Message Producer Messaging Consumer Service
    • Messaging 28 BlazeDS Server Architecture Message MessageBrokerServlet Broker Service Destination Adapter R MessageService MessageDestination •  Producer O • Consumer U ActionScript Adapter T E JMS M Adapter S G Custom Adapter
    • Messaging 29 messaging-config.xml <destination id=’chat’> <channels> <channel ref=‘sample-amf’> </channels> </destination> <mx:Application> <mx:Script> private function sendMessage(): void { var msg = new AsyncMesage(); msg.body = “Hello there” producer.send(msg); } private function handler(event:MessageEvent) : void { Alert.show(“Got it: “ + event.message.body; } </mx:Script> <mx:Producer id=“producer” destination=“chat”> <mx:Consumer id=“consumer” destination=“chat” message=“handler(event)”> </mx:Application>
    • Messaging 30   Message filtering   Through message header and subtopic information   Subscriber defines the filter criteria   Send to server during the subscripting step   Message filtering is done on the server <mx:Application> <mx:Script> private function sendMessage(): void { <mx:Application> var msg = new AsyncMesage(); <mx:Script> msg.headers = new Array(); … msg.headers[“user”]= “John”; </mx:script> msg.body = “Hello there”; <mx:Consumer id=“consumer” producer.send(msg); destination=“chat” } message=“handler(event)” </mx:script> selector=“user = ‘John’”> … </mx:Application> </mx:Application>
    • Messaging 31   Filtering through subtopic   Usesubtopic property of AsyncMessage   Support single-token wildcard in subtopic string <mx:Application> <mx:Script> private function sendMessage(): void { var msg = new AsyncMesage(); msg.body = “Hello there”; producer.subtopic = “chat.gossip”; producer.send(msg); <mx:Application> } <mx:Script> </mx:script> … <mx:Producer id=“producer” </mx:script> destination=“chat”> <mx:Consumer id=“consumer” … destination=“chat” </mx:Application> message=“handler(event)” subtopic=“chat.gossip”> </mx:Application>
    • Messaging 32 Enable destination to support subtopic <destination id=“chat” > <properties> <server> <allow-subtopics>true</allow-subtopics> <subtopic-separator>.</subtopic-separator> </properties> <channels> <channel ref=‘sample-amf’> </channels> </destination>
    • Messaging 33 Performance related settings Property Description throttle-inbound Control # of inbound messages per second throttle-outbound Control # of outbound messages per second message-time-to-live How long server should keep a message pending delivery before being discarded as undeliverable Additional settings for security
    • Messaging 34   Measuring message processing performance   Message size   Sever processing time   Network travel time   Message waiting time   Ensure clients & server clocks are synchronized   Enable at the channel level
    • Messaging 35 <channel-definition id="my-streaming-amf” class="mx.messaging.channels.StreamingAMFChannel"> <endpoint url="http://{server.name}:{server.port}/{context.root}/ messagebroker/streamingamf” class="flex.messaging.endpoints.StreamingAMFEndpoint"/> <properties> <record-message-times>true</record-message-times> <record-message-sizes>true</record-message-sizes> </properties> </channel-definition>
    • Messaging 36   Use MessagePerformanceUtils to access processing metrics private function messageHandler(message:IMessage):void { log.text += message.headers["user"] + ": " + message.body.chatMessage + "n"; var perfInfo:MessagePerformanceUtils = new MessagePerformanceUtils(message); Alert.show(perfInfo.prettyPrint()); }
    • Proxy 37 google.com Servlet Container BlazeDS yahoo.com Your Application amazon.com
    • Proxy 38   HTTPService   REST functionality   All HTTP method   PUT, DELETE, HEAD, POST, GET   Get response data when status code != 200   URL alias control on server side <mx:HTTPService destination="CNNFeed" useProxy="true" id="topNewService" resultFormat="e4x” result="handleTopNewResult(event)"/> <!– using default proxy destination  <mx:HTTPService useProxy="true" id="searchService" resultFormat="e4x” result="handleSearchResult(event)” />
    • Proxy 39   Proxy-config.xml   Server side configuration <destination id="DefaultHTTP"> <properties> <dynamic-url>http://*</dynamic-url> </properties> </destination> <destination id="CNNFeed"> <properties> <url>http://rss.cnn.com/rss/cnn_topstories.rss</url> </properties> </destination>
    • Resources 40   BlazeDS   http://opensource.adobe.com/wiki/display/blazeds/Overview   AMF Benchmark   http://www.jamesward.com/census   Architecting RIAs with Flex Data Management Services   http://www.adobe.com/devnet/flex/articles/architecting_rias.html