1
1
/*
2
- * Copyright 2018-2024 the original author or authors.
2
+ * Copyright 2018-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
17
17
package io .spring .githubchangeloggenerator .github .service ;
18
18
19
19
import java .lang .reflect .Array ;
20
+ import java .net .URI ;
20
21
import java .util .ArrayList ;
21
22
import java .util .Arrays ;
22
23
import java .util .List ;
@@ -103,7 +104,17 @@ private <T> Page<T> getPage(Class<T> type, String url, Object... uriVariables) {
103
104
if (!StringUtils .hasText (url )) {
104
105
return null ;
105
106
}
106
- ResponseEntity <T []> response = this .restTemplate .getForEntity (url , arrayType (type ), uriVariables );
107
+ return pageFrom (this .restTemplate .getForEntity (url , arrayType (type ), uriVariables ), type );
108
+ }
109
+
110
+ private <T > Page <T > getPage (Class <T > type , URI uri ) {
111
+ if (uri == null ) {
112
+ return null ;
113
+ }
114
+ return pageFrom (this .restTemplate .getForEntity (uri , arrayType (type )), type );
115
+ }
116
+
117
+ private <T > Page <T > pageFrom (ResponseEntity <T []> response , Class <T > type ) {
107
118
return new Page <>(Arrays .asList (response .getBody ()), () -> getPage (type , getNextUrl (response .getHeaders ())));
108
119
}
109
120
@@ -112,12 +123,12 @@ private <T> Class<T[]> arrayType(Class<T> elementType) {
112
123
return (Class <T []>) Array .newInstance (elementType , 0 ).getClass ();
113
124
}
114
125
115
- private String getNextUrl (HttpHeaders headers ) {
126
+ private URI getNextUrl (HttpHeaders headers ) {
116
127
String links = headers .getFirst ("Link" );
117
128
for (String link : StringUtils .commaDelimitedListToStringArray (links )) {
118
129
Matcher matcher = LINK_PATTERN .matcher (link .trim ());
119
130
if (matcher .matches () && "next" .equals (matcher .group (2 ))) {
120
- return matcher .group (1 );
131
+ return URI . create ( matcher .group (1 ) );
121
132
}
122
133
}
123
134
return null ;
0 commit comments