16
16
17
17
package org .springframework .boot .build .bom .bomr .github ;
18
18
19
- import java .io .IOException ;
20
- import java .util .Arrays ;
21
19
import java .util .Base64 ;
20
+ import java .util .Collections ;
22
21
23
22
import com .fasterxml .jackson .databind .ObjectMapper ;
24
23
25
- import org .springframework .http .HttpRequest ;
26
24
import org .springframework .http .MediaType ;
27
- import org .springframework .http .client .ClientHttpRequestExecution ;
28
- import org .springframework .http .client .ClientHttpRequestInterceptor ;
29
- import org .springframework .http .client .ClientHttpResponse ;
30
25
import org .springframework .http .converter .json .MappingJackson2HttpMessageConverter ;
31
26
import org .springframework .web .client .RestTemplate ;
32
27
import org .springframework .web .util .DefaultUriBuilderFactory ;
@@ -51,19 +46,13 @@ final class StandardGitHub implements GitHub {
51
46
@ Override
52
47
public GitHubRepository getRepository (String organization , String name ) {
53
48
RestTemplate restTemplate = new RestTemplate (
54
- Arrays .asList (new MappingJackson2HttpMessageConverter (new ObjectMapper ())));
55
- restTemplate .getInterceptors ().add (new ClientHttpRequestInterceptor () {
56
-
57
- @ Override
58
- public ClientHttpResponse intercept (HttpRequest request , byte [] body , ClientHttpRequestExecution execution )
59
- throws IOException {
60
- request .getHeaders ().add ("User-Agent" , StandardGitHub .this .username );
61
- request .getHeaders ().add ("Authorization" , "Basic " + Base64 .getEncoder ().encodeToString (
62
- (StandardGitHub .this .username + ":" + StandardGitHub .this .password ).getBytes ()));
63
- request .getHeaders ().add ("Accept" , MediaType .APPLICATION_JSON_VALUE );
64
- return execution .execute (request , body );
65
- }
66
-
49
+ Collections .singletonList (new MappingJackson2HttpMessageConverter (new ObjectMapper ())));
50
+ restTemplate .getInterceptors ().add ((request , body , execution ) -> {
51
+ request .getHeaders ().add ("User-Agent" , StandardGitHub .this .username );
52
+ request .getHeaders ().add ("Authorization" , "Basic " + Base64 .getEncoder ()
53
+ .encodeToString ((StandardGitHub .this .username + ":" + StandardGitHub .this .password ).getBytes ()));
54
+ request .getHeaders ().add ("Accept" , MediaType .APPLICATION_JSON_VALUE );
55
+ return execution .execute (request , body );
67
56
});
68
57
UriTemplateHandler uriTemplateHandler = new DefaultUriBuilderFactory (
69
58
"https://api.github.com/repos/" + organization + "/" + name + "/" );
0 commit comments