Search in sources :

Example 1 with JsonParseException

use of org.eclipse.che.commons.json.JsonParseException in project che by eclipse.

the class GitHubOAuthAuthenticator method getJson2.

protected <O> O getJson2(String getUserUrl, Class<O> userClass, Type type) throws OAuthAuthenticationException {
    HttpURLConnection urlConnection = null;
    InputStream urlInputStream = null;
    try {
        urlConnection = (HttpURLConnection) new URL(getUserUrl).openConnection();
        urlConnection.setRequestProperty("Accept", "application/vnd.github.v3.html+json");
        urlInputStream = urlConnection.getInputStream();
        return JsonHelper.fromJson(urlInputStream, userClass, type);
    } catch (JsonParseException | IOException e) {
        throw new OAuthAuthenticationException(e.getMessage(), e);
    } finally {
        if (urlInputStream != null) {
            try {
                urlInputStream.close();
            } catch (IOException ignored) {
            }
        }
        if (urlConnection != null) {
            urlConnection.disconnect();
        }
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStream(java.io.InputStream) IOException(java.io.IOException) JsonParseException(org.eclipse.che.commons.json.JsonParseException) URL(java.net.URL)

Example 2 with JsonParseException

use of org.eclipse.che.commons.json.JsonParseException in project che by eclipse.

the class OAuthAuthenticator method getJson.

protected <O> O getJson(String getUserUrl, Class<O> userClass) throws OAuthAuthenticationException {
    HttpURLConnection urlConnection = null;
    InputStream urlInputStream = null;
    try {
        urlConnection = (HttpURLConnection) new URL(getUserUrl).openConnection();
        urlInputStream = urlConnection.getInputStream();
        return JsonHelper.fromJson(urlInputStream, userClass, null);
    } catch (JsonParseException | IOException e) {
        throw new OAuthAuthenticationException(e.getMessage(), e);
    } finally {
        if (urlInputStream != null) {
            try {
                urlInputStream.close();
            } catch (IOException ignored) {
            }
        }
        if (urlConnection != null) {
            urlConnection.disconnect();
        }
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStream(java.io.InputStream) IOException(java.io.IOException) JsonParseException(org.eclipse.che.commons.json.JsonParseException) URL(java.net.URL)

Aggregations

IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HttpURLConnection (java.net.HttpURLConnection)2 URL (java.net.URL)2 JsonParseException (org.eclipse.che.commons.json.JsonParseException)2