Você está na página 1de 25

Blaze-DS Exploration Findings

Introduction-

 Blaze DS is a server-based Java remoting and web


messaging technology that allows you to connect to
back-end distributed data and push data in real-time to
Adobe Flex and Adobe AIR rich Internet applications (RIA
).

Previously it was a part of Adobe LCDS .After December 2007 it


became Open source under LGPL.

CONFIDENTIAL
LCDS Feature:-

CONFIDENTIAL
Blaze-DS Feature in Red Box :-

CONFIDENTIAL
Blaze-DS is good because it uses AMF ?

What is AMF ??
 It stands for “Action Message Format”.

 Fast(10x over XML) and small in size.

 Action Message Format (AMF) is a compact binary format


that is used to serialize ActionScript object graphs. Once
serialized an AMF encoded object graph may be used to
persist and retrieve the public state of an application
across sessions or allow two endpoints to communicate
through the exchange of strongly typed data.

 AMF was introduced with Flash Player 6, and this version


is referred to as AMF 0.(Now with AS3.0 AMF 3.0 is used)

CONFIDENTIAL
Blaze-DS is good because it uses AMF ?

What is AMF ??
 It stands for “Action Message Format”.

 Fast(10x over XML) and small in size.

 Action Message Format (AMF) is a compact binary format


that is used to serialize ActionScript object graphs. Once
serialized an AMF encoded object graph may be used to
persist and retrieve the public state of an application
across sessions or allow two endpoints to communicate
through the exchange of strongly typed data.

 AMF was introduced with Flash Player 6, and this version


is referred to as AMF 0.(Now with AS3.0 AMF 3.0 is used)

CONFIDENTIAL
Services provided in Blaze-DS

 RPC services :--


-- Provides a call and response model for accessing
external data.
-- Make asynchronous requests to remote services that
process the requests, and then return data to your Flex
application.
 Message Service :--
-- Provides messaging services for collaborative and real-
time applications.
-- Send messages to and receive messages from other
applications, including Flex applications and JMS.

CONFIDENTIAL
Remote procedure call (RPC) component

RPC component are


based on SOA.

 HTTP services .
 Web services .
 Java objects (remote object
services) .

CONFIDENTIAL
Steps in Creating RPC Clients-

 Declaring an RPC component.


 Configuring a destination.
 Calling a service Parameter Binding, Explicit parameter
passing).
 Calling services in AS (result,fault,name,concurrency).
 Handling service results.
 Validation.
 Handling asynchronous calls to services.
 Accessing Java objects in the source path (EJB).
(Small App with Add, view, delete Operation in Flex
With directory structure of various config files)

CONFIDENTIAL
Parameter binding Example

<mx:RemoteObject id="ro" destination="roDest" >


<mx:method name="setData">
<mx:arguments>
<arg1>{text1.text}</arg1>
<arg2>{text2.text}</arg2>
</mx:arguments>
</mx:method>
</mx:RemoteObject>
<mx:TextInput id="text1"/> <mx:TextInput id="text2"/>
<mx:PhoneNumberValidator
source="{ro.setData.arguments}" property="arg1"/>

CONFIDENTIAL
Explicit parameter passing Example :-
<mx:RemoteObject id="employeeRO"
destination="SalaryManager" result="empList=event.result"
fault="Alert.show(event.fault.faultString, 'Error');"/>
<mx:ComboBox id="dept" width="150">
<mx:dataProvider>
<mx:ArrayCollection>
<mx:source>
<mx:Object label="Engineering"
data="ENG"/> <mx:Object label="Product
Management" data="PM"/> <mx:Object
label="Marketing" data="MKT"/>
</mx:source>
</mx:ArrayCollection>
</mx:dataProvider>
</mx:ComboBox>
<mx:Button label="Get Employee List"
click="employeeRO.getList(dept.selectedItem.data);"/>

CONFIDENTIAL
Configuring RPC Services:-

 Destination configuration .

An RPC service destination is the object or service that


you connect to using an <mx:RemoteObject>,
<mx:WebService>, or <mx:HTTPService> tag or the
corresponding ActionScript API.

 Configuring destination properties .

To communicate with Remoting Service and Proxy


Service destinations, you configure specific types of
destination properties in the properties section of a
destination definition.

CONFIDENTIAL
Destination configuration Example:-
<service id="remoting-service"
class="flex.messaging.services.RemotingService">
<adapters>
<adapter-definition id="java-object"
class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
</adapters>
<default-channels>
<channel ref="samples-amf"/>
</default-channels>
<destination id="SampleEmployeeRO">
<properties>
<source>samples.explorer.EmployeeManager</source>
<scope>application</scope>
</properties>
<security>
<security-constraint ref="privileged-users"/>
</security>
</destination>
</service>

CONFIDENTIAL
Configuring destination properties :-

 For Remote Object :--


<destination id="SampleEmployeeRO">
<properties>
<source>samples.explorer.EmployeeManager</source>

<scope>application</scope> (request , session)


</properties>
<adapter ref="java-object"/>
</destination>

For Web Service Parameters used :- wsdl , soap .


For HTTP Service Parameters used :- url , dynamic-url .

CONFIDENTIAL
Serializing Data (AS to Java) :-

 Array (dense) -> java.util.List


 Array (sparse) -> java.util.Map
 Boolean String of "true" or "false” -> java.lang.Boolean
 flash.utils.ByteArray -> byte[ ]
 flash.utils.IExternalizable -> java.io.Externalizable
 Date -> java.util.Date
 int/uint -> java.lang.Integer
 Null -> null
 Number -> java.lang.Double
 Object (generic) -> java.util.Map
 String -> java.lang.String
 XMLDocument -> org.w3c.dom.Document

