username = remoteProviderApplication.getRemoteProviderType().getUsername();
password = remoteProviderApplication.getRemoteProviderType().getPassword();
// This block tries to get the latest build for the app and dies if it fails.
HttpResponse response = utils.getUrl(GET_APP_BUILDS_URI, username, password);
InputStream appBuildsInputStream;
if (response.isValid()) {
appBuildsInputStream = response.getInputStream();
} else {
LOG.error("Error encountered while getting application builds. Status was " + response.getStatus());
return null;
}
String appName = remoteProviderApplication.getNativeName();
VeracodeApplicationIdMapParser parser = new VeracodeApplicationIdMapParser();
List<String> buildIds = null;
assert appBuildsInputStream != null : "Failed to get app builds.";
if (appBuildsInputStream != null) {
parse(appBuildsInputStream, parser);
buildIds = parser.map.get(appName);
}
if (buildIds == null || buildIds.size() == 0) {
LOG.warn("No build IDs were parsed.");
return null; // we failed.
} else {
LOG.warn("Retrieved build IDs " + buildIds + " for application " + appName);
}
List<Scan> scans = list();
for (String buildId : buildIds) {
if (buildId == null || buildId.trim().equals("")) {
LOG.warn("Build ID was null or empty. This should never happen.");
continue; // we failed.
} else if (parser.dateMap.get(buildId) != null && parser.dateMap.get(buildId)
.before(remoteProviderApplication.getLastImportTime())) {
log.info("Build ID " + buildId + " was scanned before the most recent scan in ThreadFix.");
continue;
} else if (parser.dateMap.get(buildId)== null) {
log.info("Build ID " + buildId + " was null.");
continue;
}
LOG.warn("Importing scan for build ID " + buildId + " and application " + appName);
// This block tries to parse the scan corresponding to the build.
response = utils.getUrl(GET_DETAILED_REPORT_URI + "?build_id=" + buildId, username, password);
if (response.isValid()) {
inputStream = response.getInputStream();
} else {
LOG.warn("Received a bad response (status code " + response.getStatus() +
") from Veracode servers while attempting to parse a scan, skipping to next scan.");
continue;
}
VeracodeSAXParser scanParser = new VeracodeSAXParser();