Introduce an RIA framework to your existing structure
Now you have some knowledge about the concept of RIA. Let's see how to introduce Ria into your existing structure. We will also focus on how to present RIA in a layered application. In addition, it will also discuss some potential problems when developing with the combination of flex and some common open frameworks. These instances will help introduce RIA to your structure.
Let's start with recognizing the layered structure. A structure may include the following layers: presentation layer, business representative layer, business integrated service layer, and persistence layer. This is the basic implementation of the respective layers:
Flex + business delegates + Spring framework + hibernate
The subsequent content will focus on each layer.
What is my existing MVC presentation layer?
In Web applications, the presentation layer is used to transmit user interfaces, process backend service requests, and store information data models. Developers who are new to Ria may initially tend to reuse existing struts. However, development products such as flex provide their own MVC structure. Do you really need to maintain a presentation layer that includes two MVC structures?
The following is an instance when a flex client makes a request to the Java server through the struts component. Before receiving a request from a higher level, the request from the flex client is first sent to the struts representation framework. Figure 1 shows what is not done:
Figure 1. How to not integrate flex and struts with other Java components.
Indicates that the framework, for example, struts, is executed by sending HTML requests through HTTP. When a flex client is used to use the HTTP protocol, the developer will use the remote object over HTTP to reject the request submission method based on the performance and object-oriented advantages. Therefore, the use of these two elements in order indicates that the framework will provide Protocol Configuration errors. Unless you have a specific need to directly use RIA to integrate strut, this can be avoided. Figure 2 shows a better solution when using Flex and struts
Figure 2. Introduction to flex, Struts and other Java components
Figure 2 it is recommended that the separated flex component and Struts component coexist. However, this is conditional. This is required when the application requests the parallel Ria component and the lightweight struts component.
Developers should use the RIA client to do something. For traditional Web developers familiar with the page request response mode, this is a clear ideological change. Ria products like flex are not request-or response-driven like struts. The RIA client is responsible for updating the UI without returning to the server under any circumstances.
When using RIA, Struts is not just the only thing you want. It takes time to get familiar with this type of technology. After these twists and turns, the biggest problem is the integration of Java server components. This is not an RIA concept.
Flex and business layer Integration
We have discussed some presentation layer issues. Next we will discuss how other layers are affected in our application structure. We have reset our presentation layer component. How can we integrate it with the business layer?
Flex is an extensible Ria framework that provides many ways to communicate with your j2.ee components. Flex provides HTTP Communication, World Wide Web service communication, and Macromedia's private AMF (ActionScript messaging formatting) gateway. The AMF gateway is a high-performance binary protocol similar to the Flash remoting protocol. Remote objects are sent to the AMF gateway using the HTTP protocol. Flex provides mxml labels for each of these communication protocols, greatly reducing programming complexity. In addition, flex allows you to enable remote calls for your enterprise level either asynchronously or synchronously. By using an asynchronous remote purchase permission, you can perform some operations on the client, even if it occurs in a traditional World Wide Web application, it is not blocked. You can block users from negotiating with the UI using synchronous calls.
Let's take a look at how to integrate flex with our business integration layer. For this reason, we will use the Spring framework as our integration layer, but this does not limit what integration layer you choose to implement. Let's assume that you have your service running in spring microcontainer, and you need to call remote objects by Flex.
Because flex has no idea about spring, you may consider adding a separate, that is, a thin layer, to represent your service components. In addition, because Spring plays a major role in Java interfaces, we can create a representative object, which indicates that the object implements the same Java interface as the spring service. These indicate that the object will provide a weakened gateway that is separated from the flex and integration layers. The only thing you need to do is configure these objects in the flex configuration file so they can work with the AMF gateway. There is an instance that will demonstrate how the object is configured in the server-side flex-config.xml flex configuration file:
<Object name = "orderbusinessdelegate">
<Source>
Com. Meagle. flexro. flexbusinessdelegate
</Source>
<Type> stateless-class </type>
<Use-custom-Authentication>
True
</Use-custom-Authentication>
<Allow-unnamed-access>
False
</Allow-unnamed-access>
<Roles>
<Role> orderuser </role>
<Role> admin </role>
</Roles>
</Object>
At first glance, you will find that flex has some additional capabilities, similar to setting security, and decide whether to declare the delegate object. When flex sends a remote object call to the inner layer, it will interfere with a flex delegate Java object. the delegate object will be responsible for the call layer or service layer (such as spring ). the result object is returned to the flex client through the AMF gateway. This object is called an ActionScript object. here is an example of mxml code. The flex client uses mxml code to remotely call and store the results in a data mode.
<Mx: remoteobject id = "soapro"
Named = "orderbusinessdelegate"
Protocol = "HTTPS"
Showbusycursor = "true">
<Mx: method name = "saveneworder"
Result = "saveneworder_result (event )"
Fault = "faulthandler (event. Fault)"/>
<Mx: method name = "findorderbyid"
Result = "findorderbyid_result (event )"
Fault = "faulthandler (event. Fault)"/>
<Mx: method name = "updateorder"
Result = "updateorder_result (event )"
Fault = "faulthandler (event. Fault)"/>
</MX: remoteobject>
<Mx: Model id = "romodel">
<! -- The object graph for the Order object
Will be stored here -->
<Order/>
</MX: Model>
The Java domain objects written using the ActionScript equivalents are passed back and forth in the AMF gateway. This process starts with a request from the flex server to other layers of the application through the AMF gateway. A graph of the returned object will be returned to the server through other Java layers and finally through an AMF gateway. Once this object passes through the gateway, they will be converted to the ActionScript equivalents. Figure 3 details the process:
Figure 3. Overview of the AMF gateway.
More instructions on the back-and-forth object transfer between flex and Java tier are as follows: Because ActionScript 2.0 is an object-oriented language, it may generate an ActionScript object with Java equivalents. This makes it easier and consistent to transfer objects back and forth between AMF gateways. The ActionScript object sent back to the Flash plug-in is similar to the data transfer object (DTO ). This is necessary because the flash plug-in does not have any Java runtime components. Below is a familiar example of an order domain object written in Java:
Package com. Meagle. Bo;
Import java. util. arraylist;
Import java. util. collections;
Import java. util. List;
/**
* This object represents an order.
* @ Hibernate. Class table = "testorder"
* @ Author Meagle
*/
Public class order {
Private int ID;
Private double total;
Private int version;
Private string username;
Private list orderlineitems = new arraylist ();
// Other fields and getter/setter methods not
// Shown to save space
}
Here is the ActionScript equivalent:
/**
* Generated Action Script object
* For com. Meagle. Bo. Order. Do not edit!
*/
Class com. Meagle. Bo. Order extends object {
Public Function Order (){}
Public Static Var regclass =
Object. registerclass ("com. Meagle. Bo. Order ",
Com. Meagle. Bo. Order );
VaR ID: number;
VaR orderlineitems: array = new array ();
VaR Total: number;
VaR Username: string;
VaR version: number;
// Other fields and getter/setter methods not
// Shown to save space
}
You should pay attention to the special method of object. registerclass In The ActionScript order object. AMF gateway uses this object. registerclass method to split an object between Java and ActionScript. This method registers the client's ActionScript class to the Java class on the server side. Because these objects are very similar, it is understandable that you do not want to rewrite your domain objects in a slightly different format. Tools like XDoclet and ant financial allow you to automatically generate these ActionScript objects rather than manually encode them. Now you can operate your Java object like The ActionScript equivalents in the flex client.
Flex and persistent layer Integration
In an application that uses a coupled architecture defined on the web, you do not directly talk to your persistent layer. Using flex should not change this architecture. In most cases, the integration layer will replace your conversation with your persistent layer. Data Access Object (DAO) is usually used to connect to permanently stored data such as databases. The flex client does not directly access the integration layer or even understand this layer because it builds a close connection. Let's use hibernate as an example of the persistent layer.
When Hibernate and remote objects are used in the Macromedia's AMF gateway environment, there will be a pair of errors. Hibernate users know that you cannot access a set that does not contain initialized hibernate session objects. Accessing a set of uninitialized dynamic proxy objects will cause a running error. The AMF gateway does not know how to specifically search for hibernate dynamic proxy objects. One potential method is Aspect-oriented programming (AOP ). Remove a dynamic Proxy from an object that will be sent to the AMF gateway as the delegate object. This is a process that contains the result object passed to the interceptor and repeatedly looks for a proxy object that is not initialized using the ing. If you find useless proxy objects or collections, set them to null. This is a cross-cutting concern and can be used as an aspect to use the AOP language, such as JBoss AOP, aspectj, and Spring AOP. The AOP interceptor should be applied to objects at the business proxy layer.
Figure 4 shows an application architecture:
Figure 4 introduce the AOP interceptor before the proxy object is passed into the AMF gateway, which further reduces repeated components at the high-level level, such as the integration layer and persistent layer.
Fortunately, the AMF gateway does not know how to cache two-way objects. Therefore, an infinite recursive loop does not occur when an object is transmitted. Therefore, you can completely maintain this relationship when passing objects on the AMF gateway. At the same time, because the object is not connected and there will be a copy, you need to use the session. saveorupdatecopy (Object object) method to save an object. This method must be used because the object sent back to the AMF gateway does not add useful information for hibernate to the bytecode information.
Verify
Typical J2EE Web applications have many authentication modes. It may be a container-based authentication mode or user authentication with custom passwords. Ria servers like flex allow you to use the flash client's custom authentication format and container-based authentication on most application servers. In addition, if you look at the above example of the business authorization structure, you will find that you can assign tasks to these objects for security reasons. There are even many abnormal branches in the AMF gateway, allowing developers to obtain httprequest, httpresponse, and servletconfig objects to improve the security of the authorized objects you want to use.
Summary
This paper introduces some concepts to help you understand the trade-offs and potential defects when using RIA such as flex. Whether you are using Flex or other Ria tools, you will consider what is most important when building applications. When evaluating an RIA framework, make sure it has sufficient scalability to meet application requirements. In addition, when transmitting objects between RIA and Java, you must be careful when constructing a comprehensive problem.