• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java BMSClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient的典型用法代码示例。如果您正苦于以下问题:Java BMSClient类的具体用法?Java BMSClient怎么用?Java BMSClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



BMSClient类属于com.ibm.mobilefirstplatform.clientsdk.android.core.api包,在下文中一共展示了BMSClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: onCreate

import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient; //导入依赖的package包/类
@Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);

     bmsClient = BMSClient.getInstance();
     try {
//initialize SDK with IBM Bluemix application ID and route
//You can find your backendRoute and backendGUID in the Mobile Options section on top of your Bluemix application dashboard
         //TODO: Please replace <APPLICATION_ROUTE> with a valid ApplicationRoute and <APPLICATION_ID> with a valid ApplicationId
         bmsClient.initialize(this, "<APPLICATION_ROUTE>", "<APPLICATION_ID>", BMSClient.REGION_US_SOUTH);
     } catch (MalformedURLException e) {
         throw new RuntimeException(e);
     }

     // Init UI
     initListView();
     initSwipeRefresh();

     // Must create and set default MCA Auth Manager in order for the delete endpoint to work. This is new in core version 2.0.
     MCAAuthorizationManager MCAAuthMan = MCAAuthorizationManager.createInstance(this);

     bmsClient.setAuthorizationManager(MCAAuthMan);
 }
 
开发者ID:ibm-bluemix-mobile-services,项目名称:bms-samples-android-hellotodo,代码行数:25,代码来源:MainActivity.java


示例2: performInitializations

import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient; //导入依赖的package包/类
private void performInitializations() {
	try {
		BMSClient.getInstance().initialize(getApplicationContext(), backendURL, backendGUID, BMSClient.REGION_US_SOUTH);
	} catch (MalformedURLException e) {
		e.printStackTrace();
	}

	MCAAuthorizationManager mcaAuthorizationManager = MCAAuthorizationManager.createInstance(this.getApplicationContext());
	mcaAuthorizationManager.registerAuthenticationListener(customRealm, new MyChallengeHandler());

	// to make the authorization happen next time
	mcaAuthorizationManager.clearAuthorizationData();
	BMSClient.getInstance().setAuthorizationManager(mcaAuthorizationManager);

	Logger.setLogLevel(Logger.LEVEL.DEBUG);
	Logger.setSDKDebugLoggingEnabled(true);
}
 
开发者ID:ibm-bluemix-mobile-services,项目名称:bms-clientsdk-android-core,代码行数:18,代码来源:MainActivity.java


示例3: clearAuthorizationData

import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient; //导入依赖的package包/类
/**
 * Clear the local stored authorization data
 */
public void clearAuthorizationData() {
    preferences.accessToken.clear();
    preferences.idToken.clear();
    preferences.userIdentity.clear();
    if (BMSClient.getInstance() != null && BMSClient.getInstance().getCookieManager() != null) {
        CookieStore cookieStore = BMSClient.getInstance().getCookieManager().getCookieStore();
        if(cookieStore != null) {
            for (URI uri : cookieStore.getURIs()) {
                for (HttpCookie cookie : cookieStore.get(uri)) {
                    if (cookie.getName().equals(TAI_COOKIE_NAME)) {
                        cookieStore.remove(uri, cookie);
                    }
                }
            }
        }
    }
}
 
开发者ID:ibm-bluemix-mobile-services,项目名称:bms-clientsdk-android-core,代码行数:21,代码来源:MCAAuthorizationManager.java


示例4: startHandleChallenges

import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient; //导入依赖的package包/类
/**
 * Handles authentication challenges.
 *
 * @param jsonChallenges Collection of challenges.
 * @param response       Server response.
 */
