Browse Source

feat: Added decodeVoid feature (#2131)

* feat: Added decodeVoid feature

* fix: Added decodeVoid for AsyncFeign

---------

Co-authored-by: Marvin Froeder <velo@users.noreply.github.com>
pull/2142/head
Malik Zharykov 1 year ago committed by GitHub
parent
commit
3e089ffba5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      core/src/main/java/feign/AsyncFeign.java
  2. 4
      core/src/main/java/feign/AsyncResponseHandler.java
  3. 6
      core/src/main/java/feign/BaseBuilder.java
  4. 7
      core/src/main/java/feign/Feign.java
  5. 7
      core/src/main/java/feign/ResponseHandler.java

7
core/src/main/java/feign/AsyncFeign.java

@ -119,6 +119,11 @@ public final class AsyncFeign<C> {
return super.doNotCloseAfterDecode(); return super.doNotCloseAfterDecode();
} }
@Override
public AsyncBuilder<C> decodeVoid() {
return super.decodeVoid();
}
public AsyncBuilder<C> defaultContextSupplier(AsyncContextSupplier<C> supplier) { public AsyncBuilder<C> defaultContextSupplier(AsyncContextSupplier<C> supplier) {
this.defaultContextSupplier = supplier; this.defaultContextSupplier = supplier;
return this; return this;
@ -196,7 +201,7 @@ public final class AsyncFeign<C> {
decoder, decoder,
errorDecoder, errorDecoder,
dismiss404, dismiss404,
closeAfterDecode, responseInterceptor), closeAfterDecode, decodeVoid, responseInterceptor),
AsyncResponseHandler.class, AsyncResponseHandler.class,
capabilities); capabilities);

4
core/src/main/java/feign/AsyncResponseHandler.java

@ -28,11 +28,11 @@ class AsyncResponseHandler {
private final ResponseHandler responseHandler; private final ResponseHandler responseHandler;
AsyncResponseHandler(Level logLevel, Logger logger, Decoder decoder, AsyncResponseHandler(Level logLevel, Logger logger, Decoder decoder,
ErrorDecoder errorDecoder, boolean dismiss404, boolean closeAfterDecode, ErrorDecoder errorDecoder, boolean dismiss404, boolean closeAfterDecode, boolean decodeVoid,
ResponseInterceptor responseInterceptor) { ResponseInterceptor responseInterceptor) {
this.responseHandler = new ResponseHandler( this.responseHandler = new ResponseHandler(
logLevel, logger, decoder, logLevel, logger, decoder,
errorDecoder, dismiss404, closeAfterDecode, errorDecoder, dismiss404, closeAfterDecode, decodeVoid,
responseInterceptor); responseInterceptor);
} }

6
core/src/main/java/feign/BaseBuilder.java

@ -43,6 +43,7 @@ public abstract class BaseBuilder<B extends BaseBuilder<B>> {
protected Encoder encoder = new Encoder.Default(); protected Encoder encoder = new Encoder.Default();
protected Decoder decoder = new Decoder.Default(); protected Decoder decoder = new Decoder.Default();
protected boolean closeAfterDecode = true; protected boolean closeAfterDecode = true;
protected boolean decodeVoid = false;
protected QueryMapEncoder queryMapEncoder = new FieldQueryMapEncoder(); protected QueryMapEncoder queryMapEncoder = new FieldQueryMapEncoder();
protected ErrorDecoder errorDecoder = new ErrorDecoder.Default(); protected ErrorDecoder errorDecoder = new ErrorDecoder.Default();
protected Options options = new Options(); protected Options options = new Options();
@ -106,6 +107,11 @@ public abstract class BaseBuilder<B extends BaseBuilder<B>> {
return thisB; return thisB;
} }
public B decodeVoid() {
this.decodeVoid = true;
return thisB;
}
public B queryMapEncoder(QueryMapEncoder queryMapEncoder) { public B queryMapEncoder(QueryMapEncoder queryMapEncoder) {
this.queryMapEncoder = queryMapEncoder; this.queryMapEncoder = queryMapEncoder;
return thisB; return thisB;

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

@ -178,6 +178,11 @@ public abstract class Feign {
return super.doNotCloseAfterDecode(); return super.doNotCloseAfterDecode();
} }
@Override
public Builder decodeVoid() {
return super.decodeVoid();
}
@Override @Override
public Builder exceptionPropagationPolicy(ExceptionPropagationPolicy propagationPolicy) { public Builder exceptionPropagationPolicy(ExceptionPropagationPolicy propagationPolicy) {
return super.exceptionPropagationPolicy(propagationPolicy); return super.exceptionPropagationPolicy(propagationPolicy);
@ -201,7 +206,7 @@ public abstract class Feign {
final ResponseHandler responseHandler = final ResponseHandler responseHandler =
new ResponseHandler(logLevel, logger, decoder, errorDecoder, new ResponseHandler(logLevel, logger, decoder, errorDecoder,
dismiss404, closeAfterDecode, responseInterceptor); dismiss404, closeAfterDecode, decodeVoid, responseInterceptor);
MethodHandler.Factory<Object> methodHandlerFactory = MethodHandler.Factory<Object> methodHandlerFactory =
new SynchronousMethodHandler.Factory(client, retryer, requestInterceptors, new SynchronousMethodHandler.Factory(client, retryer, requestInterceptors,
responseHandler, logger, logLevel, propagationPolicy, responseHandler, logger, logLevel, propagationPolicy,

7
core/src/main/java/feign/ResponseHandler.java

@ -37,10 +37,12 @@ public class ResponseHandler {
private final boolean dismiss404; private final boolean dismiss404;
private final boolean closeAfterDecode; private final boolean closeAfterDecode;
private final boolean decodeVoid;
private final ResponseInterceptor responseInterceptor; private final ResponseInterceptor responseInterceptor;
public ResponseHandler(Level logLevel, Logger logger, Decoder decoder, public ResponseHandler(Level logLevel, Logger logger, Decoder decoder,
ErrorDecoder errorDecoder, boolean dismiss404, boolean closeAfterDecode, ErrorDecoder errorDecoder, boolean dismiss404, boolean closeAfterDecode, boolean decodeVoid,
ResponseInterceptor responseInterceptor) { ResponseInterceptor responseInterceptor) {
super(); super();
this.logLevel = logLevel; this.logLevel = logLevel;
@ -50,6 +52,7 @@ public class ResponseHandler {
this.dismiss404 = dismiss404; this.dismiss404 = dismiss404;
this.closeAfterDecode = closeAfterDecode; this.closeAfterDecode = closeAfterDecode;
this.responseInterceptor = responseInterceptor; this.responseInterceptor = responseInterceptor;
this.decodeVoid = decodeVoid;
} }
public Object handleResponse(String configKey, public Object handleResponse(String configKey,
@ -113,7 +116,7 @@ public class ResponseHandler {
} }
private Object decode(Response response, Type type) throws IOException { private Object decode(Response response, Type type) throws IOException {
if (isVoidType(type)) { if (isVoidType(type) && !decodeVoid) {
ensureClosed(response.body()); ensureClosed(response.body());
return null; return null;
} }

Loading…
Cancel
Save