CONFIDENTIAL
Serializing Data ( Java to AS) :-
 enum (JDK 1.5) -> String
 java.lang.String -> String
 java.lang.Boolean, boolean -> Boolean
 java.lang.Integer, int -> int
 java.lang.Short, short -> int
 ava.lang.Byte, byte[] -> int
 java.lang.Byte[] -> flash.utils.ByteArray
 java.lang.Double, double -> Number
 java.lang.Character, char -> String
 java.util.Calendar -> Date
 java.util.Date -> Date
 java.util.Collection -> mx.collections.ArrayCollection
 java.util.Map -> Object
 org.w3c.dom.Document -> XML object

CONFIDENTIAL
Explicitly mapping ActionScript and Java objects

 Blaze-DS uses the standard Java class,


java.beans.Introspector, to get property descriptors for a Java
bean class. It also uses reflection to gather public fields on a
class.
 The Java and ActionScript property names should match.
 In the ActionScript class, you use the [RemoteClass(alias=" ")]
metadata tag to create an ActionScript object that maps directly
to the Java object.
Example:--
package samples.contact {
[Bindable]
[RemoteClass(alias="samples.contact.Contact")]
public class Contact {
public var contactId:int;
}
}

CONFIDENTIAL
Configuring Blaze-DS :-
Important Files :--
 services-config.xml
The top-level Blaze-DS configuration file. This file usually contains
security constraint definitions, channel definitions, and logging
settings that each of the services can use. It can contain service
definitions inline or include them by reference. Generally, the services
are defined in the remoting-config.xml, proxy-config.xml, and
messaging-config.xml.
 remoting-config.xml
The Remoting Service configuration file, which defines Remoting
Service destinations for working with remote objects.
 proxy-config.xml
The Proxy Service configuration file, which defines Proxy Service
destinations for working with web services and HTTP services (REST
services).
 messaging-config.xml
The Message Service configuration file, which defines Message Service
destinations for performing publish subscribe messaging.

CONFIDENTIAL
Securing destinations(Custom) :-

 Custom
<service>
<destination id="roDest">
<security>
<security-constraint>
<auth-method>Custom</auth-method>
<roles><role> sampleuser r</role> </roles>
</security-constraint>
</security>
</destination>
</service>
tomcatUser.xml should contain the following entry:--
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="sampleuser"/>
<user username="tomcat" password=“facetime" roles=" sampleuser "/>
</tomcat-users>

CONFIDENTIAL
Passing credentials to a remote service:-
var employeeHTTP:HTTPService = new HTTPService();
employeeHTTP.destination = "secureJSP";
employeeHTTP.setRemoteCredentials
("myRemoteUserName", "myRemotePassword");
employeeHTTP.send({param1: 'foo'});

Alternative way of doing the above is


<destination id="samplesProxy">
<channels> <channel ref="samples-amf"/> </channels>
<properties>
<url> http://someserver/SecureService.jsp </url>
<remote-username>johndoe</remote-username>
<remote-password>opensaysme</remote-password>
</properties>
</destination>

CONFIDENTIAL
Securing destinations(Basic) :-
 Basic <security-constraint id="privileged-users">
<auth-method>Basic</auth-method>
<roles> <role>privilegedusers</role> </roles>
</security-constraint>
In Web.xml the following need to be set :-
<security-constraint>
<web-resource-collection>
<web-resource-name>Protected Channel</web-resource-
name>
<url-pattern>/messagebroker/amf</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>sampleusers</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
<security-role> <role-name>sampleusers</role-name> </security-role>

CONFIDENTIAL
Login adapters :-

 For both custom and basic authentication, Flex uses a


login adapter, known as a login command, to check a
user's credentials and log a principal into the application
server. A login command must implement the
flex.messaging.security.LoginCommand API.
 For basic authentication, an HTTP 401 error causes a
browser challenge .
 For custom authentication, the server sends a fault to the
client to indicate that authentication is required.
<security> (services-config.xml)
<login-command
class="flex.messaging.security.TomcatLoginCommand"
server="Tomcat"/>
</security>

CONFIDENTIAL
Monitoring and managing services :-

We can See all the MBean through the following :-


http://server:port/ds-console
Data services class loading :--
<servlet>
<servlet-name>MessageBrokerServlet</servlet-name>
<display-name>MessageBrokerServlet</display-name>
<servlet-class>
flex.messaging.MessageBrokerServlet
</servlet-class>
<init-param>
<param-name>services.configuration.file</param-name>
<param-value>
/WEB-INF/flex/services-config.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

CONFIDENTIAL
Server-side service logging:-

We can set the logging level to one of the following available levels:
 all ,debug ,info ,warn ,error ,none .
Example :-
<logging>
<target class="flex.messaging.log.ConsoleTarget"
level="Debug">
<properties>
<prefix>[Blaze-Ds-Test-By-Subrata]</prefix>
<includeDate>false</includeDate>
<includeTime>false</includeTime>
<includeLevel>false</includeLevel>
<includeCategory>false</includeCategory>
</properties>
<filters>
<pattern>Endpoint</pattern>
</filters>
</target>
</logging>

CONFIDENTIAL
The End
PPT By- Subrata Saha

CONFIDENTIAL

Você também pode gostar