Search in sources :

Example 1 with RescuOAuthRequestAdapter

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;
}
Also used : HttpRequest(oauth.signpost.http.HttpRequest) OAuthException(oauth.signpost.exception.OAuthException) RescuOAuthRequestAdapter(si.mazi.rescu.oauth.RescuOAuthRequestAdapter)

Aggregations

OAuthException (oauth.signpost.exception.OAuthException)1 HttpRequest (oauth.signpost.http.HttpRequest)1 RescuOAuthRequestAdapter (si.mazi.rescu.oauth.RescuOAuthRequestAdapter)1