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);
}
}
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);
}
}
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;
}
Aggregations