private void startHandleChallenges(JSONObject jsonChallenges, Response response) {
    ArrayList<String> challenges = getRealmsFromJson(jsonChallenges);

    MCAAuthorizationManager authManager = (MCAAuthorizationManager) BMSClient.getInstance().getAuthorizationManager();

    if (isAuthorizationRequired(response)) {
        setExpectedAnswers(challenges);
    }

    for (String realm : challenges) {
        ChallengeHandler handler = authManager.getChallengeHandler(realm);
        if (handler != null) {
            JSONObject challenge = jsonChallenges.optJSONObject(realm);
            handler.handleChallenge(this, challenge, context);
        } else {
            throw new RuntimeException("Challenge handler for realm is not found: " + realm);
        }
    }
}
 
开发者ID:ibm-bluemix-mobile-services,项目名称:bms-clientsdk-android-core,代码行数:26,代码来源:AuthorizationRequestManager.java


示例5: processFailures

import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient; //导入依赖的package包/类
/**
 * Processes authentication failures.
 *
 * @param jsonFailures Collection of authentication failures.
 */
private void processFailures(JSONObject jsonFailures) {
    if (jsonFailures == null) {
        return;
    }
    MCAAuthorizationManager authManager = (MCAAuthorizationManager) BMSClient.getInstance().getAuthorizationManager();

    ArrayList<String> challenges = getRealmsFromJson(jsonFailures);
    for (String realm : challenges) {
        ChallengeHandler handler = authManager.getChallengeHandler(realm);
        if (handler != null) {
            JSONObject challenge = jsonFailures.optJSONObject(realm);
            handler.handleFailure(context, challenge);
        } else {
            logger.error("Challenge handler for realm is not found: " + realm);
        }
    }
}
 
开发者ID:ibm-bluemix-mobile-services,项目名称:bms-clientsdk-android-core,代码行数:23,代码来源:AuthorizationRequestManager.java


示例6: processSuccesses

import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient; //导入依赖的package包/类
/**
 * Processes authentication successes.
 *
 * @param jsonSuccesses Collection of authentication successes.
 */
private void processSuccesses(JSONObject jsonSuccesses) {
    if (jsonSuccesses == null) {
        return;
    }

    MCAAuthorizationManager authManager = (MCAAuthorizationManager) BMSClient.getInstance().getAuthorizationManager();
    ArrayList<String> challenges = getRealmsFromJson(jsonSuccesses);
    for (String realm : challenges) {
        ChallengeHandler handler = authManager.getChallengeHandler(realm);
        if (handler != null) {
            JSONObject challenge = jsonSuccesses.optJSONObject(realm);
            handler.handleSuccess(context, challenge);
        } else {
            logger.error("Challenge handler for realm is not found: " + realm);
        }
    }
}
 
开发者ID:ibm-bluemix-mobile-services,项目名称:bms-clientsdk-android-core,代码行数:23,代码来源:AuthorizationRequestManager.java


示例7: onCreate

import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TextView buttonText = (TextView) findViewById(R.id.button_text);

    // initialize SDK with IBM Bluemix application ID and REGION, TODO: Update region if not using Bluemix US SOUTH
    BMSClient.getInstance().initialize(this, BMSClient.REGION_US_SOUTH);

    // Runtime Permission handling required for SDK 23+
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {
        buttonText.setClickable(false);
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.GET_ACCOUNTS}, PERMISSION_REQUEST_GET_ACCOUNTS);
    }

    // Register this activity as the default auth listener
    Log.i(TAG, "Registering Google Auth Listener");

    // Must create MCA auth manager before registering Google auth Manager
    //TODO: Please replace <APP_GUID> with a valid Application GUID from your MCA instance
    MCAAuthorizationManager MCAAuthMan = MCAAuthorizationManager.createInstance(this, "<APP_GUID>");
    BMSClient.getInstance().setAuthorizationManager(MCAAuthMan);
    GoogleAuthenticationManager.getInstance().register(this);
}
 
开发者ID:ibm-bluemix-mobile-services,项目名称:bms-samples-android-helloauthentication,代码行数:26,代码来源:MainActivity.java


示例8: pingBluemix

import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient; //导入依赖的package包/类
/**
 * Called when ping bluemix button is pressed.
 * Attempts to access protected Bluemix backend, kicking off the Authentication login prompt.
 * @param view the button pressed.
 */
