14
14
import java .io .IOException ;
15
15
import java .lang .reflect .Field ;
16
16
import java .lang .reflect .Type ;
17
+ import java .util .function .Function ;
17
18
18
19
public class Pager {
19
20
private Request originalRequest ;
20
21
private String _continue ;
21
22
private String resourceVersion ;
22
- private int limit ;
23
+ private Integer limit ;
23
24
private ApiClient client ;
24
25
private Call call ;
25
26
private Type listType ;
26
27
27
- public Pager (ApiClient client , Call call , int limit , Type listType ) {
28
+ public Pager (ApiClient client , Call call , Integer limit , Type listType ) {
28
29
this .client = client ;
29
30
this .call = call ;
30
31
this .limit = limit ;
@@ -51,12 +52,10 @@ public <T> T next()
51
52
} else if (_continue == null && originalRequest != null ) {
52
53
// list was exhausted at server
53
54
V1ConfigMapList list =
54
- client .getJSON ().deserialize ("{}" , new TypeToken <V1ConfigMapList >() {}.getType ());
55
- } else {
56
- // subsequent calls
55
+ client .getJSON ().deserialize ("{}" , listType );
56
+ }
57
57
Request nextRequest = transFormRequest ();
58
58
call = client .getHttpClient ().newCall (nextRequest );
59
- }
60
59
return executeRequest (client , call , listType );
61
60
}
62
61
@@ -66,9 +65,10 @@ private Request transFormRequest() {
66
65
.httpUrl ()
67
66
.newBuilder ()
68
67
.setQueryParameter ("continue" , _continue )
69
- .setQueryParameter ("limit" , String .valueOf (limit ))
68
+ .setQueryParameter ("limit" , ( limit == null )? "-1" : String .valueOf (limit ))
70
69
// .addQueryParameter("resourceversion", resourceVersion)
71
70
.build ();
71
+ System .out .println (url );
72
72
Request request = new Request .Builder ().headers (originalRequest .headers ()).url (url ).build ();
73
73
return request ;
74
74
}
0 commit comments