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:
- Relative path
- The type of the URL, mainly related to host. Will be stitched together into the full URL with the relative path.
- 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.
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