ListApplicationComponents SQL Server Example
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @sTmp0 nvarchar(max)
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @rest int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Rest', @rest OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
DECLARE @authAws int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.AuthAws', @authAws OUT
EXEC sp_OASetProperty @authAws, 'AccessKey', 'AWS_ACCESS_KEY'
EXEC sp_OASetProperty @authAws, '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.)
EXEC sp_OASetProperty @authAws, 'Region', 'us-west-2'
EXEC sp_OASetProperty @authAws, 'ServiceName', 'migrationhub-strategy'
-- SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
EXEC sp_OAMethod @rest, 'SetAuthAws', @success OUT, @authAws
-- URL: https://migrationhub-strategy.us-west-2.amazonaws.com/
-- Use the same region as specified above.
EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'migrationhub-strategy.us-west-2.amazonaws.com', 443, 1, 1
IF @success <> 1
BEGIN
EXEC sp_OAGetProperty @rest, 'ConnectFailReason', @iTmp0 OUT
PRINT 'ConnectFailReason: ' + @iTmp0
EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @authAws
RETURN
END
-- 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
DECLARE @json int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'applicationComponentCriteria', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filterValue', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'groupIdFilter[0].name', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'groupIdFilter[0].value', 'string'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'maxResults', 123
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'nextToken', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'sort', 'string'
-- The JSON request body created by the above code:
-- {
-- "applicationComponentCriteria": "string",
-- "filterValue": "string",
-- "groupIdFilter": [
-- {
-- "name": "string",
-- "value": "string"
-- }
-- ],
-- "maxResults": number,
-- "nextToken": "string",
-- "sort": "string"
-- }
EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Content-Type', 'application/x-amz-json-1.1'
EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'X-Amz-Target', 'ListApplicationComponents'
DECLARE @sbRequestBody int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbRequestBody OUT
EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody
DECLARE @sbResponseBody int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @rest, 'FullRequestSb', @success OUT, 'POST', '/list-applicationcomponents', @sbRequestBody, @sbResponseBody
IF @success <> 1
BEGIN
EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @authAws
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
EXEC @hr = sp_OADestroy @sbResponseBody
RETURN
END
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @respStatusCode OUT
PRINT 'response status code = ' + @respStatusCode
IF @respStatusCode <> 200
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @rest, 'ResponseHeader', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Response Body:'
EXEC sp_OAMethod @sbResponseBody, 'GetAsString', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @authAws
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
EXEC @hr = sp_OADestroy @sbResponseBody
RETURN
END
DECLARE @jResp int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT
EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @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
DECLARE @analysisStatus nvarchar(max)
DECLARE @S3Bucket nvarchar(max)
DECLARE @S3key nvarchar(max)
DECLARE @antipatternReportStatus nvarchar(max)
DECLARE @antipatternReportStatusMessage nvarchar(max)
DECLARE @appType nvarchar(max)
DECLARE @associatedServerId nvarchar(max)
DECLARE @SecretName nvarchar(max)
DECLARE @id nvarchar(max)
DECLARE @inclusionStatus nvarchar(max)
DECLARE @lastAnalyzedTimestamp int
DECLARE @moreServerAssociationExists int
DECLARE @name nvarchar(max)
DECLARE @osDriver nvarchar(max)
DECLARE @osVersion nvarchar(max)
DECLARE @Strategy nvarchar(max)
DECLARE @TargetDestination nvarchar(max)
DECLARE @Description nvarchar(max)
DECLARE @Name nvarchar(max)
DECLARE @TranformationToolInstallationLink nvarchar(max)
DECLARE @resourceSubType nvarchar(max)
DECLARE @statusMessage nvarchar(max)
DECLARE @j int
DECLARE @count_j int
DECLARE @count int
DECLARE @severity nvarchar(max)
DECLARE @branch nvarchar(max)
DECLARE @repository nvarchar(max)
DECLARE @versionControlType nvarchar(max)
DECLARE @nextToken nvarchar(max)
EXEC sp_OAMethod @jResp, 'StringOf', @nextToken OUT, 'nextToken'
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'applicationComponentInfos'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @analysisStatus OUT, 'applicationComponentInfos[i].analysisStatus'
EXEC sp_OAMethod @jResp, 'StringOf', @S3Bucket OUT, 'applicationComponentInfos[i].antipatternReportS3Object.s3Bucket'
EXEC sp_OAMethod @jResp, 'StringOf', @S3key OUT, 'applicationComponentInfos[i].antipatternReportS3Object.s3key'
EXEC sp_OAMethod @jResp, 'StringOf', @antipatternReportStatus OUT, 'applicationComponentInfos[i].antipatternReportStatus'
EXEC sp_OAMethod @jResp, 'StringOf', @antipatternReportStatusMessage OUT, 'applicationComponentInfos[i].antipatternReportStatusMessage'
EXEC sp_OAMethod @jResp, 'StringOf', @appType OUT, 'applicationComponentInfos[i].appType'
EXEC sp_OAMethod @jResp, 'StringOf', @associatedServerId OUT, 'applicationComponentInfos[i].associatedServerId'
EXEC sp_OAMethod @jResp, 'StringOf', @SecretName OUT, 'applicationComponentInfos[i].databaseConfigDetail.secretName'
EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'applicationComponentInfos[i].id'
EXEC sp_OAMethod @jResp, 'StringOf', @inclusionStatus OUT, 'applicationComponentInfos[i].inclusionStatus'
EXEC sp_OAMethod @jResp, 'IntOf', @lastAnalyzedTimestamp OUT, 'applicationComponentInfos[i].lastAnalyzedTimestamp'
EXEC sp_OAMethod @jResp, 'IntOf', @moreServerAssociationExists OUT, 'applicationComponentInfos[i].moreServerAssociationExists'
EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'applicationComponentInfos[i].name'
EXEC sp_OAMethod @jResp, 'StringOf', @osDriver OUT, 'applicationComponentInfos[i].osDriver'
EXEC sp_OAMethod @jResp, 'StringOf', @osVersion OUT, 'applicationComponentInfos[i].osVersion'
EXEC sp_OAMethod @jResp, 'StringOf', @Strategy OUT, 'applicationComponentInfos[i].recommendationSet.strategy'
EXEC sp_OAMethod @jResp, 'StringOf', @TargetDestination OUT, 'applicationComponentInfos[i].recommendationSet.targetDestination'
EXEC sp_OAMethod @jResp, 'StringOf', @Description OUT, 'applicationComponentInfos[i].recommendationSet.transformationTool.description'
EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'applicationComponentInfos[i].recommendationSet.transformationTool.name'
EXEC sp_OAMethod @jResp, 'StringOf', @TranformationToolInstallationLink OUT, 'applicationComponentInfos[i].recommendationSet.transformationTool.tranformationToolInstallationLink'
EXEC sp_OAMethod @jResp, 'StringOf', @resourceSubType OUT, 'applicationComponentInfos[i].resourceSubType'
EXEC sp_OAMethod @jResp, 'StringOf', @statusMessage OUT, 'applicationComponentInfos[i].statusMessage'
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'applicationComponentInfos[i].listAntipatternSeveritySummary'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
EXEC sp_OAMethod @jResp, 'IntOf', @count OUT, 'applicationComponentInfos[i].listAntipatternSeveritySummary[j].count'
EXEC sp_OAMethod @jResp, 'StringOf', @severity OUT, 'applicationComponentInfos[i].listAntipatternSeveritySummary[j].severity'
SELECT @j = @j + 1
END
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'applicationComponentInfos[i].sourceCodeRepositories'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
EXEC sp_OAMethod @jResp, 'StringOf', @branch OUT, 'applicationComponentInfos[i].sourceCodeRepositories[j].branch'
EXEC sp_OAMethod @jResp, 'StringOf', @repository OUT, 'applicationComponentInfos[i].sourceCodeRepositories[j].repository'
EXEC sp_OAMethod @jResp, 'StringOf', @versionControlType OUT, 'applicationComponentInfos[i].sourceCodeRepositories[j].versionControlType'
SELECT @j = @j + 1
END
SELECT @i = @i + 1
END
-- A sample JSON response body parsed by the above code:
-- {
-- "applicationComponentInfos": [
-- {
-- "analysisStatus": "string",
-- "antipatternReportS3Object": {
-- "s3Bucket": "string",
-- "s3key": "string"
-- },
-- "antipatternReportStatus": "string",
-- "antipatternReportStatusMessage": "string",
-- "appType": "string",
-- "associatedServerId": "string",
-- "databaseConfigDetail": {
-- "secretName": "string"
-- },
-- "id": "string",
-- "inclusionStatus": "string",
-- "lastAnalyzedTimestamp": number,
-- "listAntipatternSeveritySummary": [
-- {
-- "count": number,
-- "severity": "string"
-- }
-- ],
-- "moreServerAssociationExists": boolean,
-- "name": "string",
-- "osDriver": "string",
-- "osVersion": "string",
-- "recommendationSet": {
-- "strategy": "string",
-- "targetDestination": "string",
-- "transformationTool": {
-- "description": "string",
-- "name": "string",
-- "tranformationToolInstallationLink": "string"
-- }
-- },
-- "resourceSubType": "string",
-- "sourceCodeRepositories": [
-- {
-- "branch": "string",
-- "repository": "string",
-- "versionControlType": "string"
-- }
-- ],
-- "statusMessage": "string"
-- }
-- ],
-- "nextToken": "string"
-- }
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @authAws
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO