ListServers unicodeCpp Example
#include <CkRestW.h>
#include <CkAuthAwsW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.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;
}
// The following code creates the JSON request body.
// The JSON created by this code is shown below.
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
CkJsonObjectW json;
json.UpdateString(L"filterValue",L"string");
json.UpdateString(L"groupIdFilter[0].name",L"string");
json.UpdateString(L"groupIdFilter[0].value",L"string");
json.UpdateInt(L"maxResults",123);
json.UpdateString(L"nextToken",L"string");
json.UpdateString(L"serverCriteria",L"string");
json.UpdateString(L"sort",L"string");
// The JSON request body created by the above code:
// {
// "filterValue": "string",
// "groupIdFilter": [
// {
// "name": "string",
// "value": "string"
// }
// ],
// "maxResults": number,
// "nextToken": "string",
// "serverCriteria": "string",
// "sort": "string"
// }
rest.AddHeader(L"Content-Type",L"application/x-amz-json-1.1");
rest.AddHeader(L"X-Amz-Target",L"ListServers");
CkStringBuilderW sbRequestBody;
json.EmitSb(sbRequestBody);
CkStringBuilderW sbResponseBody;
success = rest.FullRequestSb(L"POST",L"/list-servers",sbRequestBody,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 *S3Bucket = 0;
const wchar_t *S3key = 0;
const wchar_t *antipatternReportStatus = 0;
const wchar_t *antipatternReportStatusMessage = 0;
const wchar_t *dataCollectionStatus = 0;
const wchar_t *id = 0;
int lastAnalyzedTimestamp;
const wchar_t *name = 0;
const wchar_t *Strategy = 0;
const wchar_t *TargetDestination = 0;
const wchar_t *Description = 0;
const wchar_t *Name = 0;
const wchar_t *TranformationToolInstallationLink = 0;
const wchar_t *serverType = 0;
const wchar_t *statusMessage = 0;
const wchar_t *CpuArchitecture = 0;
const wchar_t *FileSystemType = 0;
const wchar_t *v_Type = 0;
const wchar_t *Version = 0;
int j;
int count_j;
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");
int i = 0;
int count_i = jResp.SizeOfArray(L"serverInfos");
while (i < count_i) {
jResp.put_I(i);
S3Bucket = jResp.stringOf(L"serverInfos[i].antipatternReportS3Object.s3Bucket");
S3key = jResp.stringOf(L"serverInfos[i].antipatternReportS3Object.s3key");
antipatternReportStatus = jResp.stringOf(L"serverInfos[i].antipatternReportStatus");
antipatternReportStatusMessage = jResp.stringOf(L"serverInfos[i].antipatternReportStatusMessage");
dataCollectionStatus = jResp.stringOf(L"serverInfos[i].dataCollectionStatus");
id = jResp.stringOf(L"serverInfos[i].id");
lastAnalyzedTimestamp = jResp.IntOf(L"serverInfos[i].lastAnalyzedTimestamp");
name = jResp.stringOf(L"serverInfos[i].name");
Strategy = jResp.stringOf(L"serverInfos[i].recommendationSet.strategy");
TargetDestination = jResp.stringOf(L"serverInfos[i].recommendationSet.targetDestination");
Description = jResp.stringOf(L"serverInfos[i].recommendationSet.transformationTool.description");
Name = jResp.stringOf(L"serverInfos[i].recommendationSet.transformationTool.name");
TranformationToolInstallationLink = jResp.stringOf(L"serverInfos[i].recommendationSet.transformationTool.tranformationToolInstallationLink");
serverType = jResp.stringOf(L"serverInfos[i].serverType");
statusMessage = jResp.stringOf(L"serverInfos[i].statusMessage");
CpuArchitecture = jResp.stringOf(L"serverInfos[i].systemInfo.cpuArchitecture");
FileSystemType = jResp.stringOf(L"serverInfos[i].systemInfo.fileSystemType");
v_Type = jResp.stringOf(L"serverInfos[i].systemInfo.osInfo.type");
Version = jResp.stringOf(L"serverInfos[i].systemInfo.osInfo.version");
j = 0;
count_j = jResp.SizeOfArray(L"serverInfos[i].applicationComponentStrategySummary");
while (j < count_j) {
jResp.put_J(j);
count = jResp.IntOf(L"serverInfos[i].applicationComponentStrategySummary[j].count");
strategy = jResp.stringOf(L"serverInfos[i].applicationComponentStrategySummary[j].strategy");
j = j + 1;
}
j = 0;
count_j = jResp.SizeOfArray(L"serverInfos[i].listAntipatternSeveritySummary");
while (j < count_j) {
jResp.put_J(j);
count = jResp.IntOf(L"serverInfos[i].listAntipatternSeveritySummary[j].count");
severity = jResp.stringOf(L"serverInfos[i].listAntipatternSeveritySummary[j].severity");
j = j + 1;
}
j = 0;
count_j = jResp.SizeOfArray(L"serverInfos[i].systemInfo.networkInfoList");
while (j < count_j) {
jResp.put_J(j);
interfaceName = jResp.stringOf(L"serverInfos[i].systemInfo.networkInfoList[j].interfaceName");
ipAddress = jResp.stringOf(L"serverInfos[i].systemInfo.networkInfoList[j].ipAddress");
macAddress = jResp.stringOf(L"serverInfos[i].systemInfo.networkInfoList[j].macAddress");
netMask = jResp.stringOf(L"serverInfos[i].systemInfo.networkInfoList[j].netMask");
j = j + 1;
}
i = i + 1;
}
// A sample JSON response body parsed by the above code:
// {
// "nextToken": "string",
// "serverInfos": [
// {
// "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"
// }
// }
// }
// ]
// }
}