use of org.apache.http.client.methods.HttpRequestBase in project linuxtools by eclipse.
the class OSIORestRequest method execute.
protected T execute(IOperationMonitor monitor) throws IOException, OSIORestException {
HttpRequestBase request = createHttpRequestBase();
addHttpRequestEntities(request);
CommonHttpResponse response = execute(request, monitor);
return processAndRelease(response, monitor);
}
use of org.apache.http.client.methods.HttpRequestBase in project suite by stupidsing.
the class HttpUtil method httpApache.
private static HttpResult httpApache(String method, URL url, Outlet<Bytes> in, Map<String, String> headers) throws IOException {
LogUtil.info("START " + method + " " + url);
CloseableHttpClient client = HttpClients.createDefault();
HttpRequestBase request = new HttpRequestBase() {
{
setURI(URI.create(url.toString()));
headers.entrySet().forEach(e -> addHeader(e.getKey(), e.getValue()));
}
public String getMethod() {
return method;
}
};
CloseableHttpResponse response = client.execute(request);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
InputStream inputStream = response.getEntity().getContent();
Outlet<Bytes> out = //
To.outlet(inputStream).closeAtEnd(//
inputStream).closeAtEnd(//
response).closeAtEnd(//
client).closeAtEnd(() -> LogUtil.info("END__ " + method + " " + url));
if (statusCode == HttpURLConnection.HTTP_OK)
return new HttpResult(statusCode, out);
else
throw new IOException(//
"HTTP returned " + statusCode + ": " + //
url + ": " + //
statusLine.getReasonPhrase() + ": " + out.collect(As::string));
}
use of org.apache.http.client.methods.HttpRequestBase in project scheduling by ow2-proactive.
the class AbstractCommand method execute.
protected HttpResponseWrapper execute(HttpUriRequest request, ApplicationContext currentContext) {
String sessionId = currentContext.getSessionId();
if (sessionId != null) {
request.setHeader("sessionid", sessionId);
}
CommonHttpClientBuilder httpClientBuilder = new HttpClientBuilder().useSystemProperties();
try {
if ("https".equals(request.getURI().getScheme()) && currentContext.canInsecureAccess()) {
httpClientBuilder.insecure(true);
}
HttpResponse response = httpClientBuilder.build().execute(request);
return new HttpResponseWrapper(response);
} catch (SSLPeerUnverifiedException sslException) {
throw new CLIException(CLIException.REASON_OTHER, "SSL error. Perhaps HTTPS certificate could not be validated, " + "you can try with -k or insecure() for insecure SSL connection.", sslException);
} catch (Exception e) {
throw new CLIException(CLIException.REASON_OTHER, e.getMessage(), e);
} finally {
((HttpRequestBase) request).releaseConnection();
}
}
Aggregations