Chilkat Online Tools

GetRouteAnalysis Java Example

AWS Network Manager

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    // 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) {
        System.out.println("ConnectFailReason: " + rest.get_ConnectFailReason());
        System.out.println(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) {
        System.out.println(rest.lastErrorText());
        return;
        }

    int respStatusCode = rest.get_ResponseStatusCode();
    System.out.println("response status code = " + respStatusCode);
    if (respStatusCode != 200) {
        System.out.println("Response Header:");
        System.out.println(rest.responseHeader());
        System.out.println("Response Body:");
        System.out.println(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
    //   }
    // }
  }
}