-
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
Changes from 3 commits
806149c
5993c5e
e918aca
bf3df0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,48 +13,89 @@ | |
*/ | ||
package feign; | ||
|
||
import static feign.Util.checkNotNull; | ||
import static feign.Util.valuesOrEmpty; | ||
import java.net.HttpURLConnection; | ||
import java.nio.charset.Charset; | ||
import java.util.Collection; | ||
import java.util.Map; | ||
import static feign.Util.checkNotNull; | ||
import static feign.Util.valuesOrEmpty; | ||
|
||
/** | ||
* An immutable request to an http server. | ||
*/ | ||
public final class Request { | ||
|
||
public enum HttpMethod { | ||
GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH | ||
} | ||
|
||
/** | ||
* No parameters can be null except {@code body} and {@code charset}. All parameters must be | ||
* effectively immutable, via safe copies, not mutating or otherwise. | ||
* | ||
* @deprecated {@link #create(HttpMethod, String, Map, byte[], Charset)} | ||
*/ | ||
public static Request create(String method, | ||
String url, | ||
Map<String, Collection<String>> headers, | ||
byte[] body, | ||
Charset charset) { | ||
return new Request(method, url, headers, body, charset); | ||
checkNotNull(method, "httpMethod of %s", method); | ||
HttpMethod httpMethod = HttpMethod.valueOf(method.toUpperCase()); | ||
return create(httpMethod, url, headers, body, charset); | ||
} | ||
|
||
private final String method; | ||
/** | ||
* Builds a Request. All parameters must be effectively immutable, via safe copies. | ||
* | ||
* @param httpMethod for the request. | ||
* @param url for the request. | ||
* @param headers to include. | ||
* @param body of the request, can be {@literal null} | ||
* @param charset of the request, can be {@literal null} | ||
* @return a Request | ||
*/ | ||
public static Request create(HttpMethod httpMethod, | ||
String url, | ||
Map<String, Collection<String>> headers, | ||
byte[] body, | ||
Charset charset) { | ||
return new Request(httpMethod, url, headers, body, charset); | ||
|
||
} | ||
|
||
private final HttpMethod httpMethod; | ||
private final String url; | ||
private final Map<String, Collection<String>> headers; | ||
private final byte[] body; | ||
private final Charset charset; | ||
|
||
Request(String method, String url, Map<String, Collection<String>> headers, byte[] body, | ||
Request(HttpMethod method, String url, Map<String, Collection<String>> headers, byte[] body, | ||
Charset charset) { | ||
this.method = checkNotNull(method, "method of %s", url); | ||
this.httpMethod = checkNotNull(method, "httpMethod of %s", method.name()); | ||
this.url = checkNotNull(url, "url"); | ||
this.headers = checkNotNull(headers, "headers of %s %s", method, url); | ||
this.body = body; // nullable | ||
this.charset = charset; // nullable | ||
} | ||
|
||
/* Method to invoke on the server. */ | ||
/** | ||
* Http Method for this request. | ||
* | ||
* @return the HttpMethod string | ||
* @deprecated @see {@link #httpMethod()} | ||
*/ | ||
public String method() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thin we should create a new method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, let's do that. I had not added the Enum to |
||
return method; | ||
return httpMethod.name(); | ||
} | ||
|
||
/** | ||
* Http Method for the request. | ||
* | ||
* @return the HttpMethod. | ||
*/ | ||
public HttpMethod httpMethod() { | ||
return this.httpMethod; | ||
} | ||
|
||
/* Fully resolved URL including query. */ | ||
|
@@ -89,7 +130,7 @@ public byte[] body() { | |
@Override | ||
public String toString() { | ||
StringBuilder builder = new StringBuilder(); | ||
builder.append(method).append(' ').append(url).append(" HTTP/1.1\n"); | ||
builder.append(httpMethod).append(' ').append(url).append(" HTTP/1.1\n"); | ||
for (String field : headers.keySet()) { | ||
for (String value : valuesOrEmpty(headers, field)) { | ||
builder.append(field).append(": ").append(value).append('\n'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,11 +45,12 @@ public final class Response implements Closeable { | |
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. why not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted an |
||
this.status = builder.status; | ||
this.request = builder.request; | ||
this.reason = builder.reason; // nullable | ||
this.headers = Collections.unmodifiableMap(caseInsensitiveCopyOf(builder.headers)); | ||
this.body = builder.body; // nullable | ||
this.request = builder.request; // nullable | ||
} | ||
|
||
public Builder toBuilder() { | ||
|
@@ -121,11 +122,9 @@ public Builder body(String text, Charset charset) { | |
|
||
/** | ||
* @see Response#request | ||
* | ||
* NOTE: will add null check in version 10 which may require changes to custom feign.Client | ||
* or loggers | ||
*/ | ||
public Builder request(Request request) { | ||
checkNotNull(request, "request is required"); | ||
this.request = request; | ||
return this; | ||
} | ||
|
@@ -168,7 +167,7 @@ public Body body() { | |
} | ||
|
||
/** | ||
* if present, the request that generated this response | ||
* the request that generated this response | ||
*/ | ||
public Request request() { | ||
return request; | ||
|
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 withEnum
s just fine. no need to callname()