private static void callAWIS()

in java/src/main/java/com/alexa/awisapi/AWIS.java [154:200]


  private static void callAWIS(AWIS awisClient)  throws IOException, Exception {

      String canonicalQuery = "Action=urlInfo&ResponseGroup=Rank&Url=" + URLEncoder.encode(awisClient.site, StandardCharsets.UTF_8.toString());
      String accessKey  = awisClient.credentials.getAccessKeyId();
      String secretKey = awisClient.credentials.getSecretKey();
      String sessionToken = awisClient.credentials.getSessionToken();

      awisClient.setDate();

      String canonicalHeaders = "host:" + SERVICE_HOST + "\n" + "x-amz-date:" + awisClient.amzDate + "\n";
      String signedHeaders = "host;x-amz-date";

      String payloadHash = awisClient.sha256("");

      String canonicalRequest = "GET" + "\n" + SERVICE_URI + "\n" + canonicalQuery + "\n" + canonicalHeaders + "\n" + signedHeaders + "\n" + payloadHash;

      // ************* TASK 2: CREATE THE STRING TO SIGN*************
      // Match the algorithm to the hashing algorithm you use, either SHA-1 or
      // SHA-256 (recommended)
      String algorithm = "AWS4-HMAC-SHA256";
      String credentialScope = awisClient.dateStamp + "/" + SERVICE_REGION + "/" + SERVICE_NAME + "/" + "aws4_request";
      String stringToSign = algorithm + '\n' +  awisClient.amzDate + '\n' +  credentialScope + '\n' +  awisClient.sha256(canonicalRequest);

      // ************* TASK 3: CALCULATE THE SIGNATURE *************
      // Create the signing key
      byte[] signingKey = awisClient.getSignatureKey(secretKey, awisClient.dateStamp, SERVICE_REGION, SERVICE_NAME);

      // Sign the string_to_sign using the signing_key
      String signature = bytesToHex(HmacSHA256(stringToSign, signingKey));

      String uri = AWS_BASE_URL + "?" + canonicalQuery;

      System.out.println("Making request to:\n");
      System.out.println(uri + "\n");

      // Make the Request

      String authorization = algorithm + " " + "Credential=" + accessKey + "/" + credentialScope + ", " +  "SignedHeaders=" + signedHeaders + ", " + "Signature=" + signature;

      String xmlResponse = makeRequest(uri, authorization, awisClient.amzDate, sessionToken, awisClient.apikey);

      // Print out the XML Response

      System.out.println("Response:\n");
      System.out.println(xmlResponse);

  }