Request Management Module

Source: Internet
Author: User

Since the request code is now written by everyone, there is neither a unified portal nor a convenient frame replacement.
So wrote a request to manage the middle tier.

The design draft is as follows:

Description

    • 1. Request configuration.

Requestconstant? The internal enumeration class of the Requesttag class, which defines which requests are available.

Definitions include:

    1. Relative path
    2. The type of the URL, mainly related to host. Will be stitched together into the full URL with the relative path.
    3. method, currently only get, post, JSON. He decides how the requestmanager constructs the request body. The default is post.
    • 2. Request call entry, business-related.

Requestfactory?
This class is the only entry that uses the class, business-related invoke HTTP request.
Mainly responsible for the construction parameters to Requestmanager.
The request succeeds or fails to callback the corresponding method of ResponseHandler.

    • 3. Request the actual initiator. Function-related.

Requestmanager will initiate the actual request according to Requesttag,
This class is business-agnostic and business-related definitions are in Requesttag.
At the same time this class will make some basic judgments, such as whether there is a network, whether you need to log in. As with the request, the OnStart (requesttag tag, code code) method of the ResponseHandler interface is called directly.
Return the reason for the error as parameter code.

    • 4. Test unit related.

Two classes are provided for testing the requested.
Testcenteractivity?. Java and urltestactivity?. Java
If there are interface changes, modify the code, re-test it again.

Examples are as follows:

Request Management Module

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.