diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/play25/Play25CallFactory.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/play25/Play25CallFactory.mustache index b62c78aadb8..93df7a2718d 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/play25/Play25CallFactory.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/play25/Play25CallFactory.mustache @@ -6,6 +6,7 @@ import okio.BufferedSource; import play.libs.ws.WSClient; import play.libs.ws.WSRequest; import play.libs.ws.WSResponse; +import play.libs.ws.WSRequestFilter; import java.io.IOException; import java.net.MalformedURLException; @@ -31,11 +32,19 @@ public class Play25CallFactory implements okhttp3.Call.Factory { /** Extra query parameters to add to request */ private List extraQueryParams = new ArrayList<>(); + + /** Filters (interceptors) */ + private List filters = new ArrayList<>(); public Play25CallFactory(WSClient wsClient) { this.wsClient = wsClient; } + public Play25CallFactory(WSClient wsClient, List filters) { + this.wsClient = wsClient; + this.filters.addAll(filters); + } + public Play25CallFactory(WSClient wsClient, Map extraHeaders, List extraQueryParams) { this.wsClient = wsClient; @@ -74,7 +83,7 @@ public class Play25CallFactory implements okhttp3.Call.Factory { } } - return new PlayWSCall(wsClient, rb.build()); + return new PlayWSCall(wsClient, this.filters, rb.build()); } /** @@ -84,12 +93,14 @@ public class Play25CallFactory implements okhttp3.Call.Factory { private final WSClient wsClient; private WSRequest wsRequest; + private List filters; private final Request request; - public PlayWSCall(WSClient wsClient, Request request) { + public PlayWSCall(WSClient wsClient, List filters, Request request) { this.wsClient = wsClient; this.request = request; + this.filters = filters; } @Override @@ -126,6 +137,7 @@ public class Play25CallFactory implements okhttp3.Call.Factory { if (request.body() != null) { addBody(wsRequest); } + filters.stream().forEach(f -> wsRequest.withRequestFilter(f)); return wsRequest.execute(request.method()); } catch (Exception e) { diff --git a/samples/client/petstore/java/retrofit2-play25/src/main/java/io/swagger/client/Play25CallFactory.java b/samples/client/petstore/java/retrofit2-play25/src/main/java/io/swagger/client/Play25CallFactory.java index 5085288b800..ba5434f53f2 100644 --- a/samples/client/petstore/java/retrofit2-play25/src/main/java/io/swagger/client/Play25CallFactory.java +++ b/samples/client/petstore/java/retrofit2-play25/src/main/java/io/swagger/client/Play25CallFactory.java @@ -6,6 +6,7 @@ import play.libs.ws.WSClient; import play.libs.ws.WSRequest; import play.libs.ws.WSResponse; +import play.libs.ws.WSRequestFilter; import java.io.IOException; import java.net.MalformedURLException; @@ -31,11 +32,19 @@ public class Play25CallFactory implements okhttp3.Call.Factory { /** Extra query parameters to add to request */ private List extraQueryParams = new ArrayList<>(); + + /** Filters (interceptors) */ + private List filters = new ArrayList<>(); public Play25CallFactory(WSClient wsClient) { this.wsClient = wsClient; } + public Play25CallFactory(WSClient wsClient, List filters) { + this.wsClient = wsClient; + this.filters.addAll(filters); + } + public Play25CallFactory(WSClient wsClient, Map extraHeaders, List extraQueryParams) { this.wsClient = wsClient; @@ -74,7 +83,7 @@ public Call newCall(Request request) { } } - return new PlayWSCall(wsClient, rb.build()); + return new PlayWSCall(wsClient, this.filters, rb.build()); } /** @@ -84,12 +93,14 @@ static class PlayWSCall implements Call { private final WSClient wsClient; private WSRequest wsRequest; + private List filters; private final Request request; - public PlayWSCall(WSClient wsClient, Request request) { + public PlayWSCall(WSClient wsClient, List filters, Request request) { this.wsClient = wsClient; this.request = request; + this.filters = filters; } @Override @@ -126,6 +137,7 @@ CompletionStage executeAsync() { if (request.body() != null) { addBody(wsRequest); } + filters.stream().forEach(f -> wsRequest.withRequestFilter(f)); return wsRequest.execute(request.method()); } catch (Exception e) {