Android Open Source - MobileConnectTestApp Process Discovery Token






From Project

Back to project page MobileConnectTestApp.

License

The source code is released under:

MIT License

If you think the Android project MobileConnectTestApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.gsma.android.xoperatorapidemo.activity.discovery;
/*  ww w . j  a v a2s  .  c  om*/
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.json.JSONObject;

import android.app.Activity;
import android.util.Log;

import com.gsma.android.xoperatorapidemo.utils.HttpUtils;
import com.gsma.android.xoperatorapidemo.utils.JsonUtils;

/*
 * this class handles the process in which a discovery token is used to obtain the operator endpoints.
 * a request is made to the Discovery Service to get the endpoints for the given discovery token
 */
class ProcessDiscoveryToken {
  private static final String TAG = "ProcessDiscoveryToken";

  /*
   * constructor requires a mccmnc from a previous stage of
   * interacting with the Discovery Service, the application API ConsumerKey
   * and the base URI of the DiscoveryAPI service
   */
  public static JSONObject start(Activity invokingActivity, String mccmnc, String consumerKey, String serviceUri) {

    JSONObject errorResponse = null;

    try {

      /*
       * the DiscoveryAPI base URI is used to request endpoints using the
       * discovery token
       */
      
      //http://dt.gsmaoneapiexchange.com/v1/discovery/apis?redirect_uri=http://gsma.com/oneapi&mcc_mnc=262_01
      String phase2Uri = serviceUri + "?mcc_mnc="
          + mccmnc;
      Log.d(TAG, "mccmnc = " + mccmnc);
      Log.d(TAG, "phase2Uri = " + phase2Uri);

      /*
       * get an instance of an HttpClient configured to use HTTP Basic
       * Authorization using the application ConsumerKey
       */
      HttpClient httpClient = HttpUtils.getHttpClient(phase2Uri,
          consumerKey);

      /*
       * execute an HTTP GET request on the Discovery Service
       */
      HttpGet httpRequest = new HttpGet(phase2Uri);
      httpRequest.addHeader("Accept", "application/json");
      HttpResponse httpResponse = httpClient.execute(httpRequest);

      /*
       * obtain the HTTP Response headers
       */
      HashMap<String, String> headerMap = HttpUtils
          .getHeaders(httpResponse);

      /*
       * retrieve the content type of the response (should be JSON), and
       * get the response body in the form of an InputStream so that the
       * endpoints can be read and OperatorID process started
       */
      String contentType = headerMap.get("content-type");

      HttpEntity httpEntity = httpResponse.getEntity();
      InputStream is = httpEntity.getContent();

      /*
       * read the endpoints 
       */
      errorResponse=DiscoveryProcessEndpoints.start(invokingActivity,
          contentType, httpResponse, is);

      /*
       * convert the various internal error types to displayable errors
       */
    } catch (ClientProtocolException e) {
      errorResponse = JsonUtils.simpleError("ClientProtocolException",
          "ClientProtocolException - " + e.getMessage());
    } catch (IOException e) {
      errorResponse = JsonUtils.simpleError("IOException",
          "IOException - " + e.getMessage());
    }
    return errorResponse;
  }


}




Java Source Code List

com.gsma.android.xoperatorapidemo.activity.MainActivity.java
com.gsma.android.xoperatorapidemo.activity.SettingsActivity.java
com.gsma.android.xoperatorapidemo.activity.discovery.ActiveDiscoveryTask.java
com.gsma.android.xoperatorapidemo.activity.discovery.DiscoveryProcessEndpoints.java
com.gsma.android.xoperatorapidemo.activity.discovery.DisplayDiscoveryWebsiteActivity.java
com.gsma.android.xoperatorapidemo.activity.discovery.PassiveDiscoveryTask.java
com.gsma.android.xoperatorapidemo.activity.discovery.ProcessDiscoveryToken.java
com.gsma.android.xoperatorapidemo.activity.identity.AuthorizationCompleteActivity.java
com.gsma.android.xoperatorapidemo.activity.identity.DisplayIdentityWebsiteActivity.java
com.gsma.android.xoperatorapidemo.activity.identity.OpenIDConnectAbstractActivity.java
com.gsma.android.xoperatorapidemo.activity.identity.RetrieveTokenTask.java
com.gsma.android.xoperatorapidemo.activity.identity.RetrieveUserinfoTask.java
com.gsma.android.xoperatorapidemo.discovery.Api.java
com.gsma.android.xoperatorapidemo.discovery.DeveloperOperatorSetting.java
com.gsma.android.xoperatorapidemo.discovery.DiscoveryData.java
com.gsma.android.xoperatorapidemo.discovery.DiscoveryDeveloperOperatorSettings.java
com.gsma.android.xoperatorapidemo.discovery.DiscoveryServingOperatorSettings.java
com.gsma.android.xoperatorapidemo.discovery.DiscoveryStartupSettings.java
com.gsma.android.xoperatorapidemo.discovery.LinkConstants.java
com.gsma.android.xoperatorapidemo.discovery.Link.java
com.gsma.android.xoperatorapidemo.discovery.Response.java
com.gsma.android.xoperatorapidemo.discovery.ServingOperatorSetting.java
com.gsma.android.xoperatorapidemo.identity.UserinfoAddress.java
com.gsma.android.xoperatorapidemo.identity.Userinfo.java
com.gsma.android.xoperatorapidemo.logo.LogoCacheItem.java
com.gsma.android.xoperatorapidemo.logo.LogoCache.java
com.gsma.android.xoperatorapidemo.logo.LogoLoaderTask.java
com.gsma.android.xoperatorapidemo.logo.LogoResponseArray.java
com.gsma.android.xoperatorapidemo.logo.LogoResponse.java
com.gsma.android.xoperatorapidemo.utils.HttpUtils.java
com.gsma.android.xoperatorapidemo.utils.JsonUtils.java
com.gsma.android.xoperatorapidemo.utils.KeyValuePair.java
com.gsma.android.xoperatorapidemo.utils.ParameterList.java
com.gsma.android.xoperatorapidemo.utils.PhoneState.java
com.gsma.android.xoperatorapidemo.utils.PhoneUtils.java
com.gsma.android.xoperatorapidemo.utils.PreferencesUtils.java