Search in sources :

Example 1 with OAuthException

use of com.github.scribejava.core.exceptions.OAuthException in project scribejava by scribejava.

the class JDKHttpClient method doExecute.

private Response doExecute(String userAgent, Map<String, String> headers, Verb httpVerb, String completeUrl, BodyType bodyType, Object bodyContents) throws IOException {
    final HttpURLConnection connection = (HttpURLConnection) new URL(completeUrl).openConnection();
    connection.setInstanceFollowRedirects(config.isFollowRedirects());
    connection.setRequestMethod(httpVerb.name());
    if (config.getConnectTimeout() != null) {
        connection.setConnectTimeout(config.getConnectTimeout());
    }
    if (config.getReadTimeout() != null) {
        connection.setReadTimeout(config.getReadTimeout());
    }
    addHeaders(connection, headers, userAgent);
    if (httpVerb.isPermitBody()) {
        bodyType.setBody(connection, bodyContents);
    }
    try {
        connection.connect();
        final int responseCode = connection.getResponseCode();
        return new Response(responseCode, connection.getResponseMessage(), parseHeaders(connection), responseCode >= 200 && responseCode < 400 ? connection.getInputStream() : connection.getErrorStream());
    } catch (UnknownHostException e) {
        throw new OAuthException("The IP address of a host could not be determined.", e);
    }
}
Also used : Response(com.github.scribejava.core.model.Response) HttpURLConnection(java.net.HttpURLConnection) UnknownHostException(java.net.UnknownHostException) OAuthException(com.github.scribejava.core.exceptions.OAuthException) URL(java.net.URL)

Example 2 with OAuthException

use of com.github.scribejava.core.exceptions.OAuthException in project scribejava by scribejava.

the class OAuthRequest method getQueryStringParams.

/**
     * Get a {@link ParameterList} with the query string parameters.
     *
     * @return a {@link ParameterList} containing the query string parameters.
     * @throws OAuthException if the request URL is not valid.
     */
public ParameterList getQueryStringParams() {
    try {
        final ParameterList result = new ParameterList();
        final String queryString = new URL(url).getQuery();
        result.addQuerystring(queryString);
        result.addAll(querystringParams);
        return result;
    } catch (MalformedURLException mue) {
        throw new OAuthException("Malformed URL", mue);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) OAuthException(com.github.scribejava.core.exceptions.OAuthException) URL(java.net.URL)

Example 3 with OAuthException

use of com.github.scribejava.core.exceptions.OAuthException in project scribejava by scribejava.

the class OAuthEncoder method encode.

public static String encode(String plain) {
    Preconditions.checkNotNull(plain, "Cannot encode null object");
    String encoded;
    try {
        encoded = URLEncoder.encode(plain, CHARSET);
    } catch (UnsupportedEncodingException uee) {
        throw new OAuthException("Charset not found while encoding string: " + CHARSET, uee);
    }
    for (Map.Entry<String, String> rule : ENCODING_RULES.entrySet()) {
        encoded = applyRule(encoded, rule.getKey(), rule.getValue());
    }
    return encoded;
}
Also used : OAuthException(com.github.scribejava.core.exceptions.OAuthException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

OAuthException (com.github.scribejava.core.exceptions.OAuthException)3 URL (java.net.URL)2 Response (com.github.scribejava.core.model.Response)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 UnknownHostException (java.net.UnknownHostException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1