Skip to content

Commit 52b74c9

Browse files
author
adriancole
committed
cleaned up usage of util and removed unused URI parser
1 parent 83a4df9 commit 52b74c9

7 files changed

Lines changed: 27 additions & 53 deletions

File tree

feign-core/src/main/java/feign/MethodHandler.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import java.io.IOException;
1919
import java.lang.reflect.Type;
20-
import java.net.URI;
2120

2221
import javax.inject.Inject;
2322
import javax.inject.Provider;
@@ -28,9 +27,7 @@
2827

2928
import static feign.FeignException.errorExecuting;
3029
import static feign.FeignException.errorReading;
31-
import static feign.Util.LOCATION;
3230
import static feign.Util.checkNotNull;
33-
import static feign.Util.firstOrNull;
3431

3532
final class MethodHandler {
3633

@@ -109,10 +106,6 @@ public Object executeAndDecode(String configKey, RequestTemplate template, Type
109106
if (response.status() >= 200 && response.status() < 300) {
110107
if (returnType.equals(Response.class)) {
111108
return response;
112-
} else if (returnType == URI.class && response.body() == null) {
113-
String location = firstOrNull(response.headers(), LOCATION);
114-
if (location != null)
115-
return URI.create(location);
116109
} else if (returnType == void.class) {
117110
return null;
118111
}

feign-core/src/main/java/feign/Util.java

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,10 @@ public class Util {
3131
private Util() { // no instances
3232
}
3333

34-
// feign.Util
35-
/**
36-
* The HTTP Accept header field name.
37-
*/
38-
public static final String ACCEPT = "Accept";
3934
/**
4035
* The HTTP Content-Length header field name.
4136
*/
4237
public static final String CONTENT_LENGTH = "Content-Length";
43-
/**
44-
* The HTTP Content-Type header field name.
45-
*/
46-
public static final String CONTENT_TYPE = "Content-Type";
47-
/**
48-
* The HTTP Host header field name.
49-
*/
50-
public static final String HOST = "Host";
51-
/**
52-
* The HTTP Location header field name.
53-
*/
54-
public static final String LOCATION = "Location";
5538
/**
5639
* The HTTP Retry-After header field name.
5740
*/
@@ -108,19 +91,6 @@ public static String emptyToNull(String string) {
10891
return string == null || string.isEmpty() ? null : string;
10992
}
11093

111-
public static String join(char separator, String... parts) {
112-
if (parts == null || parts.length == 0)
113-
return "";
114-
StringBuilder to = new StringBuilder();
115-
for (int i = 0; i < parts.length; i++) {
116-
to.append(parts[i]);
117-
if (i + 1 < parts.length) {
118-
to.append(separator);
119-
}
120-
}
121-
return to.toString();
122-
}
123-
12494
/**
12595
* Adapted from {@code com.google.common.base.Strings#emptyToNull}.
12696
*/
@@ -144,11 +114,4 @@ public static <T> T[] toArray(Iterable<? extends T> iterable, Class<T> type) {
144114
public static <T> Collection<T> valuesOrEmpty(Map<String, Collection<T>> map, String key) {
145115
return map.containsKey(key) ? map.get(key) : Collections.<T>emptyList();
146116
}
147-
148-
public static <T> T firstOrNull(Map<String, Collection<T>> map, String key) {
149-
if (map.containsKey(key) && !map.get(key).isEmpty()) {
150-
return map.get(key).iterator().next();
151-
}
152-
return null;
153-
}
154117
}

feign-core/src/main/java/feign/codec/ErrorDecoder.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import java.text.DateFormat;
2020
import java.text.ParseException;
2121
import java.text.SimpleDateFormat;
22+
import java.util.Collection;
2223
import java.util.Date;
24+
import java.util.Map;
2325

2426
import feign.FeignException;
2527
import feign.Response;
@@ -28,7 +30,6 @@
2830
import static feign.FeignException.errorStatus;
2931
import static feign.Util.RETRY_AFTER;
3032
import static feign.Util.checkNotNull;
31-
import static feign.Util.firstOrNull;
3233
import static java.util.Locale.US;
3334
import static java.util.concurrent.TimeUnit.NANOSECONDS;
3435
import static java.util.concurrent.TimeUnit.SECONDS;
@@ -86,6 +87,13 @@ public Object decode(String methodKey, Response response, Type type) throws Thro
8687
throw new RetryableException(exception.getMessage(), exception, retryAfter);
8788
throw exception;
8889
}
90+
91+
private <T> T firstOrNull(Map<String, Collection<T>> map, String key) {
92+
if (map.containsKey(key) && !map.get(key).isEmpty()) {
93+
return map.get(key).iterator().next();
94+
}
95+
return null;
96+
}
8997
};
9098

9199
/**

feign-core/src/test/java/feign/DefaultContractTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import javax.inject.Named;
2626

27-
import static feign.Util.CONTENT_TYPE;
2827
import static org.testng.Assert.assertEquals;
2928
import static org.testng.Assert.assertFalse;
3029
import static org.testng.Assert.assertNull;
@@ -142,7 +141,7 @@ interface BodyWithoutParameters {
142141

143142
@Test public void producesAddsContentTypeHeader() throws Exception {
144143
MethodMetadata md = contract.parseAndValidatateMetadata(BodyWithoutParameters.class.getDeclaredMethod("post"));
145-
assertEquals(md.template().headers().get(CONTENT_TYPE), ImmutableSet.of("application/xml"));
144+
assertEquals(md.template().headers().get("Content-Type"), ImmutableSet.of("application/xml"));
146145
}
147146

148147
interface WithURIParam {

feign-core/src/test/java/feign/examples/AWSSignatureVersion4.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import static com.google.common.collect.Iterables.transform;
3838
import static com.google.common.hash.Hashing.sha256;
3939
import static com.google.common.io.BaseEncoding.base16;
40-
import static feign.Util.HOST;
4140
import static feign.Util.UTF_8;
4241

4342
// http://docs.aws.amazon.com/general/latest/gr/signature-version-4.html
@@ -54,7 +53,7 @@ public AWSSignatureVersion4(String accessKey, String secretKey) {
5453
}
5554

5655
@Override public Request apply(RequestTemplate input) {
57-
input.header(HOST, URI.create(input.url()).getHost());
56+
input.header("Host", URI.create(input.url()).getHost());
5857
TreeMultimap<String, String> sortedLowercaseHeaders = TreeMultimap.create();
5958
for (String key : input.headers().keySet()) {
6059
sortedLowercaseHeaders.putAll(trimToLowercase.apply(key),

feign-jaxrs/src/main/java/feign/jaxrs/JAXRSModule.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@
3333
import feign.Contract;
3434
import feign.MethodMetadata;
3535

36-
import static feign.Util.ACCEPT;
37-
import static feign.Util.CONTENT_TYPE;
3836
import static feign.Util.checkState;
39-
import static feign.Util.join;
4037

4138
@dagger.Module(library = true)
4239
public final class JAXRSModule {
40+
static final String ACCEPT = "Accept";
41+
static final String CONTENT_TYPE = "Content-Type";
4342

4443
@Provides Contract provideContract() {
4544
return new JAXRSContract();
@@ -103,4 +102,17 @@ protected boolean processAnnotationsOnParameter(MethodMetadata data, Annotation[
103102
return isHttpParam;
104103
}
105104
}
105+
106+
private static String join(char separator, String... parts) {
107+
if (parts == null || parts.length == 0)
108+
return "";
109+
StringBuilder to = new StringBuilder();
110+
for (int i = 0; i < parts.length; i++) {
111+
to.append(parts[i]);
112+
if (i + 1 < parts.length) {
113+
to.append(separator);
114+
}
115+
}
116+
return to.toString();
117+
}
106118
}

feign-jaxrs/src/test/java/feign/jaxrs/JAXRSContractTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import feign.MethodMetadata;
4343
import feign.Response;
4444

45-
import static feign.Util.CONTENT_TYPE;
45+
import static feign.jaxrs.JAXRSModule.CONTENT_TYPE;
4646
import static javax.ws.rs.HttpMethod.DELETE;
4747
import static javax.ws.rs.HttpMethod.GET;
4848
import static javax.ws.rs.HttpMethod.POST;

0 commit comments

Comments
 (0)