public void pingBluemix(View view) {

    TextView buttonText = (TextView) findViewById(R.id.button_text);
    buttonText.setClickable(false);

    TextView responseText = (TextView) findViewById(R.id.response_text);
    responseText.setText(R.string.Connecting);

    Log.i(TAG, "Attempting to Connect");

    // Testing the connection to Bluemix by attempting to obtain an authorization header, using this Activity to handle the response.
    BMSClient.getInstance().getAuthorizationManager().obtainAuthorization(this, this);
    // As an alternative, you can send a Get request using the Bluemix Mobile Services Core sdk to send the request to a protected resource on the Node.js application to kick off Authentication. See example below:
    // new Request(<YOUR_BLUEMIX_APP_ROUTE> + "/protected", Request.GET).send(this, this); TODO: Replace <YOUR_BLUEMIX_APP_ROUTE> with your appRoute on Bluemix
    // The Node.js code was provided in the MobileFirst Services Starter boilerplate.
}
 
开发者ID:ibm-bluemix-mobile-services,项目名称:bms-samples-android-helloauthentication,代码行数:22,代码来源:MainActivity.java


示例9: initialize

import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient; //导入依赖的package包/类
/**
 * MFPPush Intitialization method with clientSecret and Push App GUID.
 * <p/>
 *
 * @param context          this is the Context of the application from getApplicationContext()
 * @param appGUID          The unique ID of the Push service instance that the application must connect to.
 * @param pushClientSecret ClientSecret from the push service.
 * @param options - The MFPPushNotificationOptions with the default parameters
 *
 */
public void initialize(Context context, String appGUID, String pushClientSecret,MFPPushNotificationOptions options) {

  try {
    if (MFPPushUtils.validateString(pushClientSecret) && MFPPushUtils.validateString(appGUID)) {
      // Get the applicationId and backend route from core
      clientSecret = pushClientSecret;
      applicationId = appGUID;
      appContext = context.getApplicationContext();
      isInitialized = true;
      validateAndroidContext();

      //Storing the messages url and the client secret.
      //This is because when the app is not running and notification is dismissed/cleared,
      //there wont be applicationId and clientSecret details available to
      //MFPPushNotificationDismissHandler.
      SharedPreferences sharedPreferences = appContext.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
      MFPPushUtils.storeContentInSharedPreferences(sharedPreferences, MFPPush.PREFS_MESSAGES_URL, buildMessagesURL());
      MFPPushUtils.storeContentInSharedPreferences(sharedPreferences, MFPPush.PREFS_MESSAGES_URL_CLIENT_SECRET, clientSecret);
      MFPPushUtils.storeContentInSharedPreferences(sharedPreferences, PREFS_BMS_REGION, BMSClient.getInstance().getBluemixRegionSuffix());

      if (options != null){
        setNotificationOptions(context,options);
        this.regId = options.getDeviceid();
      }
    } else {
      logger.error("MFPPush:initialize() - An error occured while initializing MFPPush service. Add a valid ClientSecret and push service instance ID Value");
      throw new MFPPushException("MFPPush:initialize() - An error occured while initializing MFPPush service. Add a valid ClientSecret and push service instance ID Value", INITIALISATION_ERROR);
    }

  } catch (Exception e) {
    logger.error("MFPPush:initialize() - An error occured while initializing MFPPush service.");
    throw new RuntimeException(e);
  }
}
 
开发者ID:ibm-bluemix-mobile-services,项目名称:bms-clientsdk-android-push,代码行数:45,代码来源:MFPPush.java


示例10: computeRegId

import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient; //导入依赖的package包/类
private void computeRegId() {
  logger.debug("MFPPush:computeRegId() Computing device's registrationId");

  if (regId == null) {
    AuthorizationManager authorizationManager = BMSClient.getInstance().getAuthorizationManager();
    regId = authorizationManager.getDeviceIdentity().getId();
    logger.debug("MFPPush:computeRegId() - DeviceId obtained from AuthorizationManager is : " + regId);
  }
}
 
