|
9 | 9 |
|
10 | 10 | package org.elasticsearch.gradle.internal.snyk; |
11 | 11 |
|
12 | | -import org.apache.http.client.methods.CloseableHttpResponse; |
13 | | -import org.apache.http.client.methods.HttpPut; |
14 | | -import org.apache.http.entity.FileEntity; |
15 | | -import org.apache.http.impl.client.CloseableHttpClient; |
16 | | -import org.apache.http.impl.client.HttpClients; |
17 | | -import org.apache.http.util.EntityUtils; |
| 12 | +import org.apache.hc.client5.http.classic.methods.HttpPut; |
| 13 | +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; |
| 14 | +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; |
| 15 | +import org.apache.hc.client5.http.impl.classic.HttpClients; |
| 16 | +import org.apache.hc.core5.http.ContentType; |
| 17 | +import org.apache.hc.core5.http.ParseException; |
| 18 | +import org.apache.hc.core5.http.io.entity.EntityUtils; |
| 19 | +import org.apache.hc.core5.http.io.entity.FileEntity; |
18 | 20 | import org.gradle.api.DefaultTask; |
19 | 21 | import org.gradle.api.GradleException; |
20 | 22 | import org.gradle.api.file.RegularFileProperty; |
@@ -61,16 +63,16 @@ void upload() { |
61 | 63 | HttpPut putRequest = new HttpPut(endpoint); |
62 | 64 | putRequest.addHeader("Authorization", "token " + token.get()); |
63 | 65 | putRequest.addHeader("Content-Type", "application/json"); |
64 | | - putRequest.setEntity(new FileEntity(inputFile.getAsFile().get())); |
| 66 | + putRequest.setEntity(new FileEntity(inputFile.getAsFile().get(), ContentType.APPLICATION_JSON)); |
65 | 67 | response = client.execute(putRequest); |
66 | | - int statusCode = response.getStatusLine().getStatusCode(); |
| 68 | + int statusCode = response.getCode(); |
67 | 69 | String responseString = EntityUtils.toString(response.getEntity()); |
68 | 70 | getLogger().info("Snyk API call response status: " + statusCode); |
69 | 71 | if (statusCode != HttpURLConnection.HTTP_CREATED) { |
70 | 72 | throw new GradleException("Uploading Snyk Graph failed with http code " + statusCode + ": " + responseString); |
71 | 73 | } |
72 | 74 | getLogger().info(responseString); |
73 | | - } catch (IOException e) { |
| 75 | + } catch (IOException | ParseException e) { |
74 | 76 | throw new GradleException("Failed to call API endpoint to submit updated dependency graph", e); |
75 | 77 | } |
76 | 78 | } |
|
0 commit comments