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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save