use of org.graalvm.component.installer.remote.ProxyConnectionFactory.HttpConnectionException in project graal by oracle.
the class GDSChannel method interceptDownloadException.
public IOException interceptDownloadException(IOException downloadException, FileDownloader fileDownloader) {
if (downloadException instanceof HttpConnectionException) {
HttpConnectionException hex = (HttpConnectionException) downloadException;
if (hex.getRetCode() < HttpURLConnection.HTTP_BAD_REQUEST) {
return (IOException) hex.getCause();
}
String downloadURL = hex.getConnectionUrl().toString();
if (!downloadURL.endsWith(EXC_URL_END)) {
return (IOException) hex.getCause();
}
String licensePath = findLicensePath(downloadURL);
if (!nonBlankString(licensePath)) {
return (IOException) hex.getCause();
}
String code;
try {
code = new JSONObject(hex.getResponse()).getString(JSON_EXC_CODE);
} catch (JSONException ex) {
return (IOException) hex.getCause();
}
String token = getToken(licensePath);
switch(code) {
case EXC_CODE_INVALID_TOKEN:
fb.output("ERR_InvalidToken", hex, token);
token = getToken(licensePath, true);
break;
case EXC_CODE_UNACCEPTED:
Map.Entry<String, String> downloadToken = initTokenStorage().getToken();
if (fileDownloader.getAttemptNr() == 1) {
token = gdsConnector.sendVerificationEmail(downloadToken.getKey(), licensePath, downloadToken.getValue());
} else {
token = downloadToken.getValue();
}
if (nonBlankString(token)) {
fb.output("PROMPT_VerifyEmailAddressEntry", downloadToken.getKey());
fb.acceptLine(false);
}
break;
default:
return (IOException) hex.getCause();
}
fileDownloader.addRequestHeader(HEADER_DOWNLOAD_TOKEN, token);
} else {
return downloadException;
}
return null;
}
Aggregations