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
a53ba390
Commit
a53ba390
authored
Apr 09, 2015
by
Johannes Stelzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add MappingJackson2HttpMessageConverter only if not present
fixes #61
parent
967525aa
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
15 deletions
+72
-15
application.yml
...ring-boot-admin-sample/src/main/resources/application.yml
+3
-0
pom.xml
spring-boot-admin-server/pom.xml
+7
-7
AdminServerWebConfiguration.java
...entric/boot/admin/config/AdminServerWebConfiguration.java
+27
-6
AdminServerWebConfigurationTest.java
...ic/boot/admin/config/AdminServerWebConfigurationTest.java
+35
-2
No files found.
spring-boot-admin-samples/spring-boot-admin-sample/src/main/resources/application.yml
View file @
a53ba390
...
...
@@ -14,6 +14,9 @@ spring:
cloud
:
config
:
enabled
:
false
jackson
:
serialization
:
indent_output
:
true
endpoints
:
health
:
...
...
spring-boot-admin-server/pom.xml
View file @
a53ba390
...
...
@@ -43,6 +43,11 @@
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-ribbon
</artifactId>
</exclusion>
<exclusion>
<!-- ships old hamcres matchers -->
<groupId>
org.mockito
</groupId>
<artifactId>
mockito-all
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
...
...
@@ -80,13 +85,8 @@
<!-- Test -->
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-test
</artifactId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
...
...
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/config/AdminServerWebConfiguration.java
View file @
a53ba390
...
...
@@ -47,14 +47,17 @@ import org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFil
import
org.springframework.cloud.netflix.zuul.web.ZuulController
;
import
org.springframework.cloud.netflix.zuul.web.ZuulHandlerMapping
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.context.ApplicationEvent
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.hazelcast.config.Config
;
import
com.hazelcast.core.EntryEvent
;
import
com.hazelcast.core.EntryListener
;
...
...
@@ -79,14 +82,32 @@ import de.codecentric.boot.admin.zuul.ApplicationRouteLocator;
import
de.codecentric.boot.admin.zuul.ApplicationRouteRefreshListener
;
@Configuration
public
class
AdminServerWebConfiguration
extends
WebMvcConfigurerAdapter
{
public
class
AdminServerWebConfiguration
extends
WebMvcConfigurerAdapter
implements
ApplicationContextAware
{
private
ApplicationContext
applicationContext
;
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
{
this
.
applicationContext
=
applicationContext
;
}
/**
* Add JSON MessageConverter to send JSON objects to web clients.
*/
@Override
public
void
configureMessageConverters
(
List
<
HttpMessageConverter
<?>>
converters
)
{
converters
.
add
(
new
MappingJackson2HttpMessageConverter
());
public
void
extendMessageConverters
(
List
<
HttpMessageConverter
<?>>
converters
)
{
if
(!
hasConverter
(
converters
,
MappingJackson2HttpMessageConverter
.
class
))
{
ObjectMapper
objectMapper
=
Jackson2ObjectMapperBuilder
.
json
().
applicationContext
(
this
.
applicationContext
)
.
build
();
converters
.
add
(
new
MappingJackson2HttpMessageConverter
(
objectMapper
));
}
}
private
boolean
hasConverter
(
List
<
HttpMessageConverter
<?>>
converters
,
Class
<?
extends
HttpMessageConverter
<?>>
clazz
)
{
for
(
HttpMessageConverter
<?>
converter
:
converters
)
{
if
(
clazz
.
isInstance
(
converter
))
{
return
true
;
}
}
return
false
;
}
/**
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/config/AdminServerWebConfigurationTest.java
View file @
a53ba390
package
de
.
codecentric
.
boot
.
admin
.
config
;
import
static
org
.
hamcrest
.
CoreMatchers
.
hasItem
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
CoreMatchers
.
isA
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration
;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
de.codecentric.boot.admin.discovery.ApplicationDiscoveryListener
;
...
...
@@ -26,6 +35,31 @@ public class AdminServerWebConfigurationTest {
}
@Test
public
void
jacksonMapperPresentFromDefault
()
{
AdminServerWebConfiguration
config
=
new
AdminServerWebConfiguration
();
List
<
HttpMessageConverter
<?>>
converters
=
new
ArrayList
<
HttpMessageConverter
<?>>();
converters
.
add
(
new
MappingJackson2HttpMessageConverter
());
config
.
extendMessageConverters
(
converters
);
assertThat
(
converters
,
hasItem
(
isA
(
MappingJackson2HttpMessageConverter
.
class
)));
assertThat
(
converters
.
size
(),
is
(
1
));
}
@Test
public
void
jacksonMapperPresentNeedExtend
()
{
AdminServerWebConfiguration
config
=
new
AdminServerWebConfiguration
();
List
<
HttpMessageConverter
<?>>
converters
=
new
ArrayList
<
HttpMessageConverter
<?>>();
config
.
extendMessageConverters
(
converters
);
assertThat
(
converters
,
hasItem
(
isA
(
MappingJackson2HttpMessageConverter
.
class
)));
assertThat
(
converters
.
size
(),
is
(
1
));
}
@Test
public
void
simpleConfig
()
{
load
(
"spring.boot.admin.hazelcast.enabled:false"
,
"spring.boot.admin.discovery.enabled:false"
);
assertTrue
(
context
.
getBean
(
ApplicationStore
.
class
)
instanceof
SimpleApplicationStore
);
...
...
@@ -46,15 +80,14 @@ public class AdminServerWebConfigurationTest {
context
.
getBean
(
ApplicationDiscoveryListener
.
class
);
}
private
void
load
(
String
...
environment
)
{
AnnotationConfigWebApplicationContext
applicationContext
=
new
AnnotationConfigWebApplicationContext
();
applicationContext
.
register
(
ServerPropertiesAutoConfiguration
.
class
);
applicationContext
.
register
(
NoopDiscoveryClientAutoConfiguration
.
class
);
applicationContext
.
register
(
AdminServerWebConfiguration
.
class
);
EnvironmentTestUtils
.
addEnvironment
(
applicationContext
,
environment
);
applicationContext
.
refresh
();
this
.
context
=
applicationContext
;
}
}
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