|
44 | 44 | import org.jfrog.build.api.release.Promotion;
|
45 | 45 | import org.jfrog.build.api.util.FileChecksumCalculator;
|
46 | 46 | import org.jfrog.build.api.util.Log;
|
47 |
| -import org.jfrog.build.client.ArtifactoryHttpClient; |
48 |
| -import org.jfrog.build.client.ArtifactoryUploadResponse; |
49 |
| -import org.jfrog.build.client.ArtifactoryVersion; |
50 |
| -import org.jfrog.build.client.PreemptiveHttpClient; |
| 47 | +import org.jfrog.build.client.*; |
51 | 48 | import org.jfrog.build.client.bintrayResponse.BintrayResponse;
|
52 | 49 | import org.jfrog.build.client.bintrayResponse.BintrayResponseFactory;
|
53 | 50 | import org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails;
|
@@ -83,6 +80,7 @@ public class ArtifactoryBuildInfoClient extends ArtifactoryBaseClient implements
|
83 | 80 | public static final String BUILD_BROWSE_URL = "/webapp/builds";
|
84 | 81 | public static final String APPLICATION_VND_ORG_JFROG_ARTIFACTORY_JSON = "application/vnd.org.jfrog.artifactory+json";
|
85 | 82 | public static final String APPLICATION_JSON = "application/json";
|
| 83 | + public static final String ITEM_LAST_MODIFIED = "/api/storage/"; |
86 | 84 |
|
87 | 85 | /**
|
88 | 86 | * Creates a new client for the given Artifactory url.
|
@@ -307,33 +305,28 @@ private HttpResponse sendHttpRequest(HttpUriRequest request, int ... httpStatuse
|
307 | 305 | }
|
308 | 306 | }
|
309 | 307 |
|
310 |
| - public String getItemLastModified(String path) throws IOException, ParseException { |
311 |
| - String url = artifactoryUrl + "/api/storage/" + path + "?lastModified&deep=1"; |
| 308 | + public ItemLastModified getItemLastModified(String path) throws IOException { |
| 309 | + String url = artifactoryUrl + ITEM_LAST_MODIFIED + path + "?lastModified"; |
312 | 310 | HttpGet get = new HttpGet(url);
|
313 | 311 | HttpResponse response = httpClient.getHttpClient().execute(get);
|
314 |
| - |
315 |
| - StatusLine statusLine = response.getStatusLine(); |
316 |
| - if (statusLine.getStatusCode() != HttpStatus.SC_OK) { |
317 |
| - HttpEntity entity = response.getEntity(); |
318 |
| - throw new IOException("Failed to obtain item info. Status code: " + statusLine.getStatusCode() + httpClient.getMessageFromEntity(entity)); |
319 |
| - } else { |
320 |
| - HttpEntity entity = response.getEntity(); |
321 |
| - if (entity != null) { |
322 |
| - InputStream content = entity.getContent(); |
323 |
| - JsonParser parser; |
324 |
| - try { |
325 |
| - parser = httpClient.createJsonParser(content); |
326 |
| - JsonNode result = parser.readValueAsTree(); |
327 |
| - return result.get("lastModified").asText(); |
328 |
| - } finally { |
329 |
| - if (content != null) { |
330 |
| - content.close(); |
331 |
| - } |
332 |
| - EntityUtils.consume(entity); |
| 312 | + int statusCode = response.getStatusLine().getStatusCode(); |
| 313 | + if (statusCode != HttpStatus.SC_OK) { |
| 314 | + throw new IOException("While requesting item info for path " + path + " received " + response.getStatusLine().getStatusCode() + ":" + httpClient.getMessageFromEntity(response.getEntity())); |
| 315 | + } |
| 316 | + HttpEntity httpEntity = response.getEntity(); |
| 317 | + if (httpEntity != null) { |
| 318 | + try (InputStream content = httpEntity.getContent()) { |
| 319 | + JsonNode result = httpClient.getJsonNode(httpEntity, content); |
| 320 | + JsonNode lastModified = result.get("lastModified"); |
| 321 | + JsonNode uri = result.get("uri"); |
| 322 | + if (lastModified == null || uri == null) { |
| 323 | + throw new IOException("Unexpected JSON response when requesting info for path " + path + httpClient.getMessageFromEntity(response.getEntity())); |
333 | 324 | }
|
| 325 | + |
| 326 | + return new ItemLastModified(uri.asText(), lastModified.asText()); |
334 | 327 | }
|
335 | 328 | }
|
336 |
| - return null; |
| 329 | + throw new IOException("The path " + path + " returned empty entity"); |
337 | 330 | }
|
338 | 331 |
|
339 | 332 | /**
|
|
0 commit comments