开发者ID:ibm-bluemix-mobile-services,项目名称:bms-clientsdk-android-push,代码行数:10,代码来源:MFPPush.java


示例11: onMessageReceived

import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient; //导入依赖的package包/类
@Override
public void onMessageReceived(RemoteMessage message) {
    String from = message.getFrom();

    Map<String, String> data = message.getData();
    JSONObject dataPayload = new JSONObject(data);
    logger.info("MFPPushIntentService:onMessageReceived() - New notification received. Payload is: "+ dataPayload.toString());

    String messageId = getMessageId(dataPayload);
    String action = data.get(ACTION);

    if (action != null && action.equals(DISMISS_NOTIFICATION)) {
        logger.debug("MFPPushIntentService:handleMessageIntent() - Dismissal message from GCM Server");
        dismissNotification(data.get(NID).toString());
    } else {
        Context context = getApplicationContext();
        String regionSuffix = BMSClient.getInstance().getBluemixRegionSuffix();
        if(regionSuffix == null) {
            String region = MFPPushUtils.getContentFromSharedPreferences(context, PREFS_BMS_REGION);
            BMSClient.getInstance().initialize(context, region);
        }
        MFPPush.getInstance().changeStatus(messageId, MFPPushNotificationStatus.RECEIVED);
        if(isAppForeground()) {
            Intent intent = new Intent(MFPPushUtils.getIntentPrefix(context)
                                       + GCM_MESSAGE);
            intent.putExtra(GCM_EXTRA_MESSAGE, new MFPInternalPushMessage(dataPayload));
            getApplicationContext().sendBroadcast(intent);
        } else {
            MFPPush.getInstance().sendMessageDeliveryStatus(context, messageId, MFPPushConstants.SEEN);
            onUnhandled(context, dataPayload);
        }

    }
}
 
开发者ID:ibm-bluemix-mobile-services,项目名称:bms-clientsdk-android-push,代码行数:35,代码来源:MFPPushIntentService.java


示例12: MFPPushUrlBuilder

import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient; //导入依赖的package包/类
public MFPPushUrlBuilder(String applicationId) {
	if (MFPPush.overrideServerHost != null){
		pwUrl_.append(MFPPush.overrideServerHost);
		reWriteDomain = "";
	} else {
		pwUrl_.append(BMSClient.getInstance().getDefaultProtocol());
		pwUrl_.append("://");
		pwUrl_.append(IMFPUSH);
		String regionSuffix = BMSClient.getInstance().getBluemixRegionSuffix();
           if (regionSuffix != null && regionSuffix.contains(STAGE_TEST) || regionSuffix.contains(STAGE_DEV)){
               pwUrl_.append(STAGE_PROD_URL);
               if (regionSuffix.contains(STAGE_TEST)) {
                   reWriteDomain = STAGE_TEST_URL;
               }
               else {
                   reWriteDomain = STAGE_DEV_URL;
               }

           }else {
               pwUrl_.append(BMSClient.getInstance().getBluemixRegionSuffix());
               reWriteDomain = "";
           }
	}

	pwUrl_.append(FORWARDSLASH);
	pwUrl_.append(IMFPUSH);
	pwUrl_.append(FORWARDSLASH);
	pwUrl_.append(V1);
	pwUrl_.append(FORWARDSLASH);
	pwUrl_.append(APPS);
	pwUrl_.append(FORWARDSLASH);
	pwUrl_.append(applicationId);
	pwUrl_.append(FORWARDSLASH);

}
 
开发者ID:ibm-bluemix-mobile-services,项目名称:bms-clientsdk-android-push,代码行数:36,代码来源:MFPPushUrlBuilder.java


示例13: createInstance

import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient; //导入依赖的package包/类
/**
 * Init singleton instance with context
 * @param context Application context
 * @return The singleton instance
 */
public static synchronized MCAAuthorizationManager createInstance(Context context) {
    if (instance == null) {
        instance = new MCAAuthorizationManager(context.getApplicationContext());

        instance.bluemixRegionSuffix = BMSClient.getInstance().getBluemixRegionSuffix();
        instance.tenantId = BMSClient.getInstance().getBluemixAppGUID();

        AuthorizationRequest.setup();
    }
    return instance;
}
 
