-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Streaming Rest Call - returning the response input stream without… #379
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant new line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
return status >= 200 && status < 300; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got an empty reason phrase on my environment:
java.lang.AssertionError: expected [Not Found] but found []
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
* 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion - please consider making ArtifactoryStreamingResponse AutoClosable to allow using easily it with try-with-resources
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
public interface ArtifactoryStreamingResponse extends BaseArtifactoryResponse { | ||
|
||
InputStream getInputStream() throws IOException; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
InputStream getInputStream(String path) throws IOException; | ||
|
||
InputStream getInputStreamWithHeaders(String path, Map<String, String> headers) throws IOException; | ||
|
||
HttpResponse execute(HttpUriRequest request) throws IOException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so
@@ -42,10 +44,14 @@ public interface Artifactory extends ApiInterface, AutoCloseable { | |||
|
|||
ArtifactoryResponse restCall(ArtifactoryRequest artifactoryRequest) throws IOException; | |||
|
|||
ArtifactoryStreamingResponse streamingRestCall(ArtifactoryRequest artifactoryRequest) throws IOException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's document it to the README
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done and tested
README.md
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String rawBody = IOUtils.toString(response.getInputStream(),StandardCharsets.UTF_8); | |
String rawBody = IOUtils.toString(response.getInputStream(), StandardCharsets.UTF_8); |
… the wrappers