Chilkat Online Tools

GetServerDetails unicodeCpp Example

Migration Hub Strategy Recommendations

#include <CkRestW.h>
#include <CkAuthAwsW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>

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

    CkRestW rest;
    bool success;

    CkAuthAwsW authAws;
    authAws.put_AccessKey(L"AWS_ACCESS_KEY");
    authAws.put_SecretKey(L"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(L"us-west-2");
    authAws.put_ServiceName(L"migrationhub-strategy");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://migrationhub-strategy.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect(L"migrationhub-strategy.us-west-2.amazonaws.com",443,true,true);
    if (success != true) {
        wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

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

    CkStringBuilderW sbResponseBody;
    success = rest.FullRequestNoBodySb(L"GET",L"/get-server-details/{serverId}",sbResponseBody);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    int respStatusCode = rest.get_ResponseStatusCode();
    wprintf(L"response status code = %d\n",respStatusCode);
    if (respStatusCode != 200) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",rest.responseHeader());
        wprintf(L"Response Body:\n");
        wprintf(L"%s\n",sbResponseBody.getAsString());
        return;
    }

    CkJsonObjectW jResp;
    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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
    // See this example explaining how this memory should be used: const char * functions.

    const wchar_t *id = 0;
    const wchar_t *name = 0;
    int count;
    const wchar_t *strategy = 0;
    const wchar_t *severity = 0;
    const wchar_t *interfaceName = 0;
    const wchar_t *ipAddress = 0;
    const wchar_t *macAddress = 0;
    const wchar_t *netMask = 0;

    const wchar_t *nextToken = jResp.stringOf(L"nextToken");
    const wchar_t *S3Bucket = jResp.stringOf(L"serverDetail.antipatternReportS3Object.s3Bucket");
    const wchar_t *S3key = jResp.stringOf(L"serverDetail.antipatternReportS3Object.s3key");
    const wchar_t *AntipatternReportStatus = jResp.stringOf(L"serverDetail.antipatternReportStatus");
    const wchar_t *AntipatternReportStatusMessage = jResp.stringOf(L"serverDetail.antipatternReportStatusMessage");
    const wchar_t *DataCollectionStatus = jResp.stringOf(L"serverDetail.dataCollectionStatus");
    const wchar_t *Id = jResp.stringOf(L"serverDetail.id");
    int LastAnalyzedTimestamp = jResp.IntOf(L"serverDetail.lastAnalyzedTimestamp");
    const wchar_t *Name = jResp.stringOf(L"serverDetail.name");
    const wchar_t *Strategy = jResp.stringOf(L"serverDetail.recommendationSet.strategy");
    const wchar_t *TargetDestination = jResp.stringOf(L"serverDetail.recommendationSet.targetDestination");
    const wchar_t *Description = jResp.stringOf(L"serverDetail.recommendationSet.transformationTool.description");
    const wchar_t *TransformationToolName = jResp.stringOf(L"serverDetail.recommendationSet.transformationTool.name");
    const wchar_t *TranformationToolInstallationLink = jResp.stringOf(L"serverDetail.recommendationSet.transformationTool.tranformationToolInstallationLink");
    const wchar_t *ServerType = jResp.stringOf(L"serverDetail.serverType");
    const wchar_t *StatusMessage = jResp.stringOf(L"serverDetail.statusMessage");
    const wchar_t *CpuArchitecture = jResp.stringOf(L"serverDetail.systemInfo.cpuArchitecture");
    const wchar_t *FileSystemType = jResp.stringOf(L"serverDetail.systemInfo.fileSystemType");
    const wchar_t *v_Type = jResp.stringOf(L"serverDetail.systemInfo.osInfo.type");
    const wchar_t *Version = jResp.stringOf(L"serverDetail.systemInfo.osInfo.version");
    int i = 0;
    int count_i = jResp.SizeOfArray(L"associatedApplications");
    while (i < count_i) {
        jResp.put_I(i);
        id = jResp.stringOf(L"associatedApplications[i].id");
        name = jResp.stringOf(L"associatedApplications[i].name");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"serverDetail.applicationComponentStrategySummary");
    while (i < count_i) {
        jResp.put_I(i);
        count = jResp.IntOf(L"serverDetail.applicationComponentStrategySummary[i].count");
        strategy = jResp.stringOf(L"serverDetail.applicationComponentStrategySummary[i].strategy");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"serverDetail.listAntipatternSeveritySummary");
    while (i < count_i) {
        jResp.put_I(i);
        count = jResp.IntOf(L"serverDetail.listAntipatternSeveritySummary[i].count");
        severity = jResp.stringOf(L"serverDetail.listAntipatternSeveritySummary[i].severity");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"serverDetail.systemInfo.networkInfoList");
    while (i < count_i) {
        jResp.put_I(i);
        interfaceName = jResp.stringOf(L"serverDetail.systemInfo.networkInfoList[i].interfaceName");
        ipAddress = jResp.stringOf(L"serverDetail.systemInfo.networkInfoList[i].ipAddress");
        macAddress = jResp.stringOf(L"serverDetail.systemInfo.networkInfoList[i].macAddress");
        netMask = jResp.stringOf(L"serverDetail.systemInfo.networkInfoList[i].netMask");
        i = i + 1;
    }

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

    // {
    //   "associatedApplications": [
    //     {
    //       "id": "string",
    //       "name": "string"
    //     }
    //   ],
    //   "nextToken": "string",
    //   "serverDetail": {
    //     "antipatternReportS3Object": {
    //       "s3Bucket": "string",
    //       "s3key": "string"
    //     },
    //     "antipatternReportStatus": "string",
    //     "antipatternReportStatusMessage": "string",
    //     "applicationComponentStrategySummary": [
    //       {
    //         "count": number,
    //         "strategy": "string"
    //       }
    //     ],
    //     "dataCollectionStatus": "string",
    //     "id": "string",
    //     "lastAnalyzedTimestamp": number,
    //     "listAntipatternSeveritySummary": [
    //       {
    //         "count": number,
    //         "severity": "string"
    //       }
    //     ],
    //     "name": "string",
    //     "recommendationSet": {
    //       "strategy": "string",
    //       "targetDestination": "string",
    //       "transformationTool": {
    //         "description": "string",
    //         "name": "string",
    //         "tranformationToolInstallationLink": "string"
    //       }
    //     },
    //     "serverType": "string",
    //     "statusMessage": "string",
    //     "systemInfo": {
    //       "cpuArchitecture": "string",
    //       "fileSystemType": "string",
    //       "networkInfoList": [
    //         {
    //           "interfaceName": "string",
    //           "ipAddress": "string",
    //           "macAddress": "string",
    //           "netMask": "string"
    //         }
    //       ],
    //       "osInfo": {
    //         "type": "string",
    //         "version": "string"
    //       }
    //     }
    //   }
    // }
    }