use of si.mazi.rescu.oauth.RescuOAuthRequestAdapter in project rescu by mmazi.
the class HttpTemplate method send.
HttpURLConnection send(String urlString, String requestBody, Map<String, String> httpHeaders, HttpMethod method) throws IOException {
log.debug("Executing {} request at {}", method, urlString);
log.trace("Request body = {}", requestBody);
log.trace("Request headers = {}", httpHeaders);
preconditionNotNull(urlString, "urlString cannot be null");
preconditionNotNull(httpHeaders, "httpHeaders should not be null");
int contentLength = requestBody == null ? 0 : requestBody.getBytes().length;
HttpURLConnection connection = configureURLConnection(method, urlString, httpHeaders, contentLength);
if (oAuthConsumer != null) {
HttpRequest request = new RescuOAuthRequestAdapter(connection, requestBody);
try {
oAuthConsumer.sign(request);
} catch (OAuthException e) {
throw new RuntimeException("OAuth error", e);
}
}
if (contentLength > 0) {
// Write the request body
OutputStream out = connection.getOutputStream();
out.write(requestBody.getBytes(CHARSET_UTF_8));
out.flush();
}
return connection;
}
Aggregations