perf:代码调整
This commit is contained in:
31
qodana.yaml
Normal file
31
qodana.yaml
Normal file
@@ -0,0 +1,31 @@
|
||||
#-------------------------------------------------------------------------------#
|
||||
# Qodana analysis is configured by qodana.yaml file #
|
||||
# https://www.jetbrains.com/help/qodana/qodana-yaml.html #
|
||||
#-------------------------------------------------------------------------------#
|
||||
version: "1.0"
|
||||
|
||||
#Specify inspection profile for code analysis
|
||||
profile:
|
||||
name: qodana.starter
|
||||
|
||||
#Enable inspections
|
||||
#include:
|
||||
# - name: <SomeEnabledInspectionId>
|
||||
|
||||
#Disable inspections
|
||||
#exclude:
|
||||
# - name: <SomeDisabledInspectionId>
|
||||
# paths:
|
||||
# - <path/where/not/run/inspection>
|
||||
|
||||
projectJDK: 17 #(Applied in CI/CD pipeline)
|
||||
|
||||
#Execute shell command before Qodana execution (Applied in CI/CD pipeline)
|
||||
#bootstrap: sh ./prepare-qodana.sh
|
||||
|
||||
#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline)
|
||||
#plugins:
|
||||
# - id: <plugin.id> #(plugin id can be found at https://plugins.jetbrains.com)
|
||||
|
||||
#Specify Qodana linter for analysis (Applied in CI/CD pipeline)
|
||||
linter: jetbrains/qodana-jvm:latest
|
||||
@@ -16,10 +16,6 @@ import java.util.Objects;
|
||||
@Component
|
||||
public class DemoWebConfigurer implements TieshengWebConfigurer, TsLoginConfigurer {
|
||||
|
||||
@Autowired
|
||||
GlobalConfig globalConfig;
|
||||
|
||||
|
||||
@Override
|
||||
public RequestUserInfo getCurrentUserName(TokenBean tokenBean) {
|
||||
RequestUserInfo info = new RequestUserInfo();
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.tiesheng.demo.config;
|
||||
|
||||
|
||||
import com.tiesheng.web.service.CoreConfigService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
@@ -13,9 +11,6 @@ import javax.annotation.PostConstruct;
|
||||
@Component
|
||||
public class TestJobConfig {
|
||||
|
||||
@Autowired
|
||||
CoreConfigService coreConfigService;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
}
|
||||
|
||||
@@ -219,8 +219,10 @@ public class TestController {
|
||||
"83_7xqG36kdgwuf8zzWLY3jtz7bg4ucziN-0oxbE0X9zBzwbjZ4S4Ss2RM9uHeSIcRp2K-wEp6MLzWhqo2AXj0Jpzd6IiJdUsRxqdHPvEWqAdOgt83vzZwdDf7tZBkGNGeAFASZS",
|
||||
paramJson);
|
||||
Response execute1 = OkHttpUtil.ofHttpClient().build().newCall(request).execute();
|
||||
FileUtil.writeFromStream(execute1.body().byteStream(), file.getAbsolutePath());
|
||||
execute1.close();
|
||||
if (execute1.body() != null) {
|
||||
FileUtil.writeFromStream(execute1.body().byteStream(), file.getAbsolutePath());
|
||||
execute1.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ApiException("每分钟最多生成5000个二维码,请稍后再试!");
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class AliyunSmsSender implements TsMessageSender {
|
||||
String signature = specialUrlEncode(digest);
|
||||
queryMap.put("Signature", signature);
|
||||
|
||||
String respBody = "";
|
||||
String respBody;
|
||||
try {
|
||||
respBody = OkHttpUtil.get(ENDPOINT + "?Signature=" + signature + sortQueryStringTmp);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -76,15 +76,16 @@ public class PlatformDingConfig {
|
||||
request = OkHttpUtil.ofPost(url, body);
|
||||
}
|
||||
request = request.newBuilder().header("x-acs-dingtalk-access-token", accessToken).build();
|
||||
try {
|
||||
Response response = OkHttpUtil.ofHttpClient().build().newCall(request).execute();
|
||||
try (Response response = OkHttpUtil.ofHttpClient().build().newCall(request).execute()) {
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
String rawBody = response.body().string();
|
||||
DingResponse<T> bean = JSON.parseObject(rawBody, typeReference);
|
||||
bean.setRawBody(rawBody);
|
||||
return bean;
|
||||
} else {
|
||||
LogFactory.get().info(response.body().string());
|
||||
if (response.body() != null) {
|
||||
LogFactory.get().info(response.body().string());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogFactory.get().error(e);
|
||||
|
||||
@@ -17,7 +17,10 @@ public class ServletKit extends ServletUtil {
|
||||
public static HttpServletRequest getRequest() {
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes)
|
||||
RequestContextHolder.getRequestAttributes();
|
||||
return attributes.getRequest();
|
||||
if (attributes != null) {
|
||||
return attributes.getRequest();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,6 +30,9 @@ public class ServletKit extends ServletUtil {
|
||||
*/
|
||||
public static String getClientIP() {
|
||||
HttpServletRequest request = getRequest();
|
||||
if (request == null) {
|
||||
return "";
|
||||
}
|
||||
return getClientIP(request);
|
||||
}
|
||||
|
||||
|
||||
@@ -384,7 +384,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
* @since 5.7.4
|
||||
*/
|
||||
public boolean validate(long leeway) {
|
||||
if (false == verify()) {
|
||||
if (!verify()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -160,13 +160,13 @@ public class JWTValidator {
|
||||
}
|
||||
|
||||
final String algorithmIdInSigner = signer.getAlgorithmId();
|
||||
if (false == StrUtil.equals(algorithmId, algorithmIdInSigner)) {
|
||||
if (!StrUtil.equals(algorithmId, algorithmIdInSigner)) {
|
||||
throw new ValidateException("Algorithm [{}] defined in header doesn't match to [{}]!"
|
||||
, algorithmId, algorithmIdInSigner);
|
||||
}
|
||||
|
||||
// 通过算法验证签名是否正确
|
||||
if (false == jwt.verify(signer)) {
|
||||
if (!jwt.verify(signer)) {
|
||||
throw new ValidateException("Signature verification failed!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,9 +83,11 @@ public class OkHttpUtil {
|
||||
}
|
||||
|
||||
public static String get(String urlString, int timeout) {
|
||||
try {
|
||||
return ofHttpClient().connectTimeout(timeout, TimeUnit.MILLISECONDS)
|
||||
.build().newCall(ofGet(urlString)).execute().body().string();
|
||||
try (Response execute = ofHttpClient().connectTimeout(timeout, TimeUnit.MILLISECONDS)
|
||||
.build().newCall(ofGet(urlString)).execute()) {
|
||||
if (execute.body() != null) {
|
||||
return execute.body().string();
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
return null;
|
||||
@@ -117,9 +119,11 @@ public class OkHttpUtil {
|
||||
}
|
||||
|
||||
public static String post(String urlString, RequestBody body, int timeout) {
|
||||
try {
|
||||
return ofHttpClient().connectTimeout(timeout, TimeUnit.MILLISECONDS)
|
||||
.build().newCall(ofPost(urlString, body)).execute().body().string();
|
||||
try (Response response = ofHttpClient().connectTimeout(timeout, TimeUnit.MILLISECONDS)
|
||||
.build().newCall(ofPost(urlString, body)).execute()) {
|
||||
if (response.body() != null) {
|
||||
return response.body().string();
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
return null;
|
||||
@@ -135,11 +139,10 @@ public class OkHttpUtil {
|
||||
}
|
||||
|
||||
public static File downloadFile(String url, File destFile) {
|
||||
try {
|
||||
Response response = ofHttpClient()
|
||||
.connectTimeout(0, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(0, TimeUnit.MILLISECONDS)
|
||||
.build().newCall(ofGet(url)).execute();
|
||||
try (Response response = ofHttpClient()
|
||||
.connectTimeout(0, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(0, TimeUnit.MILLISECONDS)
|
||||
.build().newCall(ofGet(url)).execute()) {
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
FileUtil.writeFromStream(response.body().byteStream(), destFile);
|
||||
}
|
||||
@@ -150,11 +153,10 @@ public class OkHttpUtil {
|
||||
}
|
||||
|
||||
public static byte[] downloadBytes(String url) {
|
||||
try {
|
||||
Response response = ofHttpClient()
|
||||
.connectTimeout(0, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(0, TimeUnit.MILLISECONDS)
|
||||
.build().newCall(ofGet(url)).execute();
|
||||
try (Response response = ofHttpClient()
|
||||
.connectTimeout(0, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(0, TimeUnit.MILLISECONDS)
|
||||
.build().newCall(ofGet(url)).execute()) {
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
return response.body().bytes();
|
||||
}
|
||||
|
||||
@@ -36,11 +36,14 @@ public class OkHttpLogInterceptor implements Interceptor {
|
||||
logApi.setResult(response.code());
|
||||
|
||||
// 如果是json,xml,text,则保存记录
|
||||
if (response.body() != null && StrUtil.containsAll(response.body().contentType().toString(),
|
||||
"json", "xml", "text")) {
|
||||
ResponseBody peekBody = response.peekBody(Long.MAX_VALUE);
|
||||
logApi.setRespBody(peekBody.string());
|
||||
peekBody.close();
|
||||
if (response.body() != null) {
|
||||
MediaType mediaType = response.body().contentType();
|
||||
String contentType = mediaType == null ? "" : mediaType.toString();
|
||||
if (StrUtil.containsAny(contentType, "json", "xml", "text")) {
|
||||
ResponseBody peekBody = response.peekBody(Long.MAX_VALUE);
|
||||
logApi.setRespBody(peekBody.string());
|
||||
peekBody.close();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user