开发者ID:ibm-bluemix-mobile-services,项目名称:bms-clientsdk-android-core,代码行数:17,代码来源:MCAAuthorizationManager.java


示例14: onCreate

import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // initialize SDK with IBM Bluemix application region, add Bluemix application route for connectivity testing
    // You can find your backendRoute and backendGUID in the Mobile Options section on top of your Bluemix MCA dashboard
    // TODO: Please replace <APPLICATION_ROUTE> with a valid ApplicationRoute and change region appropriately
    BMSClient.getInstance().initialize(this, BMSClient.REGION_US_SOUTH);
    appRoute = "<APPLICATION_ROUTE>";
}
 
开发者ID:ibm-bluemix-mobile-services,项目名称:bms-samples-android-helloworld,代码行数:12,代码来源:MainActivity.java


示例15: onCreate

import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // initialize core SDK with IBM Bluemix application Region, TODO: Update region if not using Bluemix US SOUTH
    BMSClient.getInstance().initialize(this, BMSClient.REGION_US_SOUTH);

    // Grabs push client sdk instance
    push = MFPPush.getInstance();
    // Initialize Push client
    // You can find your App Guid and Client Secret by navigating to the Configure section of your Push dashboard, click Mobile Options (Upper Right Hand Corner)
    // TODO: Please replace <APP_GUID> and <CLIENT_SECRET> with a valid App GUID and Client Secret from the Push dashboard Mobile Options
    push.initialize(this, "<APP_GUID>", "<CLIENT_SECRET>");

    // Create notification listener and enable pop up notification when a message is received
    notificationListener = new MFPPushNotificationListener() {
        @Override
        public void onReceive(final MFPSimplePushNotification message) {
            Log.i(TAG, "Received a Push Notification: " + message.toString());
            runOnUiThread(new Runnable() {
                public void run() {
                    new android.app.AlertDialog.Builder(MainActivity.this)
                            .setTitle("Received a Push Notification")
                            .setMessage(message.getAlert())
                            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int whichButton) {
                                }
                            })
                            .show();
                }
            });
        }
    };

}
 
开发者ID:ibm-bluemix-mobile-services,项目名称:bms-samples-android-hellopush,代码行数:37,代码来源:MainActivity.java


示例16: onCreate

import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Initialize the Watson Conversation Service and instantiate the Message Log.
    conversationService = new ConversationService(ConversationService.VERSION_DATE_2016_07_11);
    conversationService.setUsernameAndPassword(getString(R.string.watson_conversation_username),
            getString(R.string.watson_conversation_password));
    conversationLog = new ArrayList<>();

    // If we have a savedInstanceState, recover the previous Context and Message Log.
    if (savedInstanceState != null) {
        conversationContext = (Map<String, Object>) savedInstanceState.getSerializable("context");
        conversationLog = (ArrayList<ConversationMessage>) savedInstanceState.getSerializable("backlog");

        // Repopulate the UI with the previous Messages.
        if (conversationLog != null) {
            for (ConversationMessage message : conversationLog) {
                addMessageFromUser(message);
            }
        }

        final ScrollView scrollView = (ScrollView) findViewById(R.id.message_scrollview);
        scrollView.scrollTo(0, scrollView.getBottom());
    } else {
        // Validate that the user's credentials are valid and that we can continue.
        // This also kicks off the first Conversation Task to obtain the intro message from Watson.
        ValidateCredentialsTask vct = new ValidateCredentialsTask();
        vct.execute();
    }

    ImageButton sendButton = (ImageButton) findViewById(R.id.send_button);
    sendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            TextView entryText = (TextView) findViewById(R.id.entry_text);
            String text = entryText.getText().toString();

            if (!text.isEmpty()) {
                // Add the message to the UI.
                addMessageFromUser(new ConversationMessage(text, USER_USER));

                // Record the message in the conversation log.
                conversationLog.add(new ConversationMessage(text, USER_USER));

                // Send the message to Watson Conversation.
                ConversationTask ct = new ConversationTask();
                ct.execute(text);

                entryText.setText("");
            }
        }
    });

    // Core SDK must be initialized to interact with Bluemix Mobile services.
    BMSClient.getInstance().initialize(getApplicationContext(), BMSClient.REGION_UK);


}
 
