Add Streaming Rest Call - returning the response input stream without…#379
Conversation
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
alenon
left a comment
There was a problem hiding this comment.
Please consider moving the isSuccessResponse to the common class
And making the common implementation to look like the following
public static boolean isSuccessfulResponseCode(int status) { return 200 <= status && status < 300; }
That was my first change but I saw that in the function getInputStreamWithHeaders: .../services/src/main/groovy/org/jfrog/artifactory/client/impl)/ArtifactoryImpl.java: So I understood that for streaming only 200 and 206 are valid |
|
I have read the CLA Document and I hereby sign the CLA |
aec4be2 to
618959e
Compare
| private static final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
|
||
| private HttpResponse httpResponse; | ||
|
|
There was a problem hiding this comment.
Redundant new line
|
|
||
| return status >= 200 && status < 300; | ||
| } | ||
|
|
| ArtifactoryStreamingResponse response = artifactory.streamingRestCall(request); | ||
| assertFalse(response.isSuccessResponse()); | ||
| assertEquals(response.getStatusLine().getStatusCode(), 404); | ||
| assertEquals(response.getStatusLine().getReasonPhrase(), "Not Found"); |
There was a problem hiding this comment.
I got an empty reason phrase on my environment:
java.lang.AssertionError: expected [Not Found] but found []
| * ArtifactoryStreamingResponse object returned from {@link Artifactory#streamingRestCall(ArtifactoryRequest)}. | ||
| * acts as a wrapper for {@link org.apache.http.HttpResponse}. | ||
| */ | ||
| public interface ArtifactoryStreamingResponse extends BaseArtifactoryResponse { |
There was a problem hiding this comment.
Suggestion - please consider making ArtifactoryStreamingResponse AutoClosable to allow using easily it with try-with-resources
| public interface ArtifactoryStreamingResponse extends BaseArtifactoryResponse { | ||
|
|
||
| InputStream getInputStream() throws IOException; | ||
|
|
|
|
||
| InputStream getInputStreamWithHeaders(String path, Map<String, String> headers) throws IOException; | ||
|
|
||
| HttpResponse execute(HttpUriRequest request) throws IOException; |
|
|
||
| ArtifactoryResponse restCall(ArtifactoryRequest artifactoryRequest) throws IOException; | ||
|
|
||
| ArtifactoryStreamingResponse streamingRestCall(ArtifactoryRequest artifactoryRequest) throws IOException; |
| assert response.isSuccessResponse(); | ||
|
|
||
| // Get the response raw body using input stream | ||
| String rawBody = IOUtils.toString(response.getInputStream(),StandardCharsets.UTF_8); |
There was a problem hiding this comment.
| String rawBody = IOUtils.toString(response.getInputStream(),StandardCharsets.UTF_8); | |
| String rawBody = IOUtils.toString(response.getInputStream(), StandardCharsets.UTF_8); |
… the wrappers