Important: Since June 28, 2020, mPaaS has stopped support for the baseline 10.1.32. Please use 10.1.68 or 10.1.60 instead. For how to upgrade the baseline from version 10.1.32 to 10.1.68 or 10.1.60, see mPaaS 10.1.68 upgrade guide or mPaaS 10.1.60 upgrade guide. |
The gateway serves as a bridge between the client and the server. The client accesses the backend service API through the gateway. With the gateway, you can:
- Encapsulate the communication between the client and server through dynamic proxy.
- Export the codes automatically generated by the server for the use by the client if both the server and client have consistent APIs defined.
- Perform unified process on
RpcException
, and notify users of the exception through pop-up dialog box and toast box.
The mobile gateway supports three types of access: native AAR, mPaaS Inside and component-based (Portal & Bundle).
Prerequisites
- For native AAR access, you need to Add mPaaS to project.
- For mPaaS Inside access, you need to first complete mPaaS Inside access procedure.
- For component-based access, you need to first complete Component-based access procedure.
Add the SDK
Native AAR
Referring to AAR component management, use Component management (AAR) to install the Mobile Gateway component in your projects.
mPaaS Inside
Use Component management to install the Mobile Gateway component in your projects.
For more information, see Manage component dependency.
Component-based (Portal & Bundle)
Use Component management to install the Mobile Gateway component in your Portal and Bundle projects.
For more information, see Manage component dependency.
Initialize mPaaS
If you access MGS through native AAR or mPaaS Inside method, you need to initialize mPaaS.
public class MyApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
// Callback settings of initializing mPaaS
QuinoxlessFramework.setup(this, new IInitCallback() {
@Override
public void onPostInit() {
// This callback indicates that mPaaS has been initialized, and mPaaS related calls can be made in this callback.
}
});
}
@Override
public void onCreate() {
super.onCreate();
// Initialize mPaaS
QuinoxlessFramework.init();
}
}
Generate RPC code
When the App gains access to the backend service in the mobile gateway console, you can go to the mPaaS console and, from the left-side navigation pane, choose Mobile Gateway Service > Manage APIs > Generate code, then you can download the RPC code of the client. For more information, see Mobile Gateway Service > Server Control .
The structure of the downloaded RPC code is as follows. It consists of the RPC configuration, request model and response model.
Call RPC
The client initiates RPC request.
// Obtain client instance
RpcDemoClient client = MPRpc.getRpcProxy(RpcDemoClient.class);
// Set request
GetIdGetReq req = new GetIdGetReq();
req.id = "123";
req.age = 14;
req.isMale = true;
// Initiate RPC request
try {
String response = client.getIdGet(req);
} catch (RpcException e) {
// Process RPC exception
Log.i("RpcException", "code: " + e.getCode() + " msg: " + e.getMsg());
}
RPC exception is thrown through RpcException
, and you can handle the exception with reference to the result code. For instructions on error codes, see Gateway result codes.