开发者ID:nizamudeenms,项目名称:mybotproject-Android,代码行数:64,代码来源:MainActivity.java


示例17: sendRequest

import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient; //导入依赖的package包/类
/**
  * Assembles the request path from root and path to authorization endpoint and sends the request.
  *
  * @param path    Path to authorization endpoint
  * @param options BaseRequest options
  * @throws IOException
  * @throws JSONException
  */
 public void sendRequest(String path, RequestOptions options) throws IOException, JSONException {
     String rootUrl;

     if (path == null) {
         throw new IllegalArgumentException("'path' parameter can't be null.");
     }

     if (path.indexOf(BMSClient.HTTP_SCHEME) == 0 && path.contains(":")) {
         // request using full path, split the URL to root and path
         URL url = new URL(path);
         path = url.getPath();
         rootUrl = url.toString().replace(path, "");
     } else {
         String MCATenantId = MCAAuthorizationManager.getInstance().getTenantId();
         if(MCATenantId == null){
             MCATenantId = BMSClient.getInstance().getBluemixAppGUID();
         }
         String bluemixRegionSuffix = MCAAuthorizationManager.getInstance().getBluemixRegionSuffix();
         if(bluemixRegionSuffix == null){
             bluemixRegionSuffix = BMSClient.getInstance().getBluemixRegionSuffix();
         }
         // "path" is a relative
String serverHost = BMSClient.getInstance().getDefaultProtocol()
				+ "://"
				+ AUTH_SERVER_NAME
				+ bluemixRegionSuffix;

if (overrideServerHost!=null)
	serverHost = overrideServerHost;

         rootUrl = serverHost
                 + "/"
                 + AUTH_SERVER_NAME
                 + "/"
                 + AUTH_PATH
                 + MCATenantId;
     }

     sendRequestInternal(rootUrl, path, options);
 }
 
开发者ID:ibm-bluemix-mobile-services,项目名称:bms-clientsdk-android-core,代码行数:49,代码来源:AuthorizationRequestManager.java


示例18: sendRequestInternal

import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient; //导入依赖的package包/类
/**
 * Builds an authorization request and sends it. It also caches the request url and request options in
 * order to be able to re-send the request when authorization challenges have been handled.
 *
 * @param rootUrl Root of authorization server.
 * @param path    Path to authorization endpoint.
 * @param options BaseRequest options.
 * @throws IOException
 * @throws JSONException
 */
private void sendRequestInternal(String rootUrl, String path, RequestOptions options) throws IOException, JSONException {
    logger.debug("Sending request to root: " + rootUrl + " with path: " + path);

    // create default options object with GET request method.
    if (options == null) {
        options = new RequestOptions();
    }

    // used to resend request
    this.requestPath = Utils.concatenateUrls(rootUrl, path);
    this.requestOptions = options;

    AuthorizationRequest request = new AuthorizationRequest(this.requestPath, options.requestMethod);

    if (options.timeout != 0) {
        request.setTimeout(options.timeout);
    } else {
        request.setTimeout(BMSClient.getInstance().getDefaultTimeout());
    }

    if (options.headers != null) {
        for (Map.Entry<String, String> entry : options.headers.entrySet()) {
            request.addHeader(entry.getKey(), entry.getValue());
        }
    }

    if (answers != null) {
        // 0 means no spaces in the generated string
        String answer = answers.toString(0);

        String authorizationHeaderValue = String.format("Bearer %s", answer.replace("\n", ""));
        request.addHeader("Authorization", authorizationHeaderValue);
        logger.debug("Added authorization header to request: " + authorizationHeaderValue);
    }

    if (Request.GET.equalsIgnoreCase(options.requestMethod)) {
        request.setQueryParameters(options.parameters);
        request.send(this);
    } else {
        request.send(options.parameters, this);
    }
}
 
