44
©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Advanced Communications between Java and Flex Michaël Chaize | Flash Platform Evangelist

Jax2010 adobe lcds

Embed Size (px)

DESCRIPTION

Slides presented at JAX2010 in Germany. Technical session on advanced communications between Java and Flex.

Citation preview

Page 1: Jax2010 adobe lcds

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con�dential.

Advanced Communications between Java and FlexMichaël Chaize | Flash Platform Evangelist

Page 2: Jax2010 adobe lcds

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con�dential.

Feel free to contact me

2

Michaël ChaizeFlash Platform Evangelist

My blog: www.RIAgora.com

@mchaize

Page 3: Jax2010 adobe lcds

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con�dential.

Flash Platform - A complete system for web innovation

Page 4: Jax2010 adobe lcds

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con�dential.

Flash Platform - A complete system for web innovation

Page 5: Jax2010 adobe lcds

97%Flash Player 10 (March 2010)

Page 6: Jax2010 adobe lcds

ADOBE FLEX 4

Page 7: Jax2010 adobe lcds

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con�dential.

What is Flex and how it works

Flash Builder IDE

Flex SDK

Flex Class Library

MXML ActionScript

Compile

SOAP HTTP/S AMF/S RTMP/S

Web Server

Existing Applications & Infrastructure

J2EE Application Server

LC Data ServicesXML/HTTP

REST

SOAP Web Services

Browser

Flash Player

Page 8: Jax2010 adobe lcds

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con�dential.

RIA and technical challenges

• Be�er response time• Light bandwidth• Less load on the server side• Less tests on the client side

Web 1.0 application Rich Internet Application

<page>

<page>

<page>

<page>

<page>

<page>

<page><application>

<data>

Page 9: Jax2010 adobe lcds

ADOBE FLEX 4

HTTP Request

Page 10: Jax2010 adobe lcds

2008 Adobe Systems Incorporated. All Rights Reserved.

Flex/JSP architecture

UI LAYER

SERVERPRESENTATION/SERVICES/DAOLAYER

DATABASE/STORAGE LAYER

catalog.jsp

Java servlet container (tomcat, WAS…)

JDBC

Web browser

JAVA classes/services

Webapp (WAR)

ProductService.java public getProducts()

WSDL

XML on HTTP(s)

Page 11: Jax2010 adobe lcds

© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con�dential.

! Same with PHP, Ruby, Perl, ASP...

! Returns XML, text, tabulated text, JSON...

! Use send() to launch the request

! Result and Fault events

! New data-services wizard in Flash Builder 4 to generate a STUB on the client side

Flex and <HTTPRequest>

Page 12: Jax2010 adobe lcds

ADOBE FLEX 4

Web services

Page 13: Jax2010 adobe lcds

© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con�dential.

! Web Services Description Language 1.1 (WSDL 1.1) document

! �e Flex web service API generally supports Simple Object Access Protocol (SOAP) 1.1, XML Schema 1.0 (versions 1999, 2000, and 2001), and WSDL 1.1 RPC-encoded, RPC-literal, and document-literal (bare and wrapped style parameters).

! Flex supports web service requests and results that are forma�ed as SOAP messages

Flex and <Webservice>

Page 14: Jax2010 adobe lcds

© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con�dential.

! By default, applications that are loaded from a di�erent web domain are untrusted, and applications that are loaded from the same web domain are trusted. You can, however, make a cross-domain application trusted.

! To load a cross-domain application and access its data, the target server that hosts the remote sub-application must have a policy �le called crossdomain.xml on it.

! NB: Using BLAZE DS as a proxy can help you to reach cross-domain services without the need of this XML �le.

crossdomain.xml

Page 15: Jax2010 adobe lcds

© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con�dential.

Two approaches for Client/Server development

Loosely coupled: Document Based Protocols (XML, SOAP, …)

! Language neutral, easy to debug + document

! Parsing and formatting code is harder to build and maintain as complexity grows

! Runtime overhead also grows with complexity

! Easier to develop server and client independently

Tightly coupled: Object Model Based Protocols (RMI, AMF, …)

! Adding languages is hard

! Faster for client and server and less bandwidth required

! Easier to share code or use code gen for centralizing the domain model

! Scales to much more complicated application models e�ciently

! Less design, code and fewer dependencies on the “over the wire” format

! Keeps client and server implementation in sync - if you can refresh both at the same time (easy with RIAs)

Page 16: Jax2010 adobe lcds

AMFPublished in December 2007

Page 17: Jax2010 adobe lcds

!Copyright 2008 Adobe Systems Incorporated. All rights reserved.

REMOTING AMF

XML vs AMF

Page 18: Jax2010 adobe lcds

ADOBE FLEX 4

Remoting AMF

Page 19: Jax2010 adobe lcds

© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con�dential.

LiveCycle Data Services ES

LiveCycle Data Services is a set of Java EE components and APIs used to:

Create data-intensive RIAs with less code, less risk, and accelerated time to market due to an innovative client-server programming model

Integrate RIAs with existing applications, back-end data, and JEE infrastructure

Easily integrate RIAs with LiveCycle document and process services

Enable collaboration, o�ine AIR and real-time data streaming applications to be built in a scalable and reliable manner with robust publish and subscribe messaging

Generate PDF documents from RIAs that include graphical assets

LiveCycle Data Services ES

Data Management

RPC Services

Messaging

ServiceAdapters

Data Synchronization

O�-line Applications

Data Paging

Web Service

HTTP Service

Remote Object Service

Publish & Subscribe

Collaboration

Real Time Data Push

Proxy Service

Web-tier Compiler

Portal Deployment

RIA-PDF Generation

LiveCycle

ColdFusion

Hibernate

SQL

JMS

Java

Custom…

Page 20: Jax2010 adobe lcds

© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con�dential.

Blaze DS

BlazeDS is a set of Java EE components and APIs, and a subset of LiveCycle Data Services:

- Free and open source.

- High performance data transfer for more responsive applications using AMF

- Real-time server push over standard HTTP

- Full pub/sub messaging that extends existing messaging infrastructure

LiveCycle Data Services ES

Data Management

RPC Services

Messaging

ServiceAdapters

Data Synchronization

O�-line Applications

Data Paging

Web Service

HTTP Service

Remote Object Service

Publish & Subscribe

Collaboration

Real Time Data Push

Proxy Service

Web-tier Compiler

Portal Deployment

RIA-PDF Generation

LiveCycle

ColdFusion

Hibernate

SQL

JMS

Java

Custom…

Page 21: Jax2010 adobe lcds

© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con�dential.

Java and ActionScript types

Page 22: Jax2010 adobe lcds

© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con�dential.

Java and ActionScript value objects

Java VO ActionScript VO

Page 23: Jax2010 adobe lcds

2008 Adobe Systems Incorporated. All Rights Reserved.

Flex/Java classic architecture

UI LAYER

SERVERPRESENTATION/SERVICES/DAOLAYER

DATABASE/STORAGE LAYER

LiveCycle Data Services

Java servlet container (tomcat, WAS…)

JDBC

Web browser

JAVA classes/services

Webapp (WAR)

RPC services Messaging Data Mgt ProductService.java public getProducts()

WSDL

AMF sur HTTPs

JAVA <-> AMF

Page 24: Jax2010 adobe lcds

ADOBE FLEX 4

Spring BlazeDS Integration

Page 25: Jax2010 adobe lcds

ADOBE FLEX 4

Messaging

Page 26: Jax2010 adobe lcds

2008 Adobe Systems Incorporated. All Rights Reserved.

Publish/Subscribe Messaging

44

Message

Service

LiveCycle DS / Blaze DS

Endpoint

PublisherSubscriber

!RTMP

!AMF

!HTTP

!Client A

!Client B

!Client C

Page 27: Jax2010 adobe lcds

2008 Adobe Systems Incorporated. All Rights Reserved. 45

Messaging - Data Push

Message

Services

LiveCycle DS / Blaze DS

Adapter Y

Adapter X

Messaging

System Y

Messaging

System X

EndpointJMS

ProviderJMS Adapter

PublisherSubscriber

!RTMP

!AMF

!HTTP

Page 28: Jax2010 adobe lcds

2008 Adobe Systems Incorporated. All Rights Reserved.

Channels of LiveCycle Data Services ES

46

Page 29: Jax2010 adobe lcds

ADOBE FLEX 4

Data ManagementServices

Page 30: Jax2010 adobe lcds

2005 Adobe Systems Incorporated. All Rights Reserved.75

Working with DataTraditional Page-Centric HTML Model

data data

! Client mostly used as a data capture and display device

! Client doesn’t own a version of the data

! No client side data manipulation

! Data needs to be synchronized between middle-tier and data store

Persistence Solutions:

Hibernate

JDOs

EJB 3

Others…

Page 31: Jax2010 adobe lcds

2005 Adobe Systems Incorporated. All Rights Reserved.76

RIA Model

data data data

! Client owns a version of the data

! Rich client-side data manipulation

! Data needs to be synchronized between client-tier and middle-tier and between middle-tier and data store

Page 32: Jax2010 adobe lcds

2005 Adobe Systems Incorporated. All Rights Reserved.77

RPC Approach

data

RPCServices

data

Developer’s Responsibilities:

! Flag changes (create, update, delete)

! Maintain original version of data for appropriate locking strategy

! Make Remote Procedure Calls for creating, updating, deleting items

! Identify and handle con�icts / concurrency issues

Page 33: Jax2010 adobe lcds

2005 Adobe Systems Incorporated. All Rights Reserved.78

Data Services Approach

data

DataService

data

Client-Side API:

! Flags changes (create, update, delete)

! Maintains original version of data for appropriate locking strategy

! Sends list of changes to Data Service as a set of messages

! Handle con�icts / concurrency issues

Page 34: Jax2010 adobe lcds

2005 Adobe Systems Incorporated. All Rights Reserved.79

Data Services Approach

data data

JDBC

Object

Hibernate

ColdFusion

DataService

Custom

Data Service:

! Deserializes list of changes coming from client

! Serializes data before sending to client

! Passes list of changes to con�gured adapter

! Noti�es clients who subscribed to destination

Adapter:

! Processes changes

! Identi�es con�icts

! Passes results to Data Service

Page 35: Jax2010 adobe lcds

2005 Adobe Systems Incorporated. All Rights Reserved.80

Flex Enterprise Services

Data Services

DataService

DAOObjectAdapter

HibernateAdapter

JDBCAdapter

Hibernate

RDBMS

CFCAdapter ColdFusion

Endpoint

Client A

Client B

Client C

Page 36: Jax2010 adobe lcds

!Copyright 2008 Adobe Systems Incorporated. All rights reserved.

Data Management Bene�ts

1. Automatic Client to Middle-Tier Synchronization

! Change Tracking

! Automatic invocation of remote services

2. Highlander Principle: there is only one instance of a given entity in memory at any given time

3. Con�ict resolution

4. O�ine Synchronization

5. Lazy loading

6. Paging

7. Cross-client synchronization

Page 37: Jax2010 adobe lcds

ADOBE FLEX 4

Model driven development

Page 38: Jax2010 adobe lcds

®

Copyright 2008 Adobe Systems Incorporated. All rights reserved.

Code •UI controls / formatters / styles• Calculated �elds• Validation Rules• Variants (conditional properties)• Localization• Security• Data Retrieval Logic (paging, lazy loading)• Data Synchronization Logic

Code-Driven Development

Model •Basic Data Description

Model Server-side code Client-side code

Page 39: Jax2010 adobe lcds

®

Copyright 2008 Adobe Systems Incorporated. All rights reserved.

Code• Ad-hoc customization• View composition• External business/validation logic

Fiber: LCDS Model-Driven Development

Model • Rich data model (data and behaviors)• Calculated �elds• Validation Rules• Variants (conditional properties)• Localization• Security• UI hints/defaults: controls, formatters, styles

Model includes enough information to derive data retrieval, persistence, and synchronization logic

Model Server-side code Client-side code

Page 40: Jax2010 adobe lcds

®

Copyright 2008 Adobe Systems Incorporated. All rights reserved.

!"#$%&'(')$*)+,-./$0*0+11")-*#2,'/.3*/"#$%*.,-$)1)$-'-.",*4,"*3"#$*5$,*,$$#$#6

!"#$%*'+-7").,5*',#*#$1%"2/$,-!"#$%&'(')$*5$0-+)$0*',#*')-.8'3-0*4.$9*!"#$%&#).:$,*8")/06

LCDS Model-Driven Development

;"#$*5$,*"8*<".%$)1%'-$*3"#$*4:'%+$*"<=$3-0>*0-+<0>*$-396

Page 41: Jax2010 adobe lcds

®

Copyright 2008 Adobe Systems Incorporated. All rights reserved.

LCDS Model Driven Development Bene�ts

Productivity: Less code to write

! No persistence code or data sync code

! Value objects and service stubs are automatically generated

Maintainability: Less code to maintain

! Changes to the model are automatically propagated

Consistency

! Between client and server (for example, constraints and validation rules are de�ned in the model, not duplicated using di�erent languages in the client and the server)

! Across views (for example, UI controls, styles, and validation rules are de�ned in the model, not duplicated across di�erent views)

Approachability

! No code to write to implement complex capabilities such as persistence, synchronization, paging, lazy loading, o�ine, etc.

Innovation:

! O�ine and client synchronization capabilities

! Model is language independent and can be leveraged by di�erent client technologies and tools (Flex, PDF, etc)

Page 42: Jax2010 adobe lcds

&

Christophe Coenraetshttp://coenraets.org/

Flex & Java tutorialshttp://www.adobe.com/devnet/flex/flex_java.html

Start with Flexhttp://www.flex.org

Page 43: Jax2010 adobe lcds

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con�dential.

Flash Platform - A complete system for web innovation

Page 44: Jax2010 adobe lcds

©2010 Adobe Systems Incorporated. All Rights Reserved. Adobe Con�dential.

Feel free to contact me

44

Michaël ChaizeFlash Platform Evangelist

My blog: www.RIAgora.com

@mchaize