Today we use the j2.ee server to develop Internet applications, usually including a presentation layer such as struts, tapestry, webwork, or spring. These tools generally follow the Model-View-controller (MVC) structure and output them to the browser in the form of HTML. A typical web development programming mode allows users to send requests to an application server for each action in an application. Each time an action user sends a request, the server generates a new response, which allows the user to submit a new request for more information. Browsers are generally used as user interfaces for submission to users. However, the browser is a thin client, which has limitations that affect expansion and end user experience.
The emergence of rich Internet application (RIA) technology addresses the limitations of the presentation layer. This article introduces what is RIA and how to integrate Ria into your own system structure. It also identifies potential challenges when combined with common open frameworks.
Copyright Disclaimer: Any website authorized by matrix must retain the following author information and links for reprinting.
Author: Mark eagle; molecule
Original article: http://www.onjava.com/pub/a/onjava/2004/12/01/flexjava.html
Http://www.matrix.org.cn/resource/article/44/44195_Macromedia+Flex+Java.html.
Keywords: Macromedia; flex; Java
Browser limitations
Is there any problem with the current solution? If the application runs correctly and the user is allowed to be productive, there may be no errors. However, many web developers once complained that using a browser as a client would limit performance. This is a problem encountered when developing Web applications:
1. the browser interprets the scripting language in an inconsistent way, such as the Java language. This forces developers to write the same code multiple times to adjust various browsers.
2. The simple user interface will affect the processing of selected, wizard-based forms, and Big Table datasets, which requires more additional code in the browser.
3. html is limited, and static Markup languages cannot be expanded.
4. event processing within the user interface may be challenging. Because only one page can be displayed for the reported HTML page at a time, and other pages cannot be updated before the event is returned to the server.
5. You can only use cookies to achieve continuous application status. cookies do not support objects.
6. Using a browser to develop Occasionally Connected clients is almost impossible.
Many Web developers know this fact: the current tool settings have limitations. When working on a browser, the developer must find a solution. For developers and users, using a thin client cannot withstand the current performance.
Rich internet applications
To overcome these limitations, we should consider using RIA for development. Nowadays, Ria gives users a fat client to expand the performance that browsers cannot afford. Java and Flash are the most widely used Ria clients of j2.ee. When developing applications in a large data center, RIAs is really strong. Several feasible methods for developing Ria are jdnc (jdesktop network components), Laszlo, thinlet, Java Web Start, and Macromedia Flex.
Ria can solve the problem as mentioned earlier. The following are some features of RIAs:
1. RIAs provides the same UI components as browsers, and it also provides more local components. For example, it includes a digital step, sliding control, an axial Data Grid element, and a menu bar.
2. Mature Ria applications allow the layout manager to be composed of the following, such as Tab browsers, folding, tree structures, and other layout controls comparable to AWT and swing development.
3. RIAs provides drag and drop capabilities.
4. The languages in RIA are the same. It runs through all clients and does not have to be rewritten for different implementations.
5. In the user interface, each action does not have to be in the request/response mode. Through rich Internet applications, users interact with the UI. If necessary, they only need to send requests to the server. RIAs uses the HTTP protocol to submit data to the application server. However, generally, the RIAs mechanism is better remote, which supports different methods based on Ria. RIAs provides an extended protocol for communication with HTTP.
6. event processing is possible across multiple components.
7. RIAs allows you to store more information on the client without using httpsession. This reduces the memory occupied by the application server.
8. State continuous broadcast, usually in the form of objects, provides the possibility of creating clients with occasional connections.
Ria is a fairly new technology that describes the applications involved in development. It cannot solve all applications. It depends on some implementation. However, if you think your application can benefit from a richer UI design, Then Ria may be able to serve you. This article will focus on an RIA solution, Macromedia Flex, and focus on it.
Macromedia Flex
Macromedia Flex is a commercial presentation layer server of RIA. Because this is the environment for flex applications. You must install the flash plug-in. Most browsers are equipped with Flash plug-ins. For Ria, this also helps to properly use flex. Let's discuss the significance of using the flash plug-in to talk to the j2.ee application server without using the Java Plug-in.
Developers use two core languages to create flex applications. The first core language is mxml, Which is Macromedia Flex markup language. It has a rich set of XML tags that allow developers to design user interfaces. Mxml can also be considered XUL or xml ui Language. Unlike HTML, these tags can be expanded and have the additional capabilities required by applications. Other mxml structures can be called remote objects, store the returned data in the model, and customize your own views on the mxml component.
The second core language for flex development is ActionScript 2.0, a language supported by ECMA, similar to the Javascript language. The principle of ActionScript is encoded in the mxml page. This is a strong object-oriented language, which is familiar to Java developers. It also has a great deal of event processing capabilities, allowing applications to respond to dynamic user interactions. Because ActionScript runs in the Flash plug-in, it is different from JavaScript encoding in the browser. You do not need to rewrite several versions of the same encoding to support different browsers. Mxml and ActionScript are text-based languages that can be written in a simple text editor or an IDE tool such as Eclipse, or a more sophisticated tool like flex Builder by Macromedia. If you have been familiar with Java, XML, and scripting languages such as JavaScript, you will have to bend down a little while learning flex.
The flex server is responsible for converting mxml and ActionScript components into flash bytecode in the form of. SWF files. This process is similar to compiling JSP files into servlets using Java Web application containers. In the flash running environment, the SWF file is executed in the client. The flex server provides other services such as cache, concurrency, and remote object requests.
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 to 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.
For example, Struts is used to send HTML requests over 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. The request is sent from the flex server to the other layer 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 the object that has been initialized to hibernate. 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 a 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, so an infinite recursive loop does not occur when an object is transferred. 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 will be copied, you need to use 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 take a 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.
Note: The above content comes from the Internet and I am not liable for any joint liability.
Article transferred from: http://www.jspcn.net/htmlnews/11500197164681199.html