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
e15d7d2d
Commit
e15d7d2d
authored
Nov 16, 2017
by
Johannes Edmeier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Just respond with the id for successful registration
fixes #590 (old client - new server)
parent
cf2a9eee
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
26 deletions
+36
-26
RegistryController.java
...decentric/boot/admin/registry/web/RegistryController.java
+10
-7
RegistryControllerTest.java
...ntric/boot/admin/registry/web/RegistryControllerTest.java
+26
-19
No files found.
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/registry/web/RegistryController.java
View file @
e15d7d2d
...
...
@@ -15,6 +15,7 @@
*/
package
de
.
codecentric
.
boot
.
admin
.
registry
.
web
;
import
java.net.URI
;
import
java.util.Collection
;
import
org.slf4j.Logger
;
...
...
@@ -27,11 +28,14 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.util.UriComponentsBuilder
;
import
de.codecentric.boot.admin.model.Application
;
import
de.codecentric.boot.admin.registry.ApplicationRegistry
;
import
de.codecentric.boot.admin.web.AdminController
;
import
static
java
.
util
.
Collections
.
singletonMap
;
/**
* REST controller for controlling registration of managed applications.
*/
...
...
@@ -55,12 +59,12 @@ public class RegistryController {
* @return The registered application.
*/
@RequestMapping
(
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
Application
>
register
(
@RequestBody
Application
application
)
{
Application
applicationWithSource
=
Application
.
copyOf
(
application
).
withSource
(
"http-api"
)
.
build
();
public
ResponseEntity
<?>
register
(
@RequestBody
Application
application
,
UriComponentsBuilder
builder
)
{
Application
applicationWithSource
=
Application
.
copyOf
(
application
).
withSource
(
"http-api"
).
build
();
LOGGER
.
debug
(
"Register application {}"
,
applicationWithSource
.
toString
());
Application
registeredApp
=
registry
.
register
(
applicationWithSource
);
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
body
(
registeredApp
);
String
id
=
registry
.
register
(
applicationWithSource
).
getId
();
URI
location
=
builder
.
path
(
"/{id}"
).
buildAndExpand
(
id
).
toUri
();
return
ResponseEntity
.
created
(
location
).
body
(
singletonMap
(
"id"
,
id
));
}
/**
...
...
@@ -70,8 +74,7 @@ public class RegistryController {
* @return List
*/
@RequestMapping
(
method
=
RequestMethod
.
GET
)
public
Collection
<
Application
>
applications
(
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
)
{
public
Collection
<
Application
>
applications
(
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
)
{
LOGGER
.
debug
(
"Deliver registered applications with name={}"
,
name
);
if
(
name
==
null
||
name
.
isEmpty
())
{
return
registry
.
getApplications
();
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/registry/web/RegistryControllerTest.java
View file @
e15d7d2d
...
...
@@ -15,20 +15,25 @@
*/
package
de
.
codecentric
.
boot
.
admin
.
registry
.
web
;
import
static
org
.
mockito
.
Matchers
.
matches
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
delete
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
post
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
header
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
jsonPath
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
java.io.UnsupportedEncodingException
;
import
org.hamcrest.CoreMatchers
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.Mockito
;
import
org.mockito.internal.matchers.Matches
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.MvcResult
;
...
...
@@ -48,9 +53,11 @@ public class RegistryControllerTest {
static
{
try
{
APPLICATION_TEST_JSON
=
new
JSONObject
().
put
(
"name"
,
"test"
)
.
put
(
"healthUrl"
,
"http://localhost/mgmt/health"
).
toString
();
.
put
(
"healthUrl"
,
"http://localhost/mgmt/health"
)
.
toString
();
APPLICATION_TWICE_JSON
=
new
JSONObject
().
put
(
"name"
,
"twice"
)
.
put
(
"healthUrl"
,
"http://localhost/mgmt/health"
).
toString
();
.
put
(
"healthUrl"
,
"http://localhost/mgmt/health"
)
.
toString
();
}
catch
(
JSONException
ex
)
{
throw
new
ExceptionInInitializerError
(
ex
);
}
...
...
@@ -68,31 +75,30 @@ public class RegistryControllerTest {
@Test
public
void
test_register_twice_get_and_remove
()
throws
Exception
{
MvcResult
result
=
mvc
.
perform
(
post
(
"/api/applications"
).
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
APPLICATION_TEST_JSON
))
.
andExpect
(
status
().
isCreated
()).
andExpect
(
jsonPath
(
"$.name"
).
value
(
"test"
))
.
andExpect
(
jsonPath
(
"$.healthUrl"
).
value
(
"http://localhost/mgmt/health"
))
.
andExpect
(
jsonPath
(
"$.id"
).
isNotEmpty
())
.
andReturn
();
MvcResult
result
=
mvc
.
perform
(
post
(
"/api/applications"
).
contentType
(
MediaType
.
APPLICATION_JSON
).
content
(
APPLICATION_TEST_JSON
)
)
.
andExpect
(
status
().
isCreated
(
))
.
andExpect
(
header
().
string
(
HttpHeaders
.
LOCATION
,
new
Matches
(
"http://localhost/[0-9a-f]+"
)
))
.
andExpect
(
jsonPath
(
"$.id"
).
isNotEmpty
(
))
.
andReturn
();
String
id
=
extractId
(
result
);
mvc
.
perform
(
post
(
"/api/applications"
).
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
APPLICATION_TWICE_JSON
)).
andExpect
(
status
().
isCreated
())
.
andExpect
(
jsonPath
(
"$.name"
).
value
(
"twice"
))
.
andExpect
(
jsonPath
(
"$.healthUrl"
).
value
(
"http://localhost/mgmt/health"
))
mvc
.
perform
(
post
(
"/api/applications"
).
contentType
(
MediaType
.
APPLICATION_JSON
).
content
(
APPLICATION_TWICE_JSON
))
.
andExpect
(
status
().
isCreated
())
.
andExpect
(
header
().
string
(
HttpHeaders
.
LOCATION
,
new
Matches
(
"http://localhost/[0-9a-f]+"
)))
.
andExpect
(
jsonPath
(
"$.id"
).
value
(
id
));
mvc
.
perform
(
get
(
"/api/applications"
)).
andExpect
(
status
().
isOk
())
.
andExpect
(
jsonPath
(
"$[0].id"
).
value
(
id
));
mvc
.
perform
(
get
(
"/api/applications"
)).
andExpect
(
status
().
isOk
()).
andExpect
(
jsonPath
(
"$[0].id"
).
value
(
id
));
mvc
.
perform
(
get
(
"/api/applications?name=twice"
)).
andExpect
(
status
().
isOk
())
mvc
.
perform
(
get
(
"/api/applications?name=twice"
))
.
andExpect
(
status
().
isOk
())
.
andExpect
(
jsonPath
(
"$[0].id"
).
value
(
id
));
mvc
.
perform
(
get
(
"/api/applications/{id}"
,
id
)).
andExpect
(
status
().
isOk
())
.
andExpect
(
jsonPath
(
"$.id"
).
value
(
id
));
mvc
.
perform
(
get
(
"/api/applications/{id}"
,
id
)).
andExpect
(
status
().
isOk
()).
andExpect
(
jsonPath
(
"$.id"
).
value
(
id
));
mvc
.
perform
(
delete
(
"/api/applications/{id}"
,
id
)).
andExpect
(
status
().
isOk
())
mvc
.
perform
(
delete
(
"/api/applications/{id}"
,
id
))
.
andExpect
(
status
().
isOk
())
.
andExpect
(
jsonPath
(
"$.id"
).
value
(
id
));
mvc
.
perform
(
get
(
"/api/applications/{id}"
,
id
)).
andExpect
(
status
().
isNotFound
());
...
...
@@ -105,7 +111,8 @@ public class RegistryControllerTest {
@Test
public
void
test_get_notFound
()
throws
Exception
{
mvc
.
perform
(
get
(
"/api/applications/unknown"
)).
andExpect
(
status
().
isNotFound
());
mvc
.
perform
(
get
(
"/api/applications?name=unknown"
)).
andExpect
(
status
().
isOk
())
mvc
.
perform
(
get
(
"/api/applications?name=unknown"
))
.
andExpect
(
status
().
isOk
())
.
andExpect
(
jsonPath
(
"$"
).
isEmpty
());
}
...
...
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