diff --git a/core/src/main/java/feign/AsyncFeign.java b/core/src/main/java/feign/AsyncFeign.java index 1ff3b043f..422c25aa0 100644 --- a/core/src/main/java/feign/AsyncFeign.java +++ b/core/src/main/java/feign/AsyncFeign.java @@ -210,7 +210,7 @@ closeAfterDecode, decodeVoid, responseInterceptorChain()), responseHandler, logger, logLevel, propagationPolicy, methodInfoResolver, new RequestTemplateFactoryResolver(encoder, queryMapEncoder), - options, decoder, errorDecoder); + options); final ReflectiveFeign feign = new ReflectiveFeign<>(contract, methodHandlerFactory, invocationHandlerFactory, defaultContextSupplier); diff --git a/core/src/main/java/feign/AsynchronousMethodHandler.java b/core/src/main/java/feign/AsynchronousMethodHandler.java index 528eaccd2..56e7ebb63 100644 --- a/core/src/main/java/feign/AsynchronousMethodHandler.java +++ b/core/src/main/java/feign/AsynchronousMethodHandler.java @@ -15,8 +15,6 @@ import feign.InvocationHandlerFactory.MethodHandler; import feign.Request.Options; -import feign.codec.Decoder; -import feign.codec.ErrorDecoder; import java.io.IOException; import java.util.List; import java.util.Optional; @@ -35,29 +33,14 @@ final class AsynchronousMethodHandler implements MethodHandler { private final C requestContext; private final AsyncResponseHandler asyncResponseHandler; private final MethodInfo methodInfo; - private MethodHandlerConfiguration methodHandlerConfiguration = - new MethodHandlerConfiguration(null, null, null, null, null, null, null, null, null); - - - private AsynchronousMethodHandler(Target target, AsyncClient client, Retryer retryer, - List requestInterceptors, - Logger logger, Logger.Level logLevel, MethodMetadata metadata, - RequestTemplate.Factory buildTemplateFromArgs, Options options, - AsyncResponseHandler asyncResponseHandler, ExceptionPropagationPolicy propagationPolicy, - C requestContext, MethodInfo methodInfo) { - - this.methodHandlerConfiguration.setTarget(checkNotNull(target, "target")); - this.client = checkNotNull(client, "client for %s", target); - this.methodHandlerConfiguration.setRetryer(checkNotNull(retryer, "retryer for %s", target)); - this.methodHandlerConfiguration.setRequestInterceptors( - checkNotNull(requestInterceptors, "requestInterceptors for %s", target)); - this.methodHandlerConfiguration.setLogger(checkNotNull(logger, "logger for %s", target)); - this.methodHandlerConfiguration.setLogLevel(checkNotNull(logLevel, "logLevel for %s", target)); - this.methodHandlerConfiguration.setMetadata(checkNotNull(metadata, "metadata for %s", target)); - this.methodHandlerConfiguration - .setBuildTemplateFromArgs(checkNotNull(buildTemplateFromArgs, "metadata for %s", target)); - this.methodHandlerConfiguration.setOptions(checkNotNull(options, "options for %s", target)); - this.methodHandlerConfiguration.setPropagationPolicy(propagationPolicy); + private final MethodHandlerConfiguration methodHandlerConfiguration; + + private AsynchronousMethodHandler(MethodHandlerConfiguration methodHandlerConfiguration, + AsyncClient client, AsyncResponseHandler asyncResponseHandler, C requestContext, + MethodInfo methodInfo) { + this.methodHandlerConfiguration = + checkNotNull(methodHandlerConfiguration, "methodHandlerConfiguration"); + this.client = checkNotNull(client, "client for %s", methodHandlerConfiguration.getTarget()); this.requestContext = requestContext; this.asyncResponseHandler = asyncResponseHandler; this.methodInfo = methodInfo; @@ -248,8 +231,6 @@ static class Factory implements MethodHandler.Factory { private final MethodInfoResolver methodInfoResolver; private final RequestTemplateFactoryResolver requestTemplateFactoryResolver; private final Options options; - private final Decoder decoder; - private final ErrorDecoder errorDecoder; Factory(AsyncClient client, Retryer retryer, List requestInterceptors, AsyncResponseHandler responseHandler, @@ -257,9 +238,7 @@ static class Factory implements MethodHandler.Factory { ExceptionPropagationPolicy propagationPolicy, MethodInfoResolver methodInfoResolver, RequestTemplateFactoryResolver requestTemplateFactoryResolver, - Options options, - Decoder decoder, - ErrorDecoder errorDecoder) { + Options options) { this.client = checkNotNull(client, "client"); this.retryer = checkNotNull(retryer, "retryer"); this.requestInterceptors = checkNotNull(requestInterceptors, "requestInterceptors"); @@ -271,19 +250,20 @@ static class Factory implements MethodHandler.Factory { this.requestTemplateFactoryResolver = checkNotNull(requestTemplateFactoryResolver, "requestTemplateFactoryResolver"); this.options = checkNotNull(options, "options"); - this.errorDecoder = checkNotNull(errorDecoder, "errorDecoder"); - this.decoder = checkNotNull(decoder, "decoder"); } + @Override public MethodHandler create(Target target, - MethodMetadata md, + MethodMetadata metadata, C requestContext) { final RequestTemplate.Factory buildTemplateFromArgs = - requestTemplateFactoryResolver.resolve(target, md); - return new AsynchronousMethodHandler(target, client, retryer, requestInterceptors, - logger, logLevel, md, buildTemplateFromArgs, options, responseHandler, - propagationPolicy, requestContext, - methodInfoResolver.resolve(target.type(), md.method())); + requestTemplateFactoryResolver.resolve(target, metadata); + + MethodHandlerConfiguration methodHandlerConfiguration = + new MethodHandlerConfiguration(metadata, target, retryer, requestInterceptors, logger, + logLevel, buildTemplateFromArgs, options, propagationPolicy); + return new AsynchronousMethodHandler(methodHandlerConfiguration, client, responseHandler, + requestContext, methodInfoResolver.resolve(target.type(), metadata.method())); } } } diff --git a/core/src/main/java/feign/MethodHandlerConfiguration.java b/core/src/main/java/feign/MethodHandlerConfiguration.java index 25e7bb453..0524235e0 100644 --- a/core/src/main/java/feign/MethodHandlerConfiguration.java +++ b/core/src/main/java/feign/MethodHandlerConfiguration.java @@ -14,26 +14,27 @@ package feign; import java.util.List; +import static feign.Util.checkNotNull; public class MethodHandlerConfiguration { - private MethodMetadata metadata; + private final MethodMetadata metadata; - private Target target; + private final Target target; - private Retryer retryer; + private final Retryer retryer; - private List requestInterceptors; + private final List requestInterceptors; - private Logger logger; + private final Logger logger; - private Logger.Level logLevel; + private final Logger.Level logLevel; - private RequestTemplate.Factory buildTemplateFromArgs; + private final RequestTemplate.Factory buildTemplateFromArgs; - private Request.Options options; + private final Request.Options options; - private ExceptionPropagationPolicy propagationPolicy; + private final ExceptionPropagationPolicy propagationPolicy; public MethodMetadata getMetadata() { return metadata; @@ -71,55 +72,22 @@ public ExceptionPropagationPolicy getPropagationPolicy() { return propagationPolicy; } - public void setMetadata(MethodMetadata metadata) { - this.metadata = metadata; - } - - public void setTarget(Target target) { - this.target = target; - } - - public void setRetryer(Retryer retryer) { - this.retryer = retryer; - } - - public void setRequestInterceptors(List requestInterceptors) { - this.requestInterceptors = requestInterceptors; - } - - public void setLogger(Logger logger) { - this.logger = logger; - } - - public void setLogLevel(Logger.Level logLevel) { - this.logLevel = logLevel; - } - - public void setBuildTemplateFromArgs(RequestTemplate.Factory buildTemplateFromArgs) { - this.buildTemplateFromArgs = buildTemplateFromArgs; - } - - public void setOptions(Request.Options options) { - this.options = options; - } - - public void setPropagationPolicy(ExceptionPropagationPolicy propagationPolicy) { - this.propagationPolicy = propagationPolicy; - } public MethodHandlerConfiguration(MethodMetadata metadata, Target target, Retryer retryer, List requestInterceptors, Logger logger, Logger.Level logLevel, RequestTemplate.Factory buildTemplateFromArgs, Request.Options options, ExceptionPropagationPolicy propagationPolicy) { - this.metadata = metadata; - this.target = target; - this.retryer = retryer; - this.requestInterceptors = requestInterceptors; - this.logger = logger; - this.logLevel = logLevel; - this.buildTemplateFromArgs = buildTemplateFromArgs; - this.options = options; + this.target = checkNotNull(target, "target"); + this.retryer = checkNotNull(retryer, "retryer for %s", target); + this.requestInterceptors = + checkNotNull(requestInterceptors, "requestInterceptors for %s", target); + this.logger = checkNotNull(logger, "logger for %s", target); + this.logLevel = checkNotNull(logLevel, "logLevel for %s", target); + this.metadata = checkNotNull(metadata, "metadata for %s", target); + this.buildTemplateFromArgs = checkNotNull(buildTemplateFromArgs, "metadata for %s", target); + this.options = checkNotNull(options, "options for %s", target); this.propagationPolicy = propagationPolicy; + } } diff --git a/core/src/main/java/feign/SynchronousMethodHandler.java b/core/src/main/java/feign/SynchronousMethodHandler.java index b7da80fa0..f113fb3ea 100644 --- a/core/src/main/java/feign/SynchronousMethodHandler.java +++ b/core/src/main/java/feign/SynchronousMethodHandler.java @@ -18,8 +18,6 @@ import static feign.Util.checkNotNull; import feign.InvocationHandlerFactory.MethodHandler; import feign.Request.Options; -import feign.codec.Decoder; -import feign.codec.ErrorDecoder; import java.io.IOException; import java.util.List; import java.util.concurrent.TimeUnit; @@ -29,28 +27,14 @@ final class SynchronousMethodHandler implements MethodHandler { private final Client client; private final ResponseHandler responseHandler; - private MethodHandlerConfiguration methodHandlerConfiguration = - new MethodHandlerConfiguration(null, null, null, null, null, null, null, null, null); - - - private SynchronousMethodHandler(Target target, Client client, Retryer retryer, - List requestInterceptors, - Logger logger, Logger.Level logLevel, MethodMetadata metadata, - RequestTemplate.Factory buildTemplateFromArgs, Options options, - ResponseHandler responseHandler, ExceptionPropagationPolicy propagationPolicy) { - - this.methodHandlerConfiguration.setTarget(checkNotNull(target, "target")); - this.client = checkNotNull(client, "client for %s", target); - this.methodHandlerConfiguration.setRetryer(checkNotNull(retryer, "retryer for %s", target)); - this.methodHandlerConfiguration.setRequestInterceptors( - checkNotNull(requestInterceptors, "requestInterceptors for %s", target)); - this.methodHandlerConfiguration.setLogger(checkNotNull(logger, "logger for %s", target)); - this.methodHandlerConfiguration.setLogLevel(checkNotNull(logLevel, "logLevel for %s", target)); - this.methodHandlerConfiguration.setMetadata(checkNotNull(metadata, "metadata for %s", target)); - this.methodHandlerConfiguration - .setBuildTemplateFromArgs(checkNotNull(buildTemplateFromArgs, "metadata for %s", target)); - this.methodHandlerConfiguration.setOptions(checkNotNull(options, "options for %s", target)); - this.methodHandlerConfiguration.setPropagationPolicy(propagationPolicy); + private final MethodHandlerConfiguration methodHandlerConfiguration; + + private SynchronousMethodHandler(MethodHandlerConfiguration methodHandlerConfiguration, + Client client, ResponseHandler responseHandler) { + + this.methodHandlerConfiguration = + checkNotNull(methodHandlerConfiguration, "methodHandlerConfiguration"); + this.client = checkNotNull(client, "client for %s", methodHandlerConfiguration.getTarget()); this.responseHandler = responseHandler; } @@ -170,14 +154,16 @@ static class Factory implements MethodHandler.Factory { this.options = checkNotNull(options, "options"); } + @Override public MethodHandler create(Target target, MethodMetadata md, Object requestContext) { final RequestTemplate.Factory buildTemplateFromArgs = requestTemplateFactoryResolver.resolve(target, md); - return new SynchronousMethodHandler(target, client, retryer, requestInterceptors, - logger, logLevel, md, buildTemplateFromArgs, options, - responseHandler, propagationPolicy); + MethodHandlerConfiguration methodHandlerConfiguration = + new MethodHandlerConfiguration(md, target, retryer, requestInterceptors, logger, logLevel, + buildTemplateFromArgs, options, propagationPolicy); + return new SynchronousMethodHandler(methodHandlerConfiguration, client, responseHandler); } } }