Search in sources :

Example 1 with HttpServiceResponse

use of org.xdi.oxauth.model.net.HttpServiceResponse in project oxAuth by GluuFederation.

the class HttpService method executePost.

public HttpServiceResponse executePost(HttpClient httpClient, String uri, String authData, Map<String, String> headers, String postData, ContentType contentType) {
    HttpPost httpPost = new HttpPost(uri);
    if (StringHelper.isNotEmpty(authData)) {
        httpPost.setHeader("Authorization", "Basic " + authData);
    }
    if (headers != null) {
        for (Entry<String, String> headerEntry : headers.entrySet()) {
            httpPost.setHeader(headerEntry.getKey(), headerEntry.getValue());
        }
    }
    StringEntity stringEntity = new StringEntity(postData, contentType);
    httpPost.setEntity(stringEntity);
    try {
        HttpResponse httpResponse = httpClient.execute(httpPost);
        return new HttpServiceResponse(httpPost, httpResponse);
    } catch (IOException ex) {
        log.error("Failed to execute post request", ex);
    }
    return null;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) HttpResponse(org.apache.http.HttpResponse) HttpServiceResponse(org.xdi.oxauth.model.net.HttpServiceResponse) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 HttpResponse (org.apache.http.HttpResponse)1 HttpPost (org.apache.http.client.methods.HttpPost)1 StringEntity (org.apache.http.entity.StringEntity)1 HttpServiceResponse (org.xdi.oxauth.model.net.HttpServiceResponse)1