Chilkat Online Tools

StopBuild Java Example

AWS CodeBuild

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("codebuild");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://codebuild.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect("codebuild.us-west-2.amazonaws.com",443,true,true);
    if (success != true) {
        System.out.println("ConnectFailReason: " + rest.get_ConnectFailReason());
        System.out.println(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

    CkJsonObject json = new CkJsonObject();
    json.UpdateString("id","string");

    // The JSON request body created by the above code:

    // {
    //   "id": "string"
    // }

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

    CkStringBuilder sbRequestBody = new CkStringBuilder();
    json.EmitSb(sbRequestBody);
    CkStringBuilder sbResponseBody = new CkStringBuilder();
    success = rest.FullRequestSb("POST","/",sbRequestBody,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 strVal;
    String name;
    String v_type;
    String value;
    String identifier;
    String location;
    String mountOptions;
    String mountPoint;
    int durationInSeconds;
    int endTime;
    String phaseStatus;
    String phaseType;
    int startTime;
    int j;
    int count_j;
    String message;
    String statusCode;
    String artifactIdentifier;
    String bucketOwnerAccess;
    int encryptionDisabled;
    String md5sum;
    int overrideArtifactName;
    String sha256sum;
    String authResource;
    String authType;
    String buildspec;
    String buildStatusConfigContext;
    String buildStatusConfigTargetUrl;
    int gitCloneDepth;
    int gitSubmodulesConfigFetchSubmodules;
    int insecureSsl;
    int reportBuildStatus;
    String sourceIdentifier;
    String sourceVersion;

    String Arn = jResp.stringOf("build.arn");
    String ArtifactIdentifier = jResp.stringOf("build.artifacts.artifactIdentifier");
    String BucketOwnerAccess = jResp.stringOf("build.artifacts.bucketOwnerAccess");
    int EncryptionDisabled = jResp.IntOf("build.artifacts.encryptionDisabled");
    String Location = jResp.stringOf("build.artifacts.location");
    String Md5sum = jResp.stringOf("build.artifacts.md5sum");
    int OverrideArtifactName = jResp.IntOf("build.artifacts.overrideArtifactName");
    String Sha256sum = jResp.stringOf("build.artifacts.sha256sum");
    String BuildBatchArn = jResp.stringOf("build.buildBatchArn");
    int BuildComplete = jResp.IntOf("build.buildComplete");
    int BuildNumber = jResp.IntOf("build.buildNumber");
    String BuildStatus = jResp.stringOf("build.buildStatus");
    String CacheLocation = jResp.stringOf("build.cache.location");
    String v_Type = jResp.stringOf("build.cache.type");
    String CurrentPhase = jResp.stringOf("build.currentPhase");
    int SessionEnabled = jResp.IntOf("build.debugSession.sessionEnabled");
    String SessionTarget = jResp.stringOf("build.debugSession.sessionTarget");
    String EncryptionKey = jResp.stringOf("build.encryptionKey");
    int EndTime = jResp.IntOf("build.endTime");
    String Certificate = jResp.stringOf("build.environment.certificate");
    String ComputeType = jResp.stringOf("build.environment.computeType");
    String Image = jResp.stringOf("build.environment.image");
    String ImagePullCredentialsType = jResp.stringOf("build.environment.imagePullCredentialsType");
    int PrivilegedMode = jResp.IntOf("build.environment.privilegedMode");
    String Credential = jResp.stringOf("build.environment.registryCredential.credential");
    String CredentialProvider = jResp.stringOf("build.environment.registryCredential.credentialProvider");
    String EnvironmentType = jResp.stringOf("build.environment.type");
    String Id = jResp.stringOf("build.id");
    String Initiator = jResp.stringOf("build.initiator");
    String GroupName = jResp.stringOf("build.logs.cloudWatchLogs.groupName");
    String Status = jResp.stringOf("build.logs.cloudWatchLogs.status");
    String StreamName = jResp.stringOf("build.logs.cloudWatchLogs.streamName");
    String CloudWatchLogsArn = jResp.stringOf("build.logs.cloudWatchLogsArn");
    String DeepLink = jResp.stringOf("build.logs.deepLink");
    String LogsGroupName = jResp.stringOf("build.logs.groupName");
    String S3DeepLink = jResp.stringOf("build.logs.s3DeepLink");
    String S3LogsBucketOwnerAccess = jResp.stringOf("build.logs.s3Logs.bucketOwnerAccess");
    int S3LogsEncryptionDisabled = jResp.IntOf("build.logs.s3Logs.encryptionDisabled");
    String S3LogsLocation = jResp.stringOf("build.logs.s3Logs.location");
    String S3LogsStatus = jResp.stringOf("build.logs.s3Logs.status");
    String S3LogsArn = jResp.stringOf("build.logs.s3LogsArn");
    String LogsStreamName = jResp.stringOf("build.logs.streamName");
    String NetworkInterfaceId = jResp.stringOf("build.networkInterface.networkInterfaceId");
    String SubnetId = jResp.stringOf("build.networkInterface.subnetId");
    String ProjectName = jResp.stringOf("build.projectName");
    int QueuedTimeoutInMinutes = jResp.IntOf("build.queuedTimeoutInMinutes");
    String ResolvedSourceVersion = jResp.stringOf("build.resolvedSourceVersion");
    String ServiceRole = jResp.stringOf("build.serviceRole");
    String Resource = jResp.stringOf("build.source.auth.resource");
    String AuthType = jResp.stringOf("build.source.auth.type");
    String Buildspec = jResp.stringOf("build.source.buildspec");
    String Context = jResp.stringOf("build.source.buildStatusConfig.context");
    String TargetUrl = jResp.stringOf("build.source.buildStatusConfig.targetUrl");
    int GitCloneDepth = jResp.IntOf("build.source.gitCloneDepth");
    int FetchSubmodules = jResp.IntOf("build.source.gitSubmodulesConfig.fetchSubmodules");
    int InsecureSsl = jResp.IntOf("build.source.insecureSsl");
    String SourceLocation = jResp.stringOf("build.source.location");
    int ReportBuildStatus = jResp.IntOf("build.source.reportBuildStatus");
    String SourceIdentifier = jResp.stringOf("build.source.sourceIdentifier");
    String SourceType = jResp.stringOf("build.source.type");
    String SourceVersion = jResp.stringOf("build.sourceVersion");
    int StartTime = jResp.IntOf("build.startTime");
    int TimeoutInMinutes = jResp.IntOf("build.timeoutInMinutes");
    String VpcId = jResp.stringOf("build.vpcConfig.vpcId");
    int i = 0;
    int count_i = jResp.SizeOfArray("build.cache.modes");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("build.cache.modes[i]");
        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("build.environment.environmentVariables");
    while (i < count_i) {
        jResp.put_I(i);
        name = jResp.stringOf("build.environment.environmentVariables[i].name");
        v_type = jResp.stringOf("build.environment.environmentVariables[i].type");
        value = jResp.stringOf("build.environment.environmentVariables[i].value");
        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("build.exportedEnvironmentVariables");
    while (i < count_i) {
        jResp.put_I(i);
        name = jResp.stringOf("build.exportedEnvironmentVariables[i].name");
        value = jResp.stringOf("build.exportedEnvironmentVariables[i].value");
        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("build.fileSystemLocations");
    while (i < count_i) {
        jResp.put_I(i);
        identifier = jResp.stringOf("build.fileSystemLocations[i].identifier");
        location = jResp.stringOf("build.fileSystemLocations[i].location");
        mountOptions = jResp.stringOf("build.fileSystemLocations[i].mountOptions");
        mountPoint = jResp.stringOf("build.fileSystemLocations[i].mountPoint");
        v_type = jResp.stringOf("build.fileSystemLocations[i].type");
        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("build.phases");
    while (i < count_i) {
        jResp.put_I(i);
        durationInSeconds = jResp.IntOf("build.phases[i].durationInSeconds");
        endTime = jResp.IntOf("build.phases[i].endTime");
        phaseStatus = jResp.stringOf("build.phases[i].phaseStatus");
        phaseType = jResp.stringOf("build.phases[i].phaseType");
        startTime = jResp.IntOf("build.phases[i].startTime");
        j = 0;
        count_j = jResp.SizeOfArray("build.phases[i].contexts");
        while (j < count_j) {
            jResp.put_J(j);
            message = jResp.stringOf("build.phases[i].contexts[j].message");
            statusCode = jResp.stringOf("build.phases[i].contexts[j].statusCode");
            j = j+1;
            }

        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("build.reportArns");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("build.reportArns[i]");
        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("build.secondaryArtifacts");
    while (i < count_i) {
        jResp.put_I(i);
        artifactIdentifier = jResp.stringOf("build.secondaryArtifacts[i].artifactIdentifier");
        bucketOwnerAccess = jResp.stringOf("build.secondaryArtifacts[i].bucketOwnerAccess");
        encryptionDisabled = jResp.IntOf("build.secondaryArtifacts[i].encryptionDisabled");
        location = jResp.stringOf("build.secondaryArtifacts[i].location");
        md5sum = jResp.stringOf("build.secondaryArtifacts[i].md5sum");
        overrideArtifactName = jResp.IntOf("build.secondaryArtifacts[i].overrideArtifactName");
        sha256sum = jResp.stringOf("build.secondaryArtifacts[i].sha256sum");
        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("build.secondarySources");
    while (i < count_i) {
        jResp.put_I(i);
        authResource = jResp.stringOf("build.secondarySources[i].auth.resource");
        authType = jResp.stringOf("build.secondarySources[i].auth.type");
        buildspec = jResp.stringOf("build.secondarySources[i].buildspec");
        buildStatusConfigContext = jResp.stringOf("build.secondarySources[i].buildStatusConfig.context");
        buildStatusConfigTargetUrl = jResp.stringOf("build.secondarySources[i].buildStatusConfig.targetUrl");
        gitCloneDepth = jResp.IntOf("build.secondarySources[i].gitCloneDepth");
        gitSubmodulesConfigFetchSubmodules = jResp.IntOf("build.secondarySources[i].gitSubmodulesConfig.fetchSubmodules");
        insecureSsl = jResp.IntOf("build.secondarySources[i].insecureSsl");
        location = jResp.stringOf("build.secondarySources[i].location");
        reportBuildStatus = jResp.IntOf("build.secondarySources[i].reportBuildStatus");
        sourceIdentifier = jResp.stringOf("build.secondarySources[i].sourceIdentifier");
        v_type = jResp.stringOf("build.secondarySources[i].type");
        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("build.secondarySourceVersions");
    while (i < count_i) {
        jResp.put_I(i);
        sourceIdentifier = jResp.stringOf("build.secondarySourceVersions[i].sourceIdentifier");
        sourceVersion = jResp.stringOf("build.secondarySourceVersions[i].sourceVersion");
        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("build.vpcConfig.securityGroupIds");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("build.vpcConfig.securityGroupIds[i]");
        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("build.vpcConfig.subnets");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("build.vpcConfig.subnets[i]");
        i = i+1;
        }

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

    // {
    //   "build": {
    //     "arn": "string",
    //     "artifacts": {
    //       "artifactIdentifier": "string",
    //       "bucketOwnerAccess": "string",
    //       "encryptionDisabled": boolean,
    //       "location": "string",
    //       "md5sum": "string",
    //       "overrideArtifactName": boolean,
    //       "sha256sum": "string"
    //     },
    //     "buildBatchArn": "string",
    //     "buildComplete": boolean,
    //     "buildNumber": number,
    //     "buildStatus": "string",
    //     "cache": {
    //       "location": "string",
    //       "modes": [
    //         "string"
    //       ],
    //       "type": "string"
    //     },
    //     "currentPhase": "string",
    //     "debugSession": {
    //       "sessionEnabled": boolean,
    //       "sessionTarget": "string"
    //     },
    //     "encryptionKey": "string",
    //     "endTime": number,
    //     "environment": {
    //       "certificate": "string",
    //       "computeType": "string",
    //       "environmentVariables": [
    //         {
    //           "name": "string",
    //           "type": "string",
    //           "value": "string"
    //         }
    //       ],
    //       "image": "string",
    //       "imagePullCredentialsType": "string",
    //       "privilegedMode": boolean,
    //       "registryCredential": {
    //         "credential": "string",
    //         "credentialProvider": "string"
    //       },
    //       "type": "string"
    //     },
    //     "exportedEnvironmentVariables": [
    //       {
    //         "name": "string",
    //         "value": "string"
    //       }
    //     ],
    //     "fileSystemLocations": [
    //       {
    //         "identifier": "string",
    //         "location": "string",
    //         "mountOptions": "string",
    //         "mountPoint": "string",
    //         "type": "string"
    //       }
    //     ],
    //     "id": "string",
    //     "initiator": "string",
    //     "logs": {
    //       "cloudWatchLogs": {
    //         "groupName": "string",
    //         "status": "string",
    //         "streamName": "string"
    //       },
    //       "cloudWatchLogsArn": "string",
    //       "deepLink": "string",
    //       "groupName": "string",
    //       "s3DeepLink": "string",
    //       "s3Logs": {
    //         "bucketOwnerAccess": "string",
    //         "encryptionDisabled": boolean,
    //         "location": "string",
    //         "status": "string"
    //       },
    //       "s3LogsArn": "string",
    //       "streamName": "string"
    //     },
    //     "networkInterface": {
    //       "networkInterfaceId": "string",
    //       "subnetId": "string"
    //     },
    //     "phases": [
    //       {
    //         "contexts": [
    //           {
    //             "message": "string",
    //             "statusCode": "string"
    //           }
    //         ],
    //         "durationInSeconds": number,
    //         "endTime": number,
    //         "phaseStatus": "string",
    //         "phaseType": "string",
    //         "startTime": number
    //       }
    //     ],
    //     "projectName": "string",
    //     "queuedTimeoutInMinutes": number,
    //     "reportArns": [
    //       "string"
    //     ],
    //     "resolvedSourceVersion": "string",
    //     "secondaryArtifacts": [
    //       {
    //         "artifactIdentifier": "string",
    //         "bucketOwnerAccess": "string",
    //         "encryptionDisabled": boolean,
    //         "location": "string",
    //         "md5sum": "string",
    //         "overrideArtifactName": boolean,
    //         "sha256sum": "string"
    //       }
    //     ],
    //     "secondarySources": [
    //       {
    //         "auth": {
    //           "resource": "string",
    //           "type": "string"
    //         },
    //         "buildspec": "string",
    //         "buildStatusConfig": {
    //           "context": "string",
    //           "targetUrl": "string"
    //         },
    //         "gitCloneDepth": number,
    //         "gitSubmodulesConfig": {
    //           "fetchSubmodules": boolean
    //         },
    //         "insecureSsl": boolean,
    //         "location": "string",
    //         "reportBuildStatus": boolean,
    //         "sourceIdentifier": "string",
    //         "type": "string"
    //       }
    //     ],
    //     "secondarySourceVersions": [
    //       {
    //         "sourceIdentifier": "string",
    //         "sourceVersion": "string"
    //       }
    //     ],
    //     "serviceRole": "string",
    //     "source": {
    //       "auth": {
    //         "resource": "string",
    //         "type": "string"
    //       },
    //       "buildspec": "string",
    //       "buildStatusConfig": {
    //         "context": "string",
    //         "targetUrl": "string"
    //       },
    //       "gitCloneDepth": number,
    //       "gitSubmodulesConfig": {
    //         "fetchSubmodules": boolean
    //       },
    //       "insecureSsl": boolean,
    //       "location": "string",
    //       "reportBuildStatus": boolean,
    //       "sourceIdentifier": "string",
    //       "type": "string"
    //     },
    //     "sourceVersion": "string",
    //     "startTime": number,
    //     "timeoutInMinutes": number,
    //     "vpcConfig": {
    //       "securityGroupIds": [
    //         "string"
    //       ],
    //       "subnets": [
    //         "string"
    //       ],
    //       "vpcId": "string"
    //     }
    //   }
    // }
  }
}