mirror of
https://gitee.com/dcren/initializr.git
synced 2025-09-19 10:08:22 +08:00
Upgrade to Spring Boot 1.4.0.RELEASE
This commit upgrades to Spring Boot 1.4.0.RELEASE and bumps to Java8. It also migrate the cache library from Guava to Caffeeine. The git and build information are now exposed via the `info` endpoint. Closes gh-251
This commit is contained in:
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.initializr.actuate.stat
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
import org.springframework.http.HttpRequest
|
||||
import org.springframework.http.client.ClientHttpRequestExecution
|
||||
import org.springframework.http.client.ClientHttpRequestInterceptor
|
||||
import org.springframework.http.client.ClientHttpResponse
|
||||
import org.springframework.http.client.InterceptingClientHttpRequestFactory
|
||||
import org.springframework.util.Base64Utils
|
||||
import org.springframework.web.client.RestTemplate
|
||||
|
||||
/**
|
||||
* A simple {@link RestTemplate} extension that automatically provides the
|
||||
* {@code Authorization} header if credentials are provided.
|
||||
* <p>
|
||||
* Largely inspired from Spring Boot's {@code TestRestTemplate}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.0
|
||||
*/
|
||||
class BasicAuthRestTemplate extends RestTemplate {
|
||||
|
||||
/**
|
||||
* Create a new instance. {@code username} and {@code password} can be
|
||||
* {@code null} if no authentication is necessary.
|
||||
*/
|
||||
BasicAuthRestTemplate(String username, String password) {
|
||||
addAuthentication(username, password)
|
||||
}
|
||||
|
||||
private void addAuthentication(String username, String password) {
|
||||
if (!username) {
|
||||
return;
|
||||
}
|
||||
List<ClientHttpRequestInterceptor> interceptors = Collections
|
||||
.<ClientHttpRequestInterceptor> singletonList(
|
||||
new BasicAuthorizationInterceptor(username, password))
|
||||
setRequestFactory(new InterceptingClientHttpRequestFactory(getRequestFactory(),
|
||||
interceptors))
|
||||
}
|
||||
|
||||
private static class BasicAuthorizationInterceptor
|
||||
implements ClientHttpRequestInterceptor {
|
||||
|
||||
private final String username
|
||||
|
||||
private final String password
|
||||
|
||||
BasicAuthorizationInterceptor(String username, String password) {
|
||||
this.username = username;
|
||||
this.password = (password == null ? "" : password)
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
|
||||
ClientHttpRequestExecution execution) throws IOException {
|
||||
String token = Base64Utils.encodeToString(
|
||||
(this.username + ":" + this.password).getBytes(StandardCharsets.UTF_8))
|
||||
request.getHeaders().add("Authorization", "Basic " + token)
|
||||
return execution.execute(request, body)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import groovy.util.logging.Slf4j
|
||||
import io.spring.initializr.generator.ProjectRequestEvent
|
||||
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder
|
||||
import org.springframework.context.event.EventListener
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.http.RequestEntity
|
||||
@@ -51,8 +52,8 @@ class ProjectGenerationStatPublisher {
|
||||
this.documentFactory = documentFactory
|
||||
this.statsProperties = statsProperties
|
||||
this.objectMapper = createObjectMapper()
|
||||
this.restTemplate = new BasicAuthRestTemplate(
|
||||
statsProperties.elastic.username, statsProperties.elastic.password)
|
||||
this.restTemplate = new RestTemplateBuilder().basicAuthorization(
|
||||
statsProperties.elastic.username, statsProperties.elastic.password).build()
|
||||
this.retryTemplate = retryTemplate
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration
|
||||
import org.springframework.context.annotation.Import
|
||||
import org.springframework.http.HttpHeaders
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.RequestEntity
|
||||
@@ -44,7 +44,7 @@ import static org.junit.Assert.fail
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@SpringApplicationConfiguration(StatsMockController.class)
|
||||
@Import(StatsMockController)
|
||||
@ActiveProfiles(['test-default', 'test-custom-stats'])
|
||||
class MainControllerStatsIntegrationTests extends AbstractInitializrControllerIntegrationTests {
|
||||
|
||||
|
Reference in New Issue
Block a user