开发者ID:ibm-bluemix-mobile-services,项目名称:bms-clientsdk-android-core,代码行数:53,代码来源:AuthorizationRequestManager.java


示例19: buildRewriteDomain

import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient; //导入依赖的package包/类
/**
 * Builds rewrite domain from backend route url.
 *
 * @param backendRoute Backend route.
 * @param subzone      Subzone
 * @return Rewrite domain.
 * @throws MalformedURLException if backendRoute parameter has invalid format.
 */
public static String buildRewriteDomain(String backendRoute, String subzone) throws MalformedURLException {
    if (backendRoute == null || backendRoute.isEmpty()) {
        logger.error("Backend route can't be null.");
        return null;
    }

    String applicationRoute = backendRoute;

    if (!applicationRoute.startsWith(BMSClient.HTTP_SCHEME)) {
        applicationRoute = String.format("%s://%s", BMSClient.HTTPS_SCHEME, applicationRoute);
    } else if (!applicationRoute.startsWith(BMSClient.HTTPS_SCHEME) && applicationRoute.contains(BLUEMIX_NAME)) {
        applicationRoute = applicationRoute.replace(BMSClient.HTTP_SCHEME, BMSClient.HTTPS_SCHEME);
    }

    URL url = new URL(applicationRoute);

    String host = url.getHost();
    String rewriteDomain;
    String regionInDomain = "ng";
    int port = url.getPort();

    String serviceUrl = String.format("%s://%s", url.getProtocol(), host);

    if (port != 0) {
        serviceUrl += ":" + String.valueOf(port);
    }

    String[] hostElements = host.split("\\.");

    if (!serviceUrl.contains(STAGE1_NAME)) {
        // Multi-region: myApp.eu-gb.mybluemix.net
        // US: myApp.mybluemix.net
        if (hostElements.length == 4) {
            regionInDomain = hostElements[hostElements.length - 3];
        }

        // this is production, because STAGE1 is not found
        // Multi-Region Eg: eu-gb.bluemix.net
        // US Eg: ng.bluemix.net
        rewriteDomain = String.format("%s.%s", regionInDomain, BLUEMIX_DOMAIN);
    } else {
        // Multi-region: myApp.stage1.eu-gb.mybluemix.net
        // US: myApp.stage1.mybluemix.net
        if (hostElements.length == 5) {
            regionInDomain = hostElements[hostElements.length - 3];
        }

        if (subzone != null && !subzone.isEmpty()) {
            // Multi-region Dev subzone Eg: stage1-Dev.eu-gb.bluemix.net
            // US Dev subzone Eg: stage1-Dev.ng.bluemix.net
            rewriteDomain = String.format("%s-%s.%s.%s", STAGE1_NAME, subzone, regionInDomain, BLUEMIX_DOMAIN);
        } else {
            // Multi-region Eg: stage1.eu-gb.bluemix.net
            // US  Eg: stage1.ng.bluemix.net
            rewriteDomain = String.format("%s.%s.%s", STAGE1_NAME, regionInDomain, BLUEMIX_DOMAIN);
        }
    }

    return rewriteDomain;
}
 
开发者ID:ibm-bluemix-mobile-services,项目名称:bms-clientsdk-android-core,代码行数:69,代码来源:Utils.java


示例20: convertRelativeURLToBluemixAbsolute

import com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient; //导入依赖的package包/类
private String convertRelativeURLToBluemixAbsolute(String url) {
    String appRoute = BMSClient.getInstance().getBluemixAppRoute();

    return appRoute + url;
}
 
开发者ID:ibm-bluemix-mobile-services,项目名称:bms-clientsdk-android-core,代码行数:6,代码来源:BaseRequest.java



注:本文中的com.ibm.mobilefirstplatform.clientsdk.android.core.api.BMSClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java InventoryCloseEvent类代码示例发布时间:2022-05-22
下一篇:
Java VKUIHelper类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap