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
fe84e3ac
Commit
fe84e3ac
authored
Nov 16, 2016
by
Johannes Edmeier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix compatibility for older clients
parent
accb52d1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
26 deletions
+69
-26
Application.java
...ain/java/de/codecentric/boot/admin/model/Application.java
+40
-21
ApplicationTest.java
...java/de/codecentric/boot/admin/model/ApplicationTest.java
+29
-5
No files found.
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/model/Application.java
View file @
fe84e3ac
...
...
@@ -15,17 +15,22 @@
*/
package
de
.
codecentric
.
boot
.
admin
.
model
;
import
java.io.IOException
;
import
java.io.Serializable
;
import
org.springframework.util.Assert
;
import
org.springframework.util.StringUtils
;
import
com.fasterxml.jackson.annotation.JsonCreator
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.DeserializationContext
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.annotation.JsonDeserialize
;
import
com.fasterxml.jackson.databind.deser.std.StdDeserializer
;
/**
* The domain model for all registered application at the spring boot admin application.
*/
@JsonDeserialize
(
using
=
Application
.
Deserializer
.
class
)
public
class
Application
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -48,24 +53,6 @@ public class Application implements Serializable {
this
.
statusInfo
=
builder
.
statusInfo
;
}
@JsonCreator
public
static
Application
fromJson
(
@JsonProperty
(
"url"
)
String
url
,
@JsonProperty
(
"managementUrl"
)
String
managementUrl
,
@JsonProperty
(
"healthUrl"
)
String
healthUrl
,
@JsonProperty
(
"serviceUrl"
)
String
serviceUrl
,
@JsonProperty
(
"name"
)
String
name
)
{
Builder
builder
=
create
(
name
);
if
(
StringUtils
.
hasText
(
url
))
{
// old format
builder
.
withHealthUrl
(
url
.
replaceFirst
(
"/+$"
,
""
)
+
"/health"
).
withManagementUrl
(
url
);
}
else
{
builder
.
withHealthUrl
(
healthUrl
).
withManagementUrl
(
managementUrl
)
.
withServiceUrl
(
serviceUrl
);
}
return
builder
.
build
();
}
public
static
Builder
create
(
String
name
)
{
return
new
Builder
(
name
);
}
...
...
@@ -222,4 +209,36 @@ public class Application implements Serializable {
return
true
;
}
public
static
class
Deserializer
extends
StdDeserializer
<
Application
>
{
private
static
final
long
serialVersionUID
=
1L
;
protected
Deserializer
()
{
super
(
Application
.
class
);
}
@Override
public
Application
deserialize
(
JsonParser
p
,
DeserializationContext
ctxt
)
throws
IOException
,
JsonProcessingException
{
JsonNode
node
=
p
.
readValueAsTree
();
Builder
builder
=
create
(
node
.
get
(
"name"
).
asText
());
if
(
node
.
has
(
"url"
))
{
String
url
=
node
.
get
(
"url"
).
asText
();
builder
.
withHealthUrl
(
url
.
replaceFirst
(
"/+$"
,
""
)
+
"/health"
)
.
withManagementUrl
(
url
);
}
else
{
if
(
node
.
has
(
"healthUrl"
))
{
builder
.
withHealthUrl
(
node
.
get
(
"healthUrl"
).
asText
());
}
if
(
node
.
has
(
"managementUrl"
))
{
builder
.
withManagementUrl
(
node
.
get
(
"managementUrl"
).
asText
());
}
if
(
node
.
has
(
"serviceUrl"
))
{
builder
.
withServiceUrl
(
node
.
get
(
"serviceUrl"
).
asText
());
}
}
return
builder
.
build
();
}
}
}
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/model/ApplicationTest.java
View file @
fe84e3ac
...
...
@@ -14,11 +14,10 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import
com.fasterxml.jackson.databind.ObjectMapper
;
public
class
ApplicationTest
{
private
ObjectMapper
objectMapper
=
Jackson2ObjectMapperBuilder
.
json
().
build
();
@Test
public
void
test_
old
_json_format
()
throws
JsonProcessingException
,
IOException
{
public
void
test_
1_2
_json_format
()
throws
JsonProcessingException
,
IOException
{
String
json
=
"{ \"name\" : \"test\", \"url\" : \"http://test\" }"
;
Application
value
=
objectMapper
.
readValue
(
json
,
Application
.
class
);
...
...
@@ -30,7 +29,19 @@ public class ApplicationTest {
}
@Test
public
void
test_new_json_format
()
throws
JsonProcessingException
,
IOException
{
public
void
test_1_4_json_format
()
throws
JsonProcessingException
,
IOException
{
String
json
=
"{ \"name\" : \"test\", \"managementUrl\" : \"http://test\" , \"healthUrl\" : \"http://health\" , \"serviceUrl\" : \"http://service\", \"statusInfo\": {\"status\":\"UNKNOWN\"} }"
;
Application
value
=
objectMapper
.
readValue
(
json
,
Application
.
class
);
assertThat
(
value
.
getName
(),
is
(
"test"
));
assertThat
(
value
.
getManagementUrl
(),
is
(
"http://test"
));
assertThat
(
value
.
getHealthUrl
(),
is
(
"http://health"
));
assertThat
(
value
.
getServiceUrl
(),
is
(
"http://service"
));
}
@Test
public
void
test_1_5_json_format
()
throws
JsonProcessingException
,
IOException
{
String
json
=
"{ \"name\" : \"test\", \"managementUrl\" : \"http://test\" , \"healthUrl\" : \"http://health\" , \"serviceUrl\" : \"http://service\"}"
;
Application
value
=
objectMapper
.
readValue
(
json
,
Application
.
class
);
...
...
@@ -41,14 +52,27 @@ public class ApplicationTest {
assertThat
(
value
.
getServiceUrl
(),
is
(
"http://service"
));
}
@Test
public
void
test_onlyHealhUrl
()
throws
JsonProcessingException
,
IOException
{
String
json
=
"{ \"name\" : \"test\", \"healthUrl\" : \"http://test\" }"
;
Application
value
=
objectMapper
.
readValue
(
json
,
Application
.
class
);
assertThat
(
value
.
getName
(),
is
(
"test"
));
assertThat
(
value
.
getHealthUrl
(),
is
(
"http://test"
));
assertThat
(
value
.
getManagementUrl
(),
nullValue
());
assertThat
(
value
.
getServiceUrl
(),
nullValue
());
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
test_name_expected
()
throws
JsonProcessingException
,
IOException
{
Application
.
fromJson
(
"http://url"
,
""
,
""
,
""
,
null
);
String
json
=
"{ \"name\" : \"\", \"managementUrl\" : \"http://test\" , \"healthUrl\" : \"http://health\" , \"serviceUrl\" : \"http://service\"}"
;
objectMapper
.
readValue
(
json
,
Application
.
class
);
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
test_healthUrl_expected
()
throws
JsonProcessingException
,
IOException
{
Application
.
fromJson
(
""
,
""
,
""
,
"name"
,
null
);
String
json
=
"{ \"name\" : \"test\", \"managementUrl\" : \"http://test\" , \"healthUrl\" : \"\" , \"serviceUrl\" : \"http://service\"}"
;
objectMapper
.
readValue
(
json
,
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