Using http_adapter in sandbox mode

Posted by JPLa on February 20, 2019

While testing some modifications to the http_adapter I had the need to test sending MT messages without actually letting them reach the phone. Opaali API has the sandbox mode for such a need.

There already was the API_HOST configuration parameter which was useful when the API endpoints were moved to their current opaali.telia.fi domain. Just after the hostname in Opaali API URLs comes either /production or /sandbox, which up to now was hardcoded as /production in the http_adapter source code.

(But notice that the authentication endpoint is common to both sandbox and production APIs so I couldn’t just rewrite all the URLs on the fly.)

I only needed to add one line to Config.java:

--- a/sample_applications/http_adapter/src/OpaaliAPI/Config.java
+++ b/sample_applications/http_adapter/src/OpaaliAPI/Config.java
@@ -44,6 +44,7 @@ public class Config {
         // set default config
         configSettings = new HashMap <String, String>();
         configSettings.put("API_HOST", "api.opaali.telia.fi");
+        configSettings.put("API_MODE", "production");
         serviceSettings = new HashMap <String, HashMap<String, String>>();
     }

and change one line in MessagingAPI.java:

--- a/sample_applications/http_adapter/src/OpaaliAPI/MessagingAPI.java
+++ b/sample_applications/http_adapter/src/OpaaliAPI/MessagingAPI.java
@@ -139,7 +139,7 @@ public class MessagingAPI {

         String[] MTTemplate = {
             // API request for sending MT messages
-            "POST https://${API_HOST}/production/messaging/v1/outbound/${SENDERADDRESS_ENCODED}/requests HTTP/1.1",
+            "POST https://${API_HOST}/${API_MODE}/messaging/v1/outbound/${SENDERADDRESS_ENCODED}/requests HTTP/1.1",
             "Host: ${API_HOST}",
             "Content-type: application/json",
             "Accept: application/json",

and now adding one line to config.txt switches the http_adapter to call the sandbox API instead:

# server port
port=8878
# API host name                
API_HOST=api.opaali.telia.fi
# sandbox or production (default)
API_MODE=sandbox

(…if there were more than just the Messaging API implemented in the http_adapter I would need to change the other URL templates too.)


I did not build a new binary release yet, because there will be more updates to the http_adapter after the current tests are finished - mostly fixes related to character sets in http-requests.


JPLa is a member of the Content Gateway (CGW) to Opaali migration team, specialising in programming related issues and API usage.