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
7ad11421
Commit
7ad11421
authored
Apr 16, 2015
by
Johannes Stelzer
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ouaibsky-master'
parents
d3f9728a
63612117
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
8 deletions
+36
-8
SpringBootAdminRegistrator.java
...ntric/boot/admin/services/SpringBootAdminRegistrator.java
+21
-6
SpringBootAdminRegistratorTest.java
...c/boot/admin/services/SpringBootAdminRegistratorTest.java
+15
-2
No files found.
spring-boot-admin-starter-client/src/main/java/de/codecentric/boot/admin/services/SpringBootAdminRegistrator.java
View file @
7ad11421
...
...
@@ -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 @
7ad11421
...
...
@@ -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
(
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