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
63612117
Commit
63612117
authored
Apr 16, 2015
by
clalleme
Committed by
Johannes Stelzer
Apr 16, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add JSON content type when registering to Admin Server
fixes #62
parent
d3f9728a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
9 deletions
+37
-9
SpringBootAdminRegistrator.java
...ntric/boot/admin/services/SpringBootAdminRegistrator.java
+21
-6
SpringBootAdminRegistratorTest.java
...c/boot/admin/services/SpringBootAdminRegistratorTest.java
+16
-3
No files found.
spring-boot-admin-starter-client/src/main/java/de/codecentric/boot/admin/services/SpringBootAdminRegistrator.java
View file @
63612117
...
...
@@ -15,9 +15,14 @@
*/
package
de
.
codecentric
.
boot
.
admin
.
services
;
import
java.util.Collections
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.client.RestTemplate
;
...
...
@@ -32,6 +37,14 @@ public class SpringBootAdminRegistrator {
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
SpringBootAdminRegistrator
.
class
);
private
static
HttpHeaders
HTTP_HEADERS
=
createHttpHeaders
();
private
AdminClientProperties
clientProps
;
private
AdminProperties
adminProps
;
private
final
RestTemplate
template
;
public
SpringBootAdminRegistrator
(
RestTemplate
template
,
AdminProperties
adminProps
,
AdminClientProperties
clientProps
)
{
this
.
clientProps
=
clientProps
;
...
...
@@ -39,11 +52,12 @@ public class SpringBootAdminRegistrator {
this
.
template
=
template
;
}
private
AdminClientProperties
clientProps
;
private
AdminProperties
adminProps
;
private
final
RestTemplate
template
;
private
static
HttpHeaders
createHttpHeaders
()
{
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
headers
.
setAccept
(
Collections
.
singletonList
(
MediaType
.
APPLICATION_JSON
));
return
HttpHeaders
.
readOnlyHttpHeaders
(
headers
);
}
/**
* Registers the client application at spring-boot-admin-server.
...
...
@@ -54,7 +68,8 @@ public class SpringBootAdminRegistrator {
String
adminUrl
=
adminProps
.
getUrl
()
+
'/'
+
adminProps
.
getContextPath
();
try
{
ResponseEntity
<
Application
>
response
=
template
.
postForEntity
(
adminUrl
,
app
,
Application
.
class
);
ResponseEntity
<
Application
>
response
=
template
.
postForEntity
(
adminUrl
,
new
HttpEntity
<
Application
>(
app
,
HTTP_HEADERS
),
Application
.
class
);
if
(
response
.
getStatusCode
().
equals
(
HttpStatus
.
CREATED
))
{
LOGGER
.
debug
(
"Application registered itself as {}"
,
response
.
getBody
());
...
...
spring-boot-admin-starter-client/src/test/java/de/codecentric/boot/admin/services/SpringBootAdminRegistratorTest.java
View file @
63612117
...
...
@@ -23,8 +23,13 @@ import static org.mockito.Mockito.mock;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
java.util.Collections
;
import
org.junit.Test
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.client.RestClientException
;
import
org.springframework.web.client.RestTemplate
;
...
...
@@ -45,15 +50,23 @@ public class SpringBootAdminRegistratorTest {
clientProps
.
setName
(
"AppName"
);
RestTemplate
restTemplate
=
mock
(
RestTemplate
.
class
);
when
(
restTemplate
.
postForEntity
(
isA
(
String
.
class
),
isA
(
Application
.
class
),
eq
(
Application
.
class
))).
thenReturn
(
new
ResponseEntity
<
Application
>(
HttpStatus
.
CREATED
));
when
(
restTemplate
.
postForEntity
(
isA
(
String
.
class
),
isA
(
HttpEntity
.
class
),
eq
(
Application
.
class
))).
thenReturn
(
new
ResponseEntity
<
Application
>(
HttpStatus
.
CREATED
));
SpringBootAdminRegistrator
registrator
=
new
SpringBootAdminRegistrator
(
restTemplate
,
adminProps
,
clientProps
);
boolean
result
=
registrator
.
register
();
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
headers
.
setAccept
(
Collections
.
singletonList
(
MediaType
.
APPLICATION_JSON
));
assertTrue
(
result
);
verify
(
restTemplate
).
postForEntity
(
"http://sba:8080/api/applications"
,
new
Application
(
"http://localhost:8080"
,
"AppName"
),
Application
.
class
);
new
HttpEntity
<
Application
>(
new
Application
(
"http://localhost:8080"
,
"AppName"
),
headers
),
Application
.
class
);
}
@Test
...
...
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