Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-boot-admin
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-boot-admin
Commits
918201c2
Commit
918201c2
authored
Jul 10, 2016
by
Johannes Edmeier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove deprecations and use RestTemplateBuilder
parent
97335237
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
38 additions
and
99 deletions
+38
-99
SpringBootAdminApplication.java
...de/codecentric/boot/admin/SpringBootAdminApplication.java
+1
-1
AdminServerWebConfiguration.java
...entric/boot/admin/config/AdminServerWebConfiguration.java
+8
-5
AdminApplicationHazelcastTest.java
...codecentric/boot/admin/AdminApplicationHazelcastTest.java
+2
-3
AdminApplicationTest.java
.../java/de/codecentric/boot/admin/AdminApplicationTest.java
+5
-5
AdminServerWebConfigurationTest.java
...ic/boot/admin/config/AdminServerWebConfigurationTest.java
+3
-1
DiscoveryClientConfigurationTest.java
...c/boot/admin/config/DiscoveryClientConfigurationTest.java
+2
-0
NotifierConfigurationTest.java
...ecentric/boot/admin/config/NotifierConfigurationTest.java
+2
-2
StatusUpdaterTest.java
...de/codecentric/boot/admin/registry/StatusUpdaterTest.java
+4
-0
SpringBootAdminClientAutoConfiguration.java
.../admin/config/SpringBootAdminClientAutoConfiguration.java
+7
-16
BasicAuthHttpRequestInterceptor.java
...ntric/boot/admin/web/BasicAuthHttpRequestInterceptor.java
+0
-30
AdminClientPropertiesTest.java
...ecentric/boot/admin/config/AdminClientPropertiesTest.java
+1
-1
SpringBootAdminClientAutoConfigurationTest.java
...in/config/SpringBootAdminClientAutoConfigurationTest.java
+3
-1
BasicAuthHttpRequestInterceptorTest.java
...c/boot/admin/web/BasicAuthHttpRequestInterceptorTest.java
+0
-34
No files found.
spring-boot-admin-samples/spring-boot-admin-sample-war/src/main/java/de/codecentric/boot/admin/SpringBootAdminApplication.java
View file @
918201c2
...
...
@@ -3,7 +3,7 @@ package de.codecentric.boot.admin;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.
context.web
.SpringBootServletInitializer
;
import
org.springframework.boot.
web.support
.SpringBootServletInitializer
;
import
org.springframework.context.annotation.Configuration
;
import
de.codecentric.boot.admin.config.EnableAdminServer
;
...
...
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/config/AdminServerWebConfiguration.java
View file @
918201c2
...
...
@@ -22,6 +22,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import
org.springframework.boot.autoconfigure.web.ServerProperties
;
import
org.springframework.boot.context.event.ApplicationReadyEvent
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.web.client.RestTemplateBuilder
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.context.ApplicationEventPublisher
;
...
...
@@ -36,7 +37,6 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert
import
org.springframework.scheduling.config.ScheduledTaskRegistrar
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.client.DefaultResponseErrorHandler
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.ViewControllerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
...
...
@@ -81,6 +81,9 @@ public class AdminServerWebConfiguration extends WebMvcConfigurerAdapter
@Autowired
private
ResourcePatternResolver
resourcePatternResolver
;
@Autowired
private
RestTemplateBuilder
builder
;
@Bean
@ConditionalOnMissingBean
public
AdminServerProperties
adminServerProperties
()
{
...
...
@@ -178,15 +181,15 @@ public class AdminServerWebConfiguration extends WebMvcConfigurerAdapter
@Bean
@ConditionalOnMissingBean
public
StatusUpdater
statusUpdater
()
{
RestTemplate
template
=
new
RestTemplate
();
template
.
getMessageConverters
().
add
(
new
MappingJackson2HttpMessageConverter
());
template
.
setErrorHandler
(
new
DefaultResponseErrorHandler
()
{
builder
.
messageConverters
(
new
MappingJackson2HttpMessageConverter
())
.
errorHandler
(
new
DefaultResponseErrorHandler
()
{
@Override
protected
boolean
hasError
(
HttpStatus
statusCode
)
{
return
false
;
}
});
StatusUpdater
statusUpdater
=
new
StatusUpdater
(
template
,
applicationStore
);
StatusUpdater
statusUpdater
=
new
StatusUpdater
(
builder
.
build
(),
applicationStore
);
statusUpdater
.
setStatusLifetime
(
adminServerProperties
().
getMonitor
().
getStatusLifetime
());
return
statusUpdater
;
}
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/AdminApplicationHazelcastTest.java
View file @
918201c2
...
...
@@ -30,12 +30,11 @@ import org.junit.Test;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.context.embedded.EmbeddedWebApplicationContext
;
import
org.springframework.boot.test.TestRestTemplate
;
import
org.springframework.boot.test.
web.client.
TestRestTemplate
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.client.RestTemplate
;
import
com.hazelcast.config.Config
;
import
com.hazelcast.config.EvictionPolicy
;
...
...
@@ -51,7 +50,7 @@ import de.codecentric.boot.admin.model.Application;
* @author Dennis Schulte
*/
public
class
AdminApplicationHazelcastTest
{
private
RestTemplate
template
=
new
TestRestTemplate
();
private
Test
RestTemplate
template
=
new
TestRestTemplate
();
private
EmbeddedWebApplicationContext
instance1
;
private
EmbeddedWebApplicationContext
instance2
;
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/AdminApplicationTest.java
View file @
918201c2
...
...
@@ -24,9 +24,9 @@ import org.junit.Test;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.test.
SpringApplicationConfiguration
;
import
org.springframework.boot.test.
TestRestTemplate
;
import
org.springframework.boot.test.
WebIntegrationTest
;
import
org.springframework.boot.test.
context.SpringBootTest
;
import
org.springframework.boot.test.
context.SpringBootTest.WebEnvironment
;
import
org.springframework.boot.test.
web.client.TestRestTemplate
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
...
...
@@ -42,8 +42,8 @@ import de.codecentric.boot.admin.model.Application;
* @author Dennis Schulte
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@Spring
ApplicationConfiguration
(
classes
=
TestAdminApplication
.
class
)
@WebIntegrationTest
({
"server.port=0"
,
"spring.cloud.config.enabled=false"
})
@Spring
BootTest
(
classes
=
TestAdminApplication
.
class
,
webEnvironment
=
WebEnvironment
.
RANDOM_PORT
,
properties
=
{
"spring.cloud.config.enabled=false"
})
public
class
AdminApplicationTest
{
@Value
(
"${local.server.port}"
)
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/config/AdminServerWebConfigurationTest.java
View file @
918201c2
...
...
@@ -30,7 +30,8 @@ import org.junit.Test;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration
;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration.RestTemplateConfiguration
;
import
org.springframework.boot.test.util.EnvironmentTestUtils
;
import
org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -131,6 +132,7 @@ public class AdminServerWebConfigurationTest {
applicationContext
.
register
(
config
);
}
applicationContext
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
);
applicationContext
.
register
(
RestTemplateConfiguration
.
class
);
applicationContext
.
register
(
ServerPropertiesAutoConfiguration
.
class
);
applicationContext
.
register
(
HazelcastAutoConfiguration
.
class
);
applicationContext
.
register
(
HazelcastStoreConfiguration
.
class
);
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/config/DiscoveryClientConfigurationTest.java
View file @
918201c2
...
...
@@ -8,6 +8,7 @@ import org.junit.After;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration.RestTemplateConfiguration
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration
;
import
org.springframework.cloud.commons.util.UtilAutoConfiguration
;
...
...
@@ -77,6 +78,7 @@ public class DiscoveryClientConfigurationTest {
}
applicationContext
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
);
applicationContext
.
register
(
RestTemplateConfiguration
.
class
);
applicationContext
.
register
(
ServerPropertiesAutoConfiguration
.
class
);
applicationContext
.
register
(
AdminServerWebConfiguration
.
class
);
applicationContext
.
register
(
DiscoveryClientConfiguration
.
class
);
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/config/NotifierConfigurationTest.java
View file @
918201c2
...
...
@@ -28,7 +28,7 @@ import java.util.List;
import
org.junit.After
;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration
;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.boot.test.
util.
EnvironmentTestUtils
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
...
...
@@ -158,7 +158,7 @@ public class NotifierConfigurationTest {
}
private
static
class
TestNotifier
implements
Notifier
{
private
List
<
ClientApplicationEvent
>
events
=
new
ArrayList
<
ClientApplicationEvent
>();
private
List
<
ClientApplicationEvent
>
events
=
new
ArrayList
<>();
@Override
public
void
notify
(
ClientApplicationEvent
event
)
{
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/registry/StatusUpdaterTest.java
View file @
918201c2
...
...
@@ -56,6 +56,7 @@ public class StatusUpdaterTest {
}
@Test
@SuppressWarnings
(
"rawtypes"
)
public
void
test_update_statusChanged
()
{
when
(
template
.
getForEntity
(
"health"
,
Map
.
class
)).
thenReturn
(
ResponseEntity
.
ok
().
body
((
Map
)
Collections
.
singletonMap
(
"status"
,
"UP"
)));
...
...
@@ -70,6 +71,7 @@ public class StatusUpdaterTest {
}
@Test
@SuppressWarnings
(
"rawtypes"
)
public
void
test_update_statusUnchanged
()
{
when
(
template
.
getForEntity
(
"health"
,
Map
.
class
))
.
thenReturn
(
ResponseEntity
.
ok
((
Map
)
Collections
.
singletonMap
(
"status"
,
"UNKNOWN"
)));
...
...
@@ -82,6 +84,7 @@ public class StatusUpdaterTest {
}
@Test
@SuppressWarnings
(
"rawtypes"
)
public
void
test_update_noBody
()
{
// HTTP 200 - UP
when
(
template
.
getForEntity
(
"health"
,
Map
.
class
)).
thenReturn
(
ResponseEntity
.
ok
((
Map
)
null
));
...
...
@@ -113,6 +116,7 @@ public class StatusUpdaterTest {
}
@Test
@SuppressWarnings
(
"rawtypes"
)
public
void
test_updateStatusForApplications
()
{
Application
app1
=
Application
.
create
(
"foo"
).
withId
(
"id-1"
).
withHealthUrl
(
"health-1"
)
.
build
();
...
...
spring-boot-admin-starter-client/src/main/java/de/codecentric/boot/admin/config/SpringBootAdminClientAutoConfiguration.java
View file @
918201c2
...
...
@@ -15,21 +15,17 @@
*/
package
de
.
codecentric
.
boot
.
admin
.
config
;
import
java.util.Arrays
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.web.client.RestTemplateBuilder
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.client.ClientHttpRequestInterceptor
;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
import
org.springframework.web.client.RestTemplate
;
import
de.codecentric.boot.admin.services.ApplicationRegistrator
;
import
de.codecentric.boot.admin.services.RegistrationApplicationListener
;
import
de.codecentric.boot.admin.web.BasicAuthHttpRequestInterceptor
;
@Configuration
@EnableConfigurationProperties
({
AdminProperties
.
class
,
AdminClientProperties
.
class
})
...
...
@@ -42,25 +38,20 @@ public class SpringBootAdminClientAutoConfiguration {
@Autowired
private
AdminProperties
admin
;
@Autowired
private
RestTemplateBuilder
builder
;
/**
* Task that registers the application at the spring-boot-admin application.
*/
@Bean
@ConditionalOnMissingBean
public
ApplicationRegistrator
registrator
()
{
return
new
ApplicationRegistrator
(
createRestTemplate
(
admin
),
admin
,
client
);
}
protected
RestTemplate
createRestTemplate
(
AdminProperties
admin
)
{
RestTemplate
template
=
new
RestTemplate
();
template
.
getMessageConverters
().
add
(
new
MappingJackson2HttpMessageConverter
());
builder
.
messageConverters
(
new
MappingJackson2HttpMessageConverter
());
if
(
admin
.
getUsername
()
!=
null
)
{
template
.
setInterceptors
(
Arrays
.<
ClientHttpRequestInterceptor
>
asList
(
new
BasicAuthHttpRequestInterceptor
(
admin
.
getUsername
(),
admin
.
getPassword
())));
builder
.
basicAuthorization
(
admin
.
getUsername
(),
admin
.
getPassword
());
}
return
template
;
return
new
ApplicationRegistrator
(
builder
.
build
(),
admin
,
client
);
}
/**
...
...
spring-boot-admin-starter-client/src/main/java/de/codecentric/boot/admin/web/BasicAuthHttpRequestInterceptor.java
deleted
100644 → 0
View file @
97335237
package
de
.
codecentric
.
boot
.
admin
.
web
;
import
java.io.IOException
;
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
com.fasterxml.jackson.core.Base64Variants
;
public
class
BasicAuthHttpRequestInterceptor
implements
ClientHttpRequestInterceptor
{
private
final
String
encodedAuth
;
public
BasicAuthHttpRequestInterceptor
(
String
username
,
String
password
)
{
String
auth
=
username
+
":"
+
password
;
encodedAuth
=
"Basic "
+
Base64Variants
.
MIME_NO_LINEFEEDS
.
encode
(
auth
.
getBytes
(
StandardCharsets
.
US_ASCII
));
}
@Override
public
ClientHttpResponse
intercept
(
HttpRequest
request
,
byte
[]
body
,
ClientHttpRequestExecution
execution
)
throws
IOException
{
request
.
getHeaders
().
add
(
"Authorization"
,
encodedAuth
);
return
execution
.
execute
(
request
,
body
);
}
}
spring-boot-admin-starter-client/src/test/java/de/codecentric/boot/admin/config/AdminClientPropertiesTest.java
View file @
918201c2
...
...
@@ -15,7 +15,7 @@ import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration
;
import
org.springframework.boot.context.event.ApplicationReadyEvent
;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.boot.test.
util.
EnvironmentTestUtils
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
public
class
AdminClientPropertiesTest
{
...
...
spring-boot-admin-starter-client/src/test/java/de/codecentric/boot/admin/config/SpringBootAdminClientAutoConfigurationTest.java
View file @
918201c2
...
...
@@ -6,7 +6,8 @@ import org.junit.After;
import
org.junit.Test
;
import
org.springframework.boot.actuate.autoconfigure.ManagementServerPropertiesAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration
;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration.RestTemplateConfiguration
;
import
org.springframework.boot.test.util.EnvironmentTestUtils
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
de.codecentric.boot.admin.services.ApplicationRegistrator
;
...
...
@@ -44,6 +45,7 @@ public class SpringBootAdminClientAutoConfigurationTest {
private
void
load
(
String
...
environment
)
{
AnnotationConfigWebApplicationContext
applicationContext
=
new
AnnotationConfigWebApplicationContext
();
applicationContext
.
register
(
ServerPropertiesAutoConfiguration
.
class
);
applicationContext
.
register
(
RestTemplateConfiguration
.
class
);
applicationContext
.
register
(
ManagementServerPropertiesAutoConfiguration
.
class
);
applicationContext
.
register
(
SpringBootAdminClientAutoConfiguration
.
class
);
EnvironmentTestUtils
.
addEnvironment
(
applicationContext
,
environment
);
...
...
spring-boot-admin-starter-client/src/test/java/de/codecentric/boot/admin/web/BasicAuthHttpRequestInterceptorTest.java
deleted
100644 → 0
View file @
97335237
package
de
.
codecentric
.
boot
.
admin
.
web
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
java.io.IOException
;
import
java.util.Collections
;
import
org.junit.Test
;
import
org.springframework.http.HttpRequest
;
import
org.springframework.http.client.ClientHttpRequestExecution
;
import
org.springframework.http.client.ClientHttpResponse
;
import
org.springframework.mock.http.client.MockClientHttpRequest
;
public
class
BasicAuthHttpRequestInterceptorTest
{
@Test
public
void
test
()
throws
IOException
{
BasicAuthHttpRequestInterceptor
interceptor
=
new
BasicAuthHttpRequestInterceptor
(
"admin"
,
"secret"
);
HttpRequest
request
=
new
MockClientHttpRequest
();
interceptor
.
intercept
(
request
,
(
byte
[])
null
,
new
ClientHttpRequestExecution
()
{
@Override
public
ClientHttpResponse
execute
(
HttpRequest
paramHttpRequest
,
byte
[]
paramArrayOfByte
)
throws
IOException
{
return
null
;
}
});
assertEquals
(
Collections
.
singletonList
(
"Basic YWRtaW46c2VjcmV0"
),
request
.
getHeaders
().
get
(
"Authorization"
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment