use of org.apache.http.entity.mime.content.FileBody in project acceptance-test-harness by jenkinsci.
the class FormElementPath method uploadPlugin.
private void uploadPlugin(URL url, File file) throws IOException {
try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
HttpPost post = new HttpPost(new URL(url, "pluginManager/uploadPlugin").toExternalForm());
FileBody fileBody = new FileBody(file, ContentType.DEFAULT_BINARY);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
builder.addPart("upfile", fileBody);
post.setEntity(builder.build());
HttpResponse response = httpClient.execute(post, HttpUtils.buildHttpClientContext(url, credentials));
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 302) {
// Redirect to updateCenter
throw new IOException("Could not upload plugin, received " + statusCode + ": " + EntityUtils.toString(response.getEntity()));
}
}
}
Aggregations