Browse Source

Remove overrides = true on codec modules

4.x
adriancole 11 years ago
parent
commit
073e54ee39
  1. 1
      CHANGES.md
  2. 4
      README.md
  3. 12
      core/src/main/java/feign/Feign.java
  4. 16
      core/src/main/java/feign/ReflectiveFeign.java
  5. 30
      core/src/test/java/feign/FeignTest.java
  6. 2
      core/src/test/java/feign/examples/GitHubExample.java
  7. 2
      core/src/test/java/feign/examples/IAMExample.java
  8. 2
      gson/src/main/java/feign/gson/GsonModule.java

1
CHANGES.md

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
### Version 4.3
* Add ability to configure zero or more RequestInterceptors.
* Remove `overrides = true` on codec modules.
### Version 4.2/3.3
* Document and enforce JAX-RS annotation processing from server POV

4
README.md

@ -137,7 +137,7 @@ The `GsonModule` in the `feign-gson` extension configures a (`Decoder.TextStream @@ -137,7 +137,7 @@ The `GsonModule` in the `feign-gson` extension configures a (`Decoder.TextStream
Here's how you could write this yourself, using whatever library you prefer:
```java
@Module(overrides = true, library = true)
@Module(library = true)
static class JsonModule {
@Provides(type = SET) Decoder decoder(final JsonParser parser) {
return new Decoder.TextStream<Object>() {
@ -215,7 +215,7 @@ If you have to only grab a single field from a server response, you may find reg @@ -215,7 +215,7 @@ If you have to only grab a single field from a server response, you may find reg
Here's how our IAM example grabs only one xml element from a response.
```java
@Module(overrides = true, library = true)
@Module(library = true)
static class IAMModule {
@Provides(type = SET) Decoder arnDecoder() {
return Decoders.firstGroup("<Arn>([\\S&&[^<]]+)</Arn>");

12
core/src/main/java/feign/Feign.java

@ -124,18 +124,6 @@ public abstract class Feign implements Closeable { @@ -124,18 +124,6 @@ public abstract class Feign implements Closeable {
return new Options();
}
@Provides Set<Encoder> noEncoders() {
return Collections.emptySet();
}
@Provides Set<Decoder> noDecoders() {
return Collections.emptySet();
}
@Provides Set<IncrementalDecoder> noIncrementalDecoders() {
return Collections.emptySet();
}
/**
* Used for both http invocation and decoding when observers are used.
*/

16
core/src/main/java/feign/ReflectiveFeign.java

@ -33,9 +33,9 @@ import java.lang.reflect.Method; @@ -33,9 +33,9 @@ import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -109,7 +109,19 @@ public class ReflectiveFeign extends Feign { @@ -109,7 +109,19 @@ public class ReflectiveFeign extends Feign {
@dagger.Module(complete = false, injects = {Feign.class, MethodHandler.Factory.class}, library = true)
public static class Module {
@Provides(type = Provides.Type.SET_VALUES) Set<RequestInterceptor> noRequestInterceptors() {
return new LinkedHashSet<RequestInterceptor>();
return Collections.emptySet();
}
@Provides(type = Provides.Type.SET_VALUES) Set<Encoder> noEncoders() {
return Collections.emptySet();
}
@Provides(type = Provides.Type.SET_VALUES) Set<Decoder> noDecoders() {
return Collections.emptySet();
}
@Provides(type = Provides.Type.SET_VALUES) Set<IncrementalDecoder> noIncrementalDecoders() {
return Collections.emptySet();
}
@Provides Feign provideFeign(ReflectiveFeign in) {

30
core/src/test/java/feign/FeignTest.java

@ -90,7 +90,7 @@ public class FeignTest { @@ -90,7 +90,7 @@ public class FeignTest {
@RequestLine("POST /") Observable<Response> observableResponse();
@dagger.Module(overrides = true, library = true)
@dagger.Module(library = true)
static class Module {
@Provides(type = SET) Encoder defaultEncoder() {
return new Encoder.Text<Object>() {
@ -108,14 +108,6 @@ public class FeignTest { @@ -108,14 +108,6 @@ public class FeignTest {
};
}
// just run synchronously
@Provides @Singleton @Named("http") Executor httpExecutor() {
return new Executor() {
@Override public void execute(Runnable command) {
command.run();
}
};
}
}
}
@ -126,7 +118,8 @@ public class FeignTest { @@ -126,7 +118,8 @@ public class FeignTest {
server.play();
try {
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(), new TestInterface.Module());
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(),
new TestInterface.Module(), new RunSynchronous());
final AtomicBoolean success = new AtomicBoolean();
@ -160,7 +153,8 @@ public class FeignTest { @@ -160,7 +153,8 @@ public class FeignTest {
server.play();
try {
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(), new TestInterface.Module());
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(),
new TestInterface.Module(), new RunSynchronous());
final AtomicBoolean success = new AtomicBoolean();
@ -187,6 +181,17 @@ public class FeignTest { @@ -187,6 +181,17 @@ public class FeignTest {
}
}
@Module(library = true, overrides = true)
static class RunSynchronous {
@Provides @Singleton @Named("http") Executor httpExecutor() {
return new Executor() {
@Override public void execute(Runnable command) {
command.run();
}
};
}
}
@Test
public void incrementString() throws IOException, InterruptedException {
final MockWebServer server = new MockWebServer();
@ -194,7 +199,8 @@ public class FeignTest { @@ -194,7 +199,8 @@ public class FeignTest {
server.play();
try {
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(), new TestInterface.Module());
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(),
new TestInterface.Module(), new RunSynchronous());
final AtomicBoolean success = new AtomicBoolean();

2
core/src/test/java/feign/examples/GitHubExample.java

@ -97,7 +97,7 @@ public class GitHubExample { @@ -97,7 +97,7 @@ public class GitHubExample {
/**
* Here's how it looks to wire json codecs. Note, that you can always instead use {@code feign-gson}!
*/
@Module(overrides = true, library = true)
@Module(library = true)
static class GsonModule {
@Provides @Singleton Gson gson() {

2
core/src/test/java/feign/examples/IAMExample.java

@ -63,7 +63,7 @@ public class IAMExample { @@ -63,7 +63,7 @@ public class IAMExample {
}
}
@Module(overrides = true, library = true)
@Module(library = true)
static class IAMModule {
@Provides(type = SET) Decoder decoder() {
return Decoders.firstGroup("<Arn>([\\S&&[^<]]+)</Arn>");

2
gson/src/main/java/feign/gson/GsonModule.java

@ -43,7 +43,7 @@ import java.util.concurrent.atomic.AtomicBoolean; @@ -43,7 +43,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import static dagger.Provides.Type.SET;
@dagger.Module(library = true, overrides = true)
@dagger.Module(library = true)
public final class GsonModule {
@Provides(type = SET) Encoder encoder(GsonCodec codec) {

Loading…
Cancel
Save