Android interacts with J2EE server through Hessian

Source: Internet
Author: User

For the latest project, record it.

 

First, let the J2EE brothers pass the interface classes implemented by the server Hessian and the public methods of this interface class into and return the classes that need to be serialized to themselves, and copy will also work, you can also compress it into a jar package.

The package name and Class Name of the interface-related classes must also be the same as that of the server.

 

The rest is that the client has added the hessdroid package, a third-party Hessian library for Android.

 

The call is simple. The following is the sample code:

 

Hessianproxyfactory factory = new hessianproxyfactory (); // If user authentication is required // factory. setuser ("uname"); // factory. setpassword ("XXX"); factory. setreadtimeout (5000); // This is the same interface used by the server, from the J2EE brothers, or the jar packages they provide are also the same, as long as the package name class name is the same. Xxxxinterfaceservice ifs = factory. create (xxxxinterfaceservice. class, URL, getclass (). getclassloader (); // these two methods are used to set whether the Hessian Protocol version is 2nd or not. If not, enter false // factory. sethessian2reply (false); // factory. sethessian2request (false); // now you can directly call the method in the interface, just as locally response r = ifs. getsomthing ("somthing ");

 

 

 

It is much easier than WebService.

 

By the way, remote rpc.

 

This year, we have to be brave enough. As long as it is an android client, we have to say it is cloud, isn't it?

Which one is not interacting with the server? As for how to interact, I used to prefer JSON, which is much better than soap such as WebService. As a cloud developer, do you dare to let the poor GPRS traffic of the user transmit XML which is larger than the actual data?

First, it is very troublesome to implement WebService on Android, and ksoap2 is really troublesome to use. Second, who can find the WebService package in JDK's default javax under the SDK? Google has already threw it away and replaced it with JSON.

Hessian is indeed a good choice. hessdroid is well configured on the client, and several lines of code are done. The transmitted binary data is also serialized. Capture the HTTP packet by yourself, the advantages and disadvantages of various remote rpc technologies can be minimized.

Related Article

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.