mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 02:55:19 +00:00
[Java] Added Play! WS filters support for retrofit2 client (#6499)
* added play! ws filters support * samples updated
This commit is contained in:
parent
594b390e11
commit
7f6bccb4ed
@ -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<Pair> extraQueryParams = new ArrayList<>();
|
||||
|
||||
/** Filters (interceptors) */
|
||||
private List<WSRequestFilter> filters = new ArrayList<>();
|
||||
|
||||
public Play25CallFactory(WSClient wsClient) {
|
||||
this.wsClient = wsClient;
|
||||
}
|
||||
|
||||
public Play25CallFactory(WSClient wsClient, List<WSRequestFilter> filters) {
|
||||
this.wsClient = wsClient;
|
||||
this.filters.addAll(filters);
|
||||
}
|
||||
|
||||
public Play25CallFactory(WSClient wsClient, Map<String, String> extraHeaders,
|
||||
List<Pair> 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<WSRequestFilter> filters;
|
||||
|
||||
private final Request request;
|
||||
|
||||
public PlayWSCall(WSClient wsClient, Request request) {
|
||||
public PlayWSCall(WSClient wsClient, List<WSRequestFilter> 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) {
|
||||
|
@ -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<Pair> extraQueryParams = new ArrayList<>();
|
||||
|
||||
/** Filters (interceptors) */
|
||||
private List<WSRequestFilter> filters = new ArrayList<>();
|
||||
|
||||
public Play25CallFactory(WSClient wsClient) {
|
||||
this.wsClient = wsClient;
|
||||
}
|
||||
|
||||
public Play25CallFactory(WSClient wsClient, List<WSRequestFilter> filters) {
|
||||
this.wsClient = wsClient;
|
||||
this.filters.addAll(filters);
|
||||
}
|
||||
|
||||
public Play25CallFactory(WSClient wsClient, Map<String, String> extraHeaders,
|
||||
List<Pair> 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<WSRequestFilter> filters;
|
||||
|
||||
private final Request request;
|
||||
|
||||
public PlayWSCall(WSClient wsClient, Request request) {
|
||||
public PlayWSCall(WSClient wsClient, List<WSRequestFilter> 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) {
|
||||
|
Loading…
Reference in New Issue
Block a user