All Products
Search
Document Center

Quick start

Last Updated: Apr 23, 2021
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

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.

  1. public class MyApplication extends Application {
  2. @Override
  3. protected void attachBaseContext(Context base) {
  4. super.attachBaseContext(base);
  5. // Callback settings of initializing mPaaS
  6. QuinoxlessFramework.setup(this, new IInitCallback() {
  7. @Override
  8. public void onPostInit() {
  9. // This callback indicates that mPaaS has been initialized, and mPaaS related calls can be made in this callback.
  10. }
  11. });
  12. }
  13. @Override
  14. public void onCreate() {
  15. super.onCreate();
  16. // Initialize mPaaS
  17. QuinoxlessFramework.init();
  18. }
  19. }

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.

RPC

Call RPC

The client initiates RPC request.

  1. // Obtain client instance
  2. RpcDemoClient client = MPRpc.getRpcProxy(RpcDemoClient.class);
  3. // Set request
  4. GetIdGetReq req = new GetIdGetReq();
  5. req.id = "123";
  6. req.age = 14;
  7. req.isMale = true;
  8. // Initiate RPC request
  9. try {
  10. String response = client.getIdGet(req);
  11. } catch (RpcException e) {
  12. // Process RPC exception
  13. Log.i("RpcException", "code: " + e.getCode() + " msg: " + e.getMsg());
  14. }

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.