Chilkat Online Tools

GetRouteAnalysis Android Example

AWS Network Manager

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkRest rest = new CkRest();
    boolean success;

    CkAuthAws authAws = new CkAuthAws();
    authAws.put_AccessKey("AWS_ACCESS_KEY");
    authAws.put_SecretKey("AWS_SECRET_KEY");

    // Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
    authAws.put_Region("us-west-2");
    authAws.put_ServiceName("networkmanager");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://networkmanager.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect("networkmanager.us-west-2.amazonaws.com",443,true,true);
    if (success != true) {
        Log.i(TAG, "ConnectFailReason: " + String.valueOf(rest.get_ConnectFailReason()));
        Log.i(TAG, rest.lastErrorText());
        return;
        }

    rest.AddHeader("Content-Type","application/x-amz-json-1.1");
    rest.AddHeader("X-Amz-Target","GetRouteAnalysis");

    CkStringBuilder sbResponseBody = new CkStringBuilder();
    success = rest.FullRequestNoBodySb("GET","/global-networks/{globalNetworkId}/route-analyses/{routeAnalysisId}",sbResponseBody);
    if (success != true) {
        Log.i(TAG, rest.lastErrorText());
        return;
        }

    int respStatusCode = rest.get_ResponseStatusCode();
    Log.i(TAG, "response status code = " + String.valueOf(respStatusCode));
    if (respStatusCode != 200) {
        Log.i(TAG, "Response Header:");
        Log.i(TAG, rest.responseHeader());
        Log.i(TAG, "Response Body:");
        Log.i(TAG, sbResponseBody.getAsString());
        return;
        }

    CkJsonObject jResp = new CkJsonObject();
    jResp.LoadSb(sbResponseBody);

    // The following code parses the JSON response.
    // A sample JSON response is shown below the sample code.

    // Use this online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    String DestinationCidrBlock;
    String Definition;
    int IsMiddlebox;
    String NameTag;
    String RegisteredGatewayArn;
    String ResourceArn;
    String ResourceType;
    int Sequence;
    String ResourceDefinition;
    int ResourceIsMiddlebox;
    String ResourceNameTag;
    String ResourceRegisteredGatewayArn;
    String ResourceResourceArn;
    String ResourceResourceType;

    String IpAddress = jResp.stringOf("RouteAnalysis.Destination.IpAddress");
    String TransitGatewayArn = jResp.stringOf("RouteAnalysis.Destination.TransitGatewayArn");
    String TransitGatewayAttachmentArn = jResp.stringOf("RouteAnalysis.Destination.TransitGatewayAttachmentArn");
    String ReasonCode = jResp.stringOf("RouteAnalysis.ForwardPath.CompletionStatus.ReasonCode");
    String v_String = jResp.stringOf("RouteAnalysis.ForwardPath.CompletionStatus.ReasonContext.string");
    String ResultCode = jResp.stringOf("RouteAnalysis.ForwardPath.CompletionStatus.ResultCode");
    String GlobalNetworkId = jResp.stringOf("RouteAnalysis.GlobalNetworkId");
    int IncludeReturnPath = jResp.IntOf("RouteAnalysis.IncludeReturnPath");
    String OwnerAccountId = jResp.stringOf("RouteAnalysis.OwnerAccountId");
    String CompletionStatusReasonCode = jResp.stringOf("RouteAnalysis.ReturnPath.CompletionStatus.ReasonCode");
    String ReasonContextString = jResp.stringOf("RouteAnalysis.ReturnPath.CompletionStatus.ReasonContext.string");
    String CompletionStatusResultCode = jResp.stringOf("RouteAnalysis.ReturnPath.CompletionStatus.ResultCode");
    String RouteAnalysisId = jResp.stringOf("RouteAnalysis.RouteAnalysisId");
    String SourceIpAddress = jResp.stringOf("RouteAnalysis.Source.IpAddress");
    String SourceTransitGatewayArn = jResp.stringOf("RouteAnalysis.Source.TransitGatewayArn");
    String SourceTransitGatewayAttachmentArn = jResp.stringOf("RouteAnalysis.Source.TransitGatewayAttachmentArn");
    int StartTimestamp = jResp.IntOf("RouteAnalysis.StartTimestamp");
    String Status = jResp.stringOf("RouteAnalysis.Status");
    int UseMiddleboxes = jResp.IntOf("RouteAnalysis.UseMiddleboxes");
    int i = 0;
    int count_i = jResp.SizeOfArray("RouteAnalysis.ForwardPath.Path");
    while (i < count_i) {
        jResp.put_I(i);
        DestinationCidrBlock = jResp.stringOf("RouteAnalysis.ForwardPath.Path[i].DestinationCidrBlock");
        Definition = jResp.stringOf("RouteAnalysis.ForwardPath.Path[i].Resource.Definition");
        IsMiddlebox = jResp.IntOf("RouteAnalysis.ForwardPath.Path[i].Resource.IsMiddlebox");
        NameTag = jResp.stringOf("RouteAnalysis.ForwardPath.Path[i].Resource.NameTag");
        RegisteredGatewayArn = jResp.stringOf("RouteAnalysis.ForwardPath.Path[i].Resource.RegisteredGatewayArn");
        ResourceArn = jResp.stringOf("RouteAnalysis.ForwardPath.Path[i].Resource.ResourceArn");
        ResourceType = jResp.stringOf("RouteAnalysis.ForwardPath.Path[i].Resource.ResourceType");
        Sequence = jResp.IntOf("RouteAnalysis.ForwardPath.Path[i].Sequence");
        i = i + 1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("RouteAnalysis.ReturnPath.Path");
    while (i < count_i) {
        jResp.put_I(i);
        DestinationCidrBlock = jResp.stringOf("RouteAnalysis.ReturnPath.Path[i].DestinationCidrBlock");
        ResourceDefinition = jResp.stringOf("RouteAnalysis.ReturnPath.Path[i].Resource.Definition");
        ResourceIsMiddlebox = jResp.IntOf("RouteAnalysis.ReturnPath.Path[i].Resource.IsMiddlebox");
        ResourceNameTag = jResp.stringOf("RouteAnalysis.ReturnPath.Path[i].Resource.NameTag");
        ResourceRegisteredGatewayArn = jResp.stringOf("RouteAnalysis.ReturnPath.Path[i].Resource.RegisteredGatewayArn");
        ResourceResourceArn = jResp.stringOf("RouteAnalysis.ReturnPath.Path[i].Resource.ResourceArn");
        ResourceResourceType = jResp.stringOf("RouteAnalysis.ReturnPath.Path[i].Resource.ResourceType");
        Sequence = jResp.IntOf("RouteAnalysis.ReturnPath.Path[i].Sequence");
        i = i + 1;
        }

    // A sample JSON response body parsed by the above code:

    // {
    //   "RouteAnalysis": {
    //     "Destination": {
    //       "IpAddress": "string",
    //       "TransitGatewayArn": "string",
    //       "TransitGatewayAttachmentArn": "string"
    //     },
    //     "ForwardPath": {
    //       "CompletionStatus": {
    //         "ReasonCode": "string",
    //         "ReasonContext": {
    //           "string": "string"
    //         },
    //         "ResultCode": "string"
    //       },
    //       "Path": [
    //         {
    //           "DestinationCidrBlock": "string",
    //           "Resource": {
    //             "Definition": "string",
    //             "IsMiddlebox": boolean,
    //             "NameTag": "string",
    //             "RegisteredGatewayArn": "string",
    //             "ResourceArn": "string",
    //             "ResourceType": "string"
    //           },
    //           "Sequence": number
    //         }
    //       ]
    //     },
    //     "GlobalNetworkId": "string",
    //     "IncludeReturnPath": boolean,
    //     "OwnerAccountId": "string",
    //     "ReturnPath": {
    //       "CompletionStatus": {
    //         "ReasonCode": "string",
    //         "ReasonContext": {
    //           "string": "string"
    //         },
    //         "ResultCode": "string"
    //       },
    //       "Path": [
    //         {
    //           "DestinationCidrBlock": "string",
    //           "Resource": {
    //             "Definition": "string",
    //             "IsMiddlebox": boolean,
    //             "NameTag": "string",
    //             "RegisteredGatewayArn": "string",
    //             "ResourceArn": "string",
    //             "ResourceType": "string"
    //           },
    //           "Sequence": number
    //         }
    //       ]
    //     },
    //     "RouteAnalysisId": "string",
    //     "Source": {
    //       "IpAddress": "string",
    //       "TransitGatewayArn": "string",
    //       "TransitGatewayAttachmentArn": "string"
    //     },
    //     "StartTimestamp": number,
    //     "Status": "string",
    //     "UseMiddleboxes": boolean
    //   }
    // }

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}