-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Adding Method to Retryable Exception for evaluation #744
Conversation
Closes OpenFeign#719 This change adds the original Request Method to `RetryableException`, allowing implementers to determine if a retry should occur based on method and exception type. To support this, `Response` objects now require that the original `Request` be present. Test Cases, benchmarks, and documentation have been added.
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 add a few pointer... overall looks good.
core/src/main/java/feign/Client.java
Outdated
@@ -65,7 +65,7 @@ public Default(SSLSocketFactory sslContextFactory, HostnameVerifier hostnameVeri | |||
@Override | |||
public Response execute(Request request, Options options) throws IOException { | |||
HttpURLConnection connection = convertAndSend(request, options); | |||
return convertResponse(connection).toBuilder().request(request).build(); | |||
return convertResponse(connection, request).toBuilder().request(request).build(); |
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.
By doing this you can eliminate the .toBuilder().request(request).build()
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 must have missed this one during testing. I'll remove it.
@@ -37,15 +41,15 @@ public static Request create(String method, | |||
return new Request(method, url, headers, body, charset); | |||
} | |||
|
|||
private final String method; | |||
private final Methods method; |
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.
Nice... maybe just call it Method
? Or HttpMethod
to avoid conflict with other methods =D
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 had not considered that, good catch! I'll rename to HttpMethod
@@ -45,11 +45,12 @@ | |||
|
|||
private Response(Builder builder) { | |||
checkState(builder.status >= 200, "Invalid status code: %s", builder.status); | |||
checkState(builder.request != null, "original request is required"); |
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.
why not use checkNotNull
?
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 wanted an IllegalStateException
thrown and not a NullPointerException
. From my point of view, I prefer not to throw NPE's directly. But I'm open to change it if you feel strongly enough.
checkNotNull(request, "the original request is required on all responses"); | ||
|
||
/* don't keep the body, we don't want to tie up memory on large requests */ | ||
this.request = Request.create( |
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.
IMO, Request
and Response
object are short lived, so, feels like any gain we would have memory usage by creating a new request, we would loose on GC time for 2 objects....
If someone decides to keep the Response in memory for some reason, I think, they would like to have the whole Request.
Lemme know your thoughts
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.
My concern is with larger requests that deal with multi-part uploads and pure binary requests. Keeping the body in memory after the request feels like it may lead to unexpected memory usages and leaks. I had not considered the GC impact.
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.
It feels like an early optimization for me.
What if we include the original Request
for now, and try to fix the problem when we spot real use cases?
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.
Understood. I'll change to to reference the original and not create a new request.
@@ -24,20 +24,23 @@ | |||
private static final long serialVersionUID = 1L; | |||
|
|||
private final Long retryAfter; | |||
private final String method; |
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.
What about using the enumeration Methods
?
@@ -54,7 +58,7 @@ public static Request create(String method, | |||
|
|||
/* Method to invoke on the server. */ | |||
public String method() { |
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 thin we should create a new method httpMethod()
that will return the enum and then deprecate this one to be removed on feign 12!?
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.
Yeah, let's do that. I had not added the Enum to RetryableException
due to this method. I'll make that change here and in RetryableException
@@ -13,6 +13,7 @@ | |||
*/ | |||
package feign.client; | |||
|
|||
import feign.FeignException; |
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.
Think that is not necessary
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'll clean that up.
@velo, remarks addressed and the PR has been updated. |
* Added `HttpMethod` enum that represents the supported HTTP methods replacing String handling. * Deprecated `Request#method()` in favor of `Request#httpMethod()`
47e071f
to
5993c5e
Compare
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.
LGTM, feel free to hit the button
@@ -43,7 +43,7 @@ public int status() { | |||
|
|||
static FeignException errorReading(Request request, Response ignored, IOException cause) { | |||
return new FeignException( | |||
format("%s reading %s %s", cause.getMessage(), request.method(), request.url()), | |||
format("%s reading %s %s", cause.getMessage(), request.httpMethod().name(), request.url()), |
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.
format
should be able to deal with Enum
s just fine. no need to call name()
There is no need to have an explicit call to `Enum.name`. Removed. Style Compliance.
Closes #719 This change adds the original Request Method to `RetryableException`, allowing implementers to determine if a retry should occur based on method and exception type. To support this, `Response` objects now require that the original `Request` be present. Test Cases, benchmarks, and documentation have been added. * Refactored Request Method Attribute on Requests * Added `HttpMethod` enum that represents the supported HTTP methods replacing String handling. * Deprecated `Request#method()` in favor of `Request#httpMethod()`
Closes #719 This change adds the original Request Method to `RetryableException`, allowing implementers to determine if a retry should occur based on method and exception type. To support this, `Response` objects now require that the original `Request` be present. Test Cases, benchmarks, and documentation have been added. * Refactored Request Method Attribute on Requests * Added `HttpMethod` enum that represents the supported HTTP methods replacing String handling. * Deprecated `Request#method()` in favor of `Request#httpMethod()`
Closes #719
This change adds the original Request Method to
RetryableException
,allowing implementers to determine if a retry should occur based on
method and exception type.
To support this,
Response
objects now require that the originalRequest
be present. Test Cases, benchmarks, and documentation havebeen added.