Skip to content
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

Restore bytcode compatibility #1689

Merged
merged 1 commit into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 82 additions & 7 deletions core/src/main/java/feign/AsyncFeign.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
package feign;

import feign.Logger.Level;
import feign.Request.Options;
import feign.Target.HardCodedTarget;
import feign.codec.Decoder;
import feign.codec.Encoder;
import feign.codec.ErrorDecoder;
import java.io.IOException;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -70,17 +73,46 @@ public AsyncBuilder<C> defaultContextSupplier(Supplier<C> supplier) {
return this;
}

public AsyncBuilder<C> defaultContextSupplier(AsyncContextSupplier<C> supplier) {
this.defaultContextSupplier = supplier;
public AsyncBuilder<C> client(AsyncClient<C> client) {
this.client = client;
return this;
}

@Override
public AsyncBuilder<C> mapAndDecode(ResponseMapper mapper, Decoder decoder) {
return super.mapAndDecode(mapper, decoder);
}

public AsyncBuilder<C> client(AsyncClient<C> client) {
this.client = client;
return this;
@Override
public AsyncBuilder<C> decoder(Decoder decoder) {
return super.decoder(decoder);
}

@Override
@Deprecated
public AsyncBuilder<C> decode404() {
return super.decode404();
}

@Override
public AsyncBuilder<C> dismiss404() {
return super.dismiss404();
}

@Override
public AsyncBuilder<C> errorDecoder(ErrorDecoder errorDecoder) {
return super.errorDecoder(errorDecoder);
}

@Override
public AsyncBuilder<C> doNotCloseAfterDecode() {
return super.doNotCloseAfterDecode();
}

public AsyncBuilder<C> defaultContextSupplier(AsyncContextSupplier<C> supplier) {
this.defaultContextSupplier = supplier;
return this;
}

public <T> T target(Class<T> apiType, String url) {
return target(new HardCodedTarget<>(apiType, url));
Expand All @@ -98,6 +130,51 @@ public <T> T target(Target<T> target, C context) {
return build().newInstance(target, context);
}

@Override
public AsyncBuilder<C> logLevel(Level logLevel) {
return super.logLevel(logLevel);
}

@Override
public AsyncBuilder<C> contract(Contract contract) {
return super.contract(contract);
}

@Override
public AsyncBuilder<C> logger(Logger logger) {
return super.logger(logger);
}

@Override
public AsyncBuilder<C> encoder(Encoder encoder) {
return super.encoder(encoder);
}

@Override
public AsyncBuilder<C> queryMapEncoder(QueryMapEncoder queryMapEncoder) {
return super.queryMapEncoder(queryMapEncoder);
}

@Override
public AsyncBuilder<C> options(Options options) {
return super.options(options);
}

@Override
public AsyncBuilder<C> requestInterceptor(RequestInterceptor requestInterceptor) {
return super.requestInterceptor(requestInterceptor);
}

@Override
public AsyncBuilder<C> requestInterceptors(Iterable<RequestInterceptor> requestInterceptors) {
return super.requestInterceptors(requestInterceptors);
}

@Override
public AsyncBuilder<C> invocationHandlerFactory(InvocationHandlerFactory invocationHandlerFactory) {
return super.invocationHandlerFactory(invocationHandlerFactory);
}

public AsyncFeign<C> build() {
super.enrich();
ThreadLocal<AsyncInvocation<C>> activeContextHolder = new ThreadLocal<>();
Expand Down Expand Up @@ -216,8 +293,6 @@ protected AsyncFeign(Feign feign, AsyncContextSupplier<C> defaultContextSupplier
this.defaultContextSupplier = defaultContextSupplier;
}



@Override
public <T> T newInstance(Target<T> target) {
return newInstance(target, defaultContextSupplier.newContext());
Expand Down
89 changes: 89 additions & 0 deletions core/src/main/java/feign/Feign.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
package feign;

import feign.ReflectiveFeign.ParseHandlersByName;
import feign.Request.Options;
import feign.Target.HardCodedTarget;
import feign.codec.Decoder;
import feign.codec.Encoder;
import feign.codec.ErrorDecoder;
import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
Expand Down Expand Up @@ -94,12 +97,98 @@ public static class Builder extends BaseBuilder<Builder> {
private Client client = new Client.Default(null, null);
private boolean forceDecoding = false;

@Override
public Builder logLevel(Logger.Level logLevel) {
return super.logLevel(logLevel);
}

@Override
public Builder contract(Contract contract) {
return super.contract(contract);
}

public Builder client(Client client) {
this.client = client;

return this;
}

@Override
public Builder retryer(Retryer retryer) {
return super.retryer(retryer);
}

@Override
public Builder logger(Logger logger) {
return super.logger(logger);
}

@Override
public Builder encoder(Encoder encoder) {
return super.encoder(encoder);
}

@Override
public Builder decoder(Decoder decoder) {
return super.decoder(decoder);
}

@Override
public Builder queryMapEncoder(QueryMapEncoder queryMapEncoder) {
return super.queryMapEncoder(queryMapEncoder);
}

@Override
public Builder mapAndDecode(ResponseMapper mapper, Decoder decoder) {
return super.mapAndDecode(mapper, decoder);
}

@Deprecated
@Override
public Builder decode404() {
return super.decode404();
}

@Override
public Builder errorDecoder(ErrorDecoder errorDecoder) {
return super.errorDecoder(errorDecoder);
}

@Override
public Builder options(Options options) {
return super.options(options);
}

@Override
public Builder requestInterceptor(RequestInterceptor requestInterceptor) {
return super.requestInterceptor(requestInterceptor);
}

@Override
public Builder requestInterceptors(Iterable<RequestInterceptor> requestInterceptors) {
return super.requestInterceptors(requestInterceptors);
}

@Override
public Builder invocationHandlerFactory(InvocationHandlerFactory invocationHandlerFactory) {
return super.invocationHandlerFactory(invocationHandlerFactory);
}

@Override
public Builder doNotCloseAfterDecode() {
return super.doNotCloseAfterDecode();
}

@Override
public Builder exceptionPropagationPolicy(ExceptionPropagationPolicy propagationPolicy) {
return super.exceptionPropagationPolicy(propagationPolicy);
}

@Override
public Builder addCapability(Capability capability) {
return super.addCapability(capability);
}

/**
* Internal - used to indicate that the decoder should be immediately called
*/
Expand Down
42 changes: 0 additions & 42 deletions core/src/test/java/feign/BaseBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,54 +17,12 @@
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.RETURNS_MOCKS;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import org.junit.Test;
import org.mockito.Mockito;

public class BaseBuilderTest {

@Test
public void avoidDuplicationsBetweenBuilders() {
List<String> builderA = getExclusiveMethods(Feign.Builder.class);
List<String> builderB = getExclusiveMethods(AsyncFeign.AsyncBuilder.class);

assertThat(builderA).noneMatch(m -> builderB.contains(m));
assertThat(builderB).noneMatch(m -> builderA.contains(m));

}

@Test
public void avoidDuplicationsBetweenAsyncBuilderAndBaseBuilder() {
List<String> builderA = getExclusiveMethods(BaseBuilder.class);
List<String> builderB = getExclusiveMethods(AsyncFeign.AsyncBuilder.class);

assertThat(builderA).noneMatch(m -> builderB.contains(m));
assertThat(builderB).noneMatch(m -> builderA.contains(m));

}

@Test
public void avoidDuplicationsBetweenBuilderAndBaseBuilder() {
List<String> builderA = getExclusiveMethods(Feign.Builder.class);
List<String> builderB = getExclusiveMethods(BaseBuilder.class);

assertThat(builderA).noneMatch(m -> builderB.contains(m));
assertThat(builderB).noneMatch(m -> builderA.contains(m));

}

private List<String> getExclusiveMethods(Class<?> clazz) {
return Arrays.stream(clazz.getDeclaredMethods())
.filter(m -> !Objects.equals(m.getName(), "target"))
.filter(m -> !Objects.equals(m.getName(), "build"))
.filter(m -> !m.isSynthetic())
.map(m -> m.getName() + "#" + Arrays.toString(m.getParameterTypes()))
.collect(Collectors.toList());
}

@Test
public void checkEnrichTouchesAllAsyncBuilderFields()
throws IllegalArgumentException, IllegalAccessException {
Expand Down