This article explains how to use example code properly for Android SDK
Configuration in Admin Portal
Before implementing the example code, you need to configure several things such as generate Trusted Certificate, Add API Endpoints, and Create API Group.
Generate New Trusted Certificate
First, Login to the Admin portal. Go to Settings, then Click Configurations. You can see in the right section there are 3 menu, click Trusted Certificate.
Then click Generate Certificate. Fill the certificate name as you want, and do not forget to fill the PassPhrase Certificate. If you finish, click Generate on right below.
After that, the new certificate already generated. Click Download Client Certificate to save the Certificate in your local directory.
Add API Endpoint
Set your API Endpoint in admin portal. Go to Settings then Click API Protection.
To create new API Endpoint, click New API Endpoint in right above. As example, create echo API from Postman echo-server for sample API that to be used on Example code. And fill the form as follows:
- Name: echo
- Endpoint Address/FQDN/Hostname: postman-echo.com
- Protocol: HTTPS
- Other settings: using default settings (no changed)
If finished fill the form, click Save.
Then create another simple web API Endpoint for testing. You need to add New API Endpoint and fill the form like this:
- Name: simple-web
- Endpoint Address/FQDN/Hostname: 192.168.0.1
- Protocol: HTTP (or HTTPS. It's depends on your environment)
- Other settings: using default settings (no changed)
Click Save if you finished.
Create New Default API Group
As a summary for those API Endpoint that already created, you need create an API group. Go to Settings, click API Protection then go to API group on left bar.
Click New API Group on right above. Fill the form with the instruction below:
- API Group Code: default
- Description: Default Group Description (or fill as you want)
- Trusted Certificate: cert-1
- API Application (Main): echo, simple-web
After that, click Save.
Generate safouswaap.ini file
Go to Settings, click API Protection then go to API group on left bar. Then select the API group that you want to generate. Click Download Config beside Edit button on the top left.
The popup appeared. Now fill the passphrase with password of your certificate, and path of certificate placed on your directory project.
*note: Check path of your directory project with example code below.
- Client Certificate Passphrase: <passphrase_of_certificate>
- Client Certificate Path: /data/user/0/<project>/files/<certificate>.p12
If it is done, click download on the bottom left of popup. Now the safouswaap.ini file are automatically downloaded.
Download Source Code of the Example Code
Get the example code from GitHub by clone the repository.
https://github.com/iij-safous/safous-waap-sdk-android-example
After clone the example code repository, open the project in Android Studio.
Download SDK from Admin Portal.
Get the WAAP SDK for Android from admin portal. Login to admin portal, then go to Settings then click SDK on left bar. You will see the list of SDK version that WAAP release.
Click Download button in right side of the list for get the SDK into your local directory.
Put Certificate, .ini file and SDK into Example Code project.
At first you already download the certificate, safouswaap.ini file and SDK to put on local directory. Now for certificate and safouswaap.ini file, move it to Assets directory in main project.
<project>/app/src/main/assets
For SDK, put it on libs directory in project.
<project>/app/libs
Set URL for Example Transaction
You need to create 2 Endpoints for testing. There are Simple and Echo API. It can be created in Admin Portal. If it is done, It may look like the image below.
Next, update the URL for Transaction modules in Safous WAAP. Open Example Transaction Activity files, then set the URL that you already generated from admin portal. For more you can see the detail from GitHub link below. Check the Simple and Echo API that you created in Admin Portal already correct with the configuration.
ExampleTransactionActivity L20-L21
public String urlBasicApi = "https://simple-web.example-waap.waap.safous.com/"
public String urlEchoApi = "https://echo.example-waap.waap.safous.com/"
Build and Run the Example Code Project
Open your Android Studio with Example Code project in it. Click Run on taskbar or Click Ctrl+R from your keyboard. There are 3 classes you can run such as ExampleSetup, ExampleRegistration, and ExampleTransaction. All 3 classes have a different purposes as you can see the detail below.
Class | Description |
ExampleSetupActivity | This is use as setup and declaration parameter that determine which environment you used for your codebase. |
ExampleRegistrationActivity | This is an example of registration, using registerDevice and verifyDevice method |
ExampleTransactionActivity | This is an example of transaction, using transaction method and simple-web API endpoint, Echo server API Endpoint, and Terminate method. |