Flex Remote Call mechanism RemoteObject application Tips

Source: Internet
Author: User

Transferred from: http://zerozone.javaeye.com/blog/60846
Flex Remote Call RemoteObject problems and answers:

This article focuses on the process of flex interaction between client and Java EE middle tier data.

Flex is a client-side technology for building RIA applications. It has the advantage of providing rich client performance capabilities (such as enhanced UI components, caching, drag-and-drop, shrinking/unwinding, etc.), avoiding the pitfalls of HTML-based technology, and seamlessly combining the powerful advantages of the Java EE technology in the middle tier (business logic layer).

Although the "experience economy" proposed by Macromedia has a propaganda strategy, the prevalence of RIA and Ajax suggests that there is a market demand for rich-client technology. As with the Java EE Platform Architecture, no technology is perfect. Each new technology appears to address specific issues. The Java EE Construction Web application is already very mature, already has many good practice, but is limited by the Java EE itself, it has the limitation in the presentation Rich client aspect (JSF's appearance may solve this problem).

RPC-based Httpservice, WebService, and RemoteObject are common data access mechanisms. According to the official information, remoteobject performance and development efficiency performance is better. The method of data encapsulation based on XML text protocol such as Webservice/httpservice in case of large user concurrency and heavy load, the RemoteObject uses the AMF (Actice Message Format, the current version is AMF3) more efficient. The AMF protocol is a binary protocol that gives HTTP, which serializes the business objects of the middle tier (mainly business data Objects) from Java to the ActionScript object.

RemoteObject the use of the process has a few problems and more trouble.

1. The compilation and configuration process is cumbersome, such as the common unknown destination problem is caused by incorrect compilation or configuration process.

2. It is also a cumbersome process to write ActionScript objects that correspond to Java objects. Can be categorized as repetitive and less meaningful work. You might consider this task to be done by the tool. Imagine that it's really not a pleasant thing to maintain the mapping between ActionScript and the corresponding Java object for a project with a large scale of requirements change.

A few problems encountered:

1.Unknown Destination

The reason for the error may be that the Flex compiler has not established service parameters.

workaround : Set compiler parameters in Flex Builder or the eclipse environment where the FlexBuilder2 plug-in is installed, select the Flex Project right-click, select Properties, and then select Flex Complier, Add the corresponding parameters and values to the additional parameters. For example the following two, Blackbody is modified before the red body Word is modified.

-locale en_US

-locale en_us-context-root=/flex-services= "C:\Program files\apache software foundation\tomcat 5.0\webapps\flex\ Web-inf\flex\services-config.xml "

2.could ' t invoke XXX method (for example, call specific Ro getquote, mistakenly written getquote)

The reason is probably because the specific RO function name is wrong, because the Mxml language uses a large number of parameter annotation mode to specify the object properties, resulting in quotation marks can not be recognized by the compiler, the problem is deferred to run-time time to find.

3.Send failed

The reason is that the channels definition in Service-config.xml MY-AMF {context.root} does not specify its context-root in the Flex Builder compiler parameter, causing the compiled SWF file to be incorrect;

Solution with 1

4.Ljava.lang.NoSuchMethodError ...

The reason is that a call to a nonexistent method may occur in the corresponding Java code of RO. For example, a RO corresponds to a Java class ticker in its function getquote in the new StockQuote instance StockQuote x = new StockQuote (PARAM1,PARAM2), But the StockQuote class has only one constructor for an empty argument, so the Nosuchmethoderror error is passed to the flex-call RO client. Why is there a ticker reference to a nonexistent StockQuote constructor because the code is not synchronized in time. For example, the StockQuote code has been modified to remove the constructor with parameters, and ticker that rely on this class have not been corrected in time.

5.Referenceerror:error #1056: Could not create attribute B for a

This is a curious question, all of the ActionScript classes that synchronize the Java object classes, that is, the classes specified by the METADATA keyword Remoteclass. property names corresponding to Java classes cannot start with uppercase letters.

For example, the StockQuote class in Java
Java code

  1. Package com.stockquote;
  2. public class StockQuote {
  3. Public StockQuote () {}
  4. Public String Getcompany () {
  5. Return company;
  6. }
  7. public void Setcompany (String company) {
  8. This.company = Company;
  9. }
  10. Public double GetPrice () {
  11. return price;
  12. }
  13. public void Setprice (double price) {
  14. This.price = Price;
  15. }
  16. Private String Company;
  17. private double price;
  18. }


In Actionscrpit, company and price must start with lowercase, or there will be an error, that is, the field cannot be deserialized on the flex call side.

Java code

  1. Package com.stockquote{
  2. [Bindable]
  3. [Remoteclass (alias= "Com.stockquote.StockQuote")]
  4. public class stockquote{
  5. function StockQuote () {
  6. Constructor code if needed
  7. Trace (this);
  8. }
  9. Public Function Getcompany (): string{
  10. Return company;
  11. }
  12. Public Function Setcompany (company:string): void{
  13. This.company = Company;
  14. }
  15. Public Function GetPrice (): number{
  16. return price;
  17. }
  18. Public Function Setprice (price:number): void{
  19. This.price = Price;
  20. }
  21. public Var company:string;
  22. public Var Price:number;
  23. }
  24. }


The code above will cause the following error.

Referenceerror:error #1056: Could not create property for Com.stockquote.StockQuote company.

Flex Remote Call mechanism RemoteObject application Tips

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.