BlazeDS

24
Integration of Spring with Blaze DS and Cairngorm UM Deepdive by N.S.Devaraj http://nsdevaraj.wordpress.com/ twitter : @nsdevaraj

Transcript of BlazeDS

Page 1: BlazeDS

Integration of Spring with Blaze DS and Cairngorm UM Deepdive by N.S.Devaraj http://nsdevaraj.wordpress.com/twitter : @nsdevaraj

Page 2: BlazeDS

Agenda for this season What is Spring? Why Spring with Flex? Why Spring BlazeDS Integration? What is & Why Cairngorm UM? What is & why generic DAO? What is & Why CairnSpring?

Page 3: BlazeDS

`

WHAT IS SPRING?

The result is looser coupling between components. The Spring IoC container has

proven to be a solid foundation for building robust enterprise applications.

The components managed by the Spring IoC container are called Spring beans.

Page 4: BlazeDS

WHAT IS SPRING?

The Spring framework includes several other modules in addition to its core IoC

container. http://www.springframework.org.

Page 5: BlazeDS

WHY WE NEED FLEX ACCESS SPRING?

Flex is the obvious choice when a SpringDeveloper is looking at RIA.

Can reuse your server-side Spring to moveinto RIA.

Page 6: BlazeDS

WHY WE NEED FLEX ACCESS SPRING?

In scenario of the Remoting and Data Management Services approaches:

It enable the tightest integration with Spring. There is no need to transform

data, or to expose services in a certain way: the Flex application works directly

with the beans registered in the Spring IoC container.

Page 7: BlazeDS

WHY WE NEED FLEX ACCESS SPRING?

The BlazeDS Remoting enables binding your valueobjects with Java pojo Classes easily

by metadata [RemoteClass(alias=”com.adobe.pojo.ob”]

By using the Spring Security 2.0 we can make our application secured for

transactions.

Page 8: BlazeDS

Browser or AIR .swf

application

ServiceProxy

RemoteProcedure

CallsMessaging

domain http(s)

blazeds server

External Services

WHAT is BlazeDS?BlazeDS provides a set of services that lets you connect

a client-side application to server-side data, and pass data among multiple clients connected to the server. BlazeDS implements real-time messaging between

clients.

Page 9: BlazeDS

domain

/{context}/messagebroker/*servlet

.classconfig

.jarlibrary.jar

library

proxy-config.xmlconfig

messaging-config.xmlconfig

remote-config.xmlconfig

services-config.xmlconfig

core

flex

LibClasses

BlazeDS Server

Page 10: BlazeDS

BLAZE DS WAY Using the “dependency lookup” approach of the SpringFactory feels opposite to the "Spring Way" The burden of configuration is multiplied. Potential for deep integration beyond just remoting is limited.

Page 11: BlazeDS

Bootstrap the BlazeDS MessageBroker as a Spring-managed bean (no more web.xml or MessageBrokerServlet config needed). Route http-based Flex messages to theMessageBroker through the Spring DispatcherServlet. Expose Spring beans for remoting by namespace

BLAZEDS SPRING INTEGRATION

Page 12: BlazeDS

TRADITIONAL BLAZE DS WAY

The BlazeDS configuration first imports the 'remoting-config.xml',The parameters in the URL 'server.name' and 'server.port' are supplied by the Flex runtime. The 'context.root' parameter needs to be supplied during compilation using the 'context-root' compiler option.services-config.xml

<?xml version="1.0" encoding="UTF-8"?><services-config> <services> <service-include file-path="remoting-config.xml" /> <default-channels> <channel ref="person-amf"/> </default-channels> </services> <channels> <channel-definition id="person-amf" class="mx.messaging.channels.AMFChannel"> <endpoint url="http://{server.name}:{server.port}/{context.root}/spring/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/> </channel-definition> </channels> </services-config>

Page 13: BlazeDS

SPRING BLAZEDS INTEGRATIONWEB.XML

Spring BlazeDS Integration servlet

<servlet>

<servlet-name>spring-flex</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/flex-servlet-context.xml</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

Mapping Spring BlazeDS Integration servlet to handle all requests to '/spring/*

<servlet-mapping>

<servlet-name>spring-flex</servlet-name>

<url-pattern>/spring/*</url-pattern>

</servlet-mapping>

Example:

Page 14: BlazeDS

SPRING BLAZE DS EXAMPLE

flex-servlet-context.xml

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:flex="http://www.springframework.org/schema/flex" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/flexhttp://www.springframework.org/schema/flex/spring-flex-1.0.xsd">

<context:component-scan base-package="org.springbyexample.web.service" />

<flex:message-broker/> ----Spring BlazeDS Integration configuration of the BlazeDS message broker, which handles remoting and messaging requests.

<flex:remoting-destination ref="personDao" /> ---Exposes the personDao bean as a BlazeDS remoting destination

</beans>

Page 15: BlazeDS

SPRING BLAZEDS INTEGRATION PersonService.java

@Service@RemotingDestinationpublic class PersonService { private final PersonDao personDao; /** * Constructor */ @Autowired public PersonService(PersonDao personDao) { this.personDao = personDao; } public void remove(int id) { Person person = personDao.findPersonById(id); personDao.delete(person); }}

PersonDeleteCommand.as var ro:RemoteObject = new RemoteObject("personDao"); ro.remove(id); ro.addEventListener(ResultEvent.RESULT, updateSearch);

Page 16: BlazeDS

Cairngorm with UM Extensions Universal Mind Cairngorm Extensions

( UM – CGX is easy to migrate from CG) Event – Business logic combined together Command logic can be aggregated to

context-specific command classes (minimizes the number of classes)

Support for easy queue of delegate calls (SequenceGenerator)

Page 17: BlazeDS

Cairngorm with UM Extensions Create Responder in view Add responder to event Cache/Store responder from event to

command In Command, on success/failure call back

these responders On view handle success/failure to control

view states

Page 18: BlazeDS
Page 19: BlazeDS

Cairngorm with UM ExtensionsView Layer Model Layer Control Layer

View

ModelLocator

Command Delegate Servervia databinding

via IRespondertcp/ip

View Layer Business Layer

View Command Delegate Server

via IResponder via IRespondertcp/ip

via eventdispatching

via eventdispatching

MVC Classic Usage

Using View Notifications

MVC Classic Usage

Page 20: BlazeDS

J2EE – DAO INTRODUCTION All database access in the system is made

through a DAO to achieve encapsulation. Each DAO instance is responsible for one

primary domain object or entity. If a domain object has an independent lifecycle, it should have its own DAO.

The DAO is responsible for creations, reads (by primary key), updates, and deletions -- that is, CRUD -- on the domain object.

Page 21: BlazeDS

generic DAO For creating a new DAO we need →a Hibernate mapping file, a plain old Java interface, and 10 lines in your Spring configuration

file.

Resource:http://www.ibm.com/developerworks/java/library/j-

genericdao.html

Page 22: BlazeDS

CairnSpring

The CairnSpring includes both Caringorm UM, Generic DAO along with the Spring BlazeDS

Integration.

It also enables Paging request.

http://www.code.google.com/p/cairnspring

Page 23: BlazeDS

Cha

nnel

s

BlazeDS

Long Polling

NIO Streaming

RTMPNIO Polling

PollingAMF

HTTP

Messaging

NIO LongPolling

Streaming

Producer ConsumerRemoteObject Dataservice

Remoting Data Mgmt

Piggyback

®

Copyright 2008 Adobe Systems Incorporated. All rights reserved.

Ser

vice

sA

dapt

ers

MessagingProxy

Remoting Data Mgmt

Change Tracking

Data Sync

RPC

AMF

Pub/Sub

Real Time Push PDF

Security

Hibernate ColdFusionSQL

SpringWSRP

JMS Java

Page 24: BlazeDS

QUESTIONS