Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
commons
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DevOps
commons
Commits
c6fa0339
Commit
c6fa0339
authored
Jun 21, 2022
by
meng.cheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
清理无用代码
parent
af14582f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
86 deletions
+2
-86
TokenJob.java
.../src/main/java/cn/quantgroup/tech/brave/job/TokenJob.java
+0
-84
pom.xml
pom.xml
+2
-2
No files found.
brave-spring-boot-starter/src/main/java/cn/quantgroup/tech/brave/job/TokenJob.java
deleted
100644 → 0
View file @
af14582f
package
cn
.
quantgroup
.
tech
.
brave
.
job
;
import
cn.quantgroup.tech.brave.handler.TokenHandler
;
import
cn.quantgroup.tech.brave.service.ITechRestTemplateBuilder
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.Data
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.web.client.RestTemplate
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.Resource
;
import
java.util.Base64
;
import
java.util.Map
;
@Data
class
TokenResp
{
private
Integer
code
;
@JsonProperty
(
"access_token"
)
private
String
token
;
@JsonProperty
(
"expires_in"
)
private
Integer
expires
;
}
@Slf4j
@EnableScheduling
public
class
TokenJob
{
private
static
final
String
CREDENTIAL
=
"credential"
;
private
static
final
int
SUCCESS
=
200
;
@Value
(
"${tech.auth.clientId}"
)
private
String
clientId
;
@Value
(
"${tech.auth.secret}"
)
private
String
secret
;
@Value
(
"${tech.auth.tokenUrl}"
)
private
String
tokenUrl
;
@Resource
private
ITechRestTemplateBuilder
techRestTemplateBuilder
;
@Bean
public
RestTemplate
restTemplate
()
{
return
techRestTemplateBuilder
.
createRestTemplate
();
}
@Scheduled
(
cron
=
"0 */30 * * * ?"
)
public
void
getToken
()
{
HttpHeaders
requestHeaders
=
new
HttpHeaders
();
requestHeaders
.
add
(
CREDENTIAL
,
base64ForCredential
());
HttpEntity
<
Map
<
String
,
Object
>>
httpEntity
=
new
HttpEntity
<>(
requestHeaders
);
TokenResp
tokenResp
=
restTemplate
().
exchange
(
tokenUrl
,
HttpMethod
.
GET
,
httpEntity
,
TokenResp
.
class
).
getBody
();
log
.
info
(
"getToken tokenResp = 【{}】"
,
tokenResp
);
boolean
tokenValid
=
tokenResp
!=
null
&&
SUCCESS
==
tokenResp
.
getCode
()
&&
StringUtils
.
isNotBlank
(
tokenResp
.
getToken
());
if
(
tokenValid
)
{
TokenHandler
.
setToken
(
tokenResp
.
getToken
());
}
}
@Scheduled
(
cron
=
"0 */2 * * * ?"
)
public
void
getTokenDemotion
()
{
if
(
StringUtils
.
isBlank
(
TokenHandler
.
getToken
()))
{
getToken
();
}
}
private
String
base64ForCredential
()
{
String
credential
=
clientId
+
":"
+
secret
;
return
Base64
.
getEncoder
().
encodeToString
(
credential
.
getBytes
());
}
@PostConstruct
public
void
init
()
{
getToken
();
}
}
pom.xml
View file @
c6fa0339
...
...
@@ -6,7 +6,7 @@
<modelVersion>
4.0.0
</modelVersion>
<groupId>
cn.quantgroup
</groupId>
<artifactId>
commons-parent
</artifactId>
<version>
0.
3.2
</version>
<version>
0.
4.0
</version>
<parent>
<groupId>
org.springframework.boot
</groupId>
...
...
@@ -20,7 +20,7 @@
<module>
shutdown-spring-boot-starter
</module>
<module>
brave-spring-boot-starter
</module>
<module>
idgenerator-spring-boot-starter
</module>
<
module>
enoch-agent-spring-boot-starter
</module
>
<
!--<module>enoch-agent-spring-boot-starter</module>--
>
<module>
elastic-job-lite-spring-boot-starter
</module>
</modules>
...
...
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