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
3f02e73f
Commit
3f02e73f
authored
Jul 23, 2017
by
Johannes Edmeier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add getters to LetsChatNotifier
in order to get the ConfigurationProperties correctly recognized we need to provide some getters for the properties. fixes #493
parent
21082226
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
103 additions
and
81 deletions
+103
-81
LetsChatNotifier.java
...va/de/codecentric/boot/admin/notify/LetsChatNotifier.java
+103
-81
No files found.
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/notify/LetsChatNotifier.java
View file @
3f02e73f
...
...
@@ -38,85 +38,107 @@ import de.codecentric.boot.admin.event.ClientApplicationEvent;
* @author Rico Pahlisch
*/
public
class
LetsChatNotifier
extends
AbstractStatusChangeNotifier
{
private
static
final
String
DEFAULT_MESSAGE
=
"*#{application.name}* (#{application.id}) is *#{to.status}*"
;
private
final
SpelExpressionParser
parser
=
new
SpelExpressionParser
();
private
RestTemplate
restTemplate
=
new
RestTemplate
();
/**
* Host URL for Let´s Chat
*/
private
URI
url
;
/**
* Name of the room
*/
private
String
room
;
/**
* Token for the Let´s chat API
*/
private
String
token
;
/**
* username which sends notification
*/
private
String
username
=
"Spring Boot Admin"
;
/**
* Message template. SpEL template using event as root
*/
private
Expression
message
;
public
LetsChatNotifier
()
{
this
.
message
=
parser
.
parseExpression
(
DEFAULT_MESSAGE
,
ParserContext
.
TEMPLATE_EXPRESSION
);
}
@Override
protected
void
doNotify
(
ClientApplicationEvent
event
)
throws
Exception
{
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
// Let's Chat requiers the token as basic username, the password can be an arbitrary string.
String
auth
=
Base64Utils
.
encodeToString
(
String
.
format
(
"%s:%s"
,
token
,
username
).
getBytes
());
headers
.
add
(
HttpHeaders
.
AUTHORIZATION
,
String
.
format
(
"Basic %s"
,
auth
));
restTemplate
.
exchange
(
createUrl
(),
HttpMethod
.
POST
,
new
HttpEntity
<>(
createMessage
(
event
),
headers
),
Void
.
class
);
}
private
URI
createUrl
()
{
return
URI
.
create
(
String
.
format
(
"%s/rooms/%s/messages"
,
url
,
room
));
}
public
void
setRestTemplate
(
RestTemplate
restTemplate
)
{
this
.
restTemplate
=
restTemplate
;
}
public
void
setUrl
(
URI
url
)
{
this
.
url
=
url
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
void
setRoom
(
String
room
)
{
this
.
room
=
room
;
}
public
void
setToken
(
String
token
)
{
this
.
token
=
token
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
parser
.
parseExpression
(
message
,
ParserContext
.
TEMPLATE_EXPRESSION
);
}
protected
Object
createMessage
(
ClientApplicationEvent
event
)
{
Map
<
String
,
String
>
messageJson
=
new
HashMap
<>();
messageJson
.
put
(
"text"
,
getText
(
event
));
return
messageJson
;
}
protected
String
getText
(
ClientApplicationEvent
event
)
{
return
message
.
getValue
(
event
,
String
.
class
);
}
private
static
final
String
DEFAULT_MESSAGE
=
"*#{application.name}* (#{application.id}) is *#{to.status}*"
;
private
final
SpelExpressionParser
parser
=
new
SpelExpressionParser
();
private
RestTemplate
restTemplate
=
new
RestTemplate
();
/**
* Host URL for Let´s Chat
*/
private
URI
url
;
/**
* Name of the room
*/
private
String
room
;
/**
* Token for the Let´s chat API
*/
private
String
token
;
/**
* username which sends notification
*/
private
String
username
=
"Spring Boot Admin"
;
/**
* Message template. SpEL template using event as root
*/
private
Expression
message
;
public
LetsChatNotifier
()
{
this
.
message
=
parser
.
parseExpression
(
DEFAULT_MESSAGE
,
ParserContext
.
TEMPLATE_EXPRESSION
);
}
@Override
protected
void
doNotify
(
ClientApplicationEvent
event
)
throws
Exception
{
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
// Let's Chat requiers the token as basic username, the password can be an arbitrary string.
String
auth
=
Base64Utils
.
encodeToString
(
String
.
format
(
"%s:%s"
,
token
,
username
).
getBytes
());
headers
.
add
(
HttpHeaders
.
AUTHORIZATION
,
String
.
format
(
"Basic %s"
,
auth
));
restTemplate
.
exchange
(
createUrl
(),
HttpMethod
.
POST
,
new
HttpEntity
<>(
createMessage
(
event
),
headers
),
Void
.
class
);
}
private
URI
createUrl
()
{
return
URI
.
create
(
String
.
format
(
"%s/rooms/%s/messages"
,
url
,
room
));
}
public
void
setRestTemplate
(
RestTemplate
restTemplate
)
{
this
.
restTemplate
=
restTemplate
;
}
public
void
setUrl
(
URI
url
)
{
this
.
url
=
url
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
void
setRoom
(
String
room
)
{
this
.
room
=
room
;
}
public
void
setToken
(
String
token
)
{
this
.
token
=
token
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
parser
.
parseExpression
(
message
,
ParserContext
.
TEMPLATE_EXPRESSION
);
}
protected
Object
createMessage
(
ClientApplicationEvent
event
)
{
Map
<
String
,
String
>
messageJson
=
new
HashMap
<>();
messageJson
.
put
(
"text"
,
getText
(
event
));
return
messageJson
;
}
protected
String
getText
(
ClientApplicationEvent
event
)
{
return
message
.
getValue
(
event
,
String
.
class
);
}
public
URI
getUrl
()
{
return
url
;
}
public
String
getRoom
()
{
return
room
;
}
public
String
getToken
()
{
return
token
;
}
public
String
getUsername
()
{
return
username
;
}
public
String
getMessage
()
{
return
message
.
getExpressionString
();
}
}
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