Search in sources :

Example 1 with HttpConnectionException

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;
}
Also used : JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) JSONException(com.oracle.truffle.tools.utils.json.JSONException) IOException(java.io.IOException) Map(java.util.Map) HttpConnectionException(org.graalvm.component.installer.remote.ProxyConnectionFactory.HttpConnectionException)

Aggregations

JSONException (com.oracle.truffle.tools.utils.json.JSONException)1 JSONObject (com.oracle.truffle.tools.utils.json.JSONObject)1 IOException (java.io.IOException)1 Map (java.util.Map)1 HttpConnectionException (org.graalvm.component.installer.remote.ProxyConnectionFactory.HttpConnectionException)1