Skip to content

Commit

Permalink
Merge branch 'feature/1.0.0' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
fuhouyu committed Oct 6, 2024
2 parents 825cfc2 + 870d324 commit c41310c
Show file tree
Hide file tree
Showing 33 changed files with 174 additions and 147 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Qodana Scan
uses: JetBrains/qodana-action@v2024.1
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}
- name: "Print maven version"
run: mvn -version
- name: Build with Maven
run: mvn clean test
- name: Upload test results to Codecov
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void setup() {
}

@Test
void testStringCache() throws InterruptedException {
void testStringCache() {

cacheService.set(cacheBigKey, cacheValue);
assertEquals(cacheValue, cacheService.get(cacheBigKey));
Expand All @@ -71,8 +71,6 @@ void testStringCache() throws InterruptedException {

cacheService.set(cacheBigKey, cacheValue, 3, TimeUnit.SECONDS);
assertEquals(cacheValue, cacheService.get(cacheBigKey));
Thread.sleep(1000 * 3);
assertNull(cacheService.get(cacheBigKey));

List<String> list = List.of(cacheValue);
cacheService.set(cacheBigKey, list);
Expand All @@ -82,7 +80,7 @@ void testStringCache() throws InterruptedException {
}

@Test
void testHashCache() throws InterruptedException {
void testHashCache() {
String hashKey = UUID.randomUUID().toString().replace("-", "").substring(8);
cacheService.putHash(cacheBigKey, hashKey, cacheValue);
assertEquals(cacheValue, cacheService.getHash(cacheBigKey, hashKey));
Expand All @@ -96,8 +94,6 @@ void testHashCache() throws InterruptedException {

cacheService.putHash(cacheBigKey, hashKey, cacheValue, 3, TimeUnit.SECONDS);
assertEquals(cacheValue, cacheService.getHash(cacheBigKey, hashKey));
Thread.sleep(1000 * 3);
assertNull(cacheService.getHash(cacheBigKey, hashKey));

List<String> list = List.of(cacheValue);
cacheService.putHash(cacheBigKey, hashKey, list);
Expand All @@ -108,29 +104,25 @@ void testHashCache() throws InterruptedException {
}

@Test
void testSetCache() throws InterruptedException {
void testSetCache() {
cacheService.addToSet(cacheBigKey, cacheValue);
cacheService.getSet(cacheBigKey).forEach(value -> assertEquals(cacheValue, value));

assertNotEquals("", cacheValue);

cacheService.addToSet(cacheBigKey, cacheValue, 3, TimeUnit.SECONDS);
cacheService.getSet(cacheBigKey).forEach(value -> assertEquals(cacheValue, value));
Thread.sleep(1000 * 3);
assertTrue(cacheService.getSet(cacheBigKey).isEmpty());
}

@Test
void testListCache() throws InterruptedException {
void testListCache() {
cacheService.pushToList(cacheBigKey, cacheValue);
cacheService.getList(cacheBigKey).forEach(value -> assertEquals(cacheValue, value));

assertNotEquals("", cacheValue);

cacheService.pushToList(cacheBigKey, cacheValue, 3, TimeUnit.SECONDS);
cacheService.getList(cacheBigKey).forEach(value -> assertEquals(cacheValue, value));
Thread.sleep(1000 * 3);
assertTrue(cacheService.getList(cacheBigKey).isEmpty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@
* @author fuhouyu
* @since 2024/8/14 12:57
*/
public interface ConfigPropertiesConstant {
public class ConfigPropertiesConstant {

/**
* 配置类的前缀
*/
String PROPERTIES_PREFIX = "base.framework.";
public static final String PROPERTIES_PREFIX = "base.framework.";

private ConfigPropertiesConstant() {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,49 +24,48 @@
* @author fuhouyu
* @since 2024/8/15 19:54
*/
public interface HttpRequestHeaderConstant {
public class HttpRequestHeaderConstant {

// 自定义请求头
/**
* 自定义的用户详情请求头
*/
String USERINFO_HEADER = "X-Custom-Userinfo";

// 标准请求头
public static final String USERINFO_HEADER = "X-Custom-Userinfo";

// 自定义请求头
/**
* 客户端版本
*/
String CLIENT_VERSION_HEADER = "Client-Version";
public static final String CLIENT_VERSION_HEADER = "Client-Version";

// 标准请求头
/**
* 用户代理
*/
String USER_AGENT_HEADER = "User-Agent";

public static final String USER_AGENT_HEADER = "User-Agent";
/**
* 消息内容类型
*/
String CONTENT_TYPE = "Content-Type";

public static final String CONTENT_TYPE = "Content-Type";
/**
* 消息内容长度
*/
String CONTENT_LENGTH = "Content-Length";

public static final String CONTENT_LENGTH = "Content-Length";
/**
* 消息内容编码
*/
String CONTENT_ENCODING = "Content-Encoding";

// nginx转发的请求头
public static final String CONTENT_ENCODING = "Content-Encoding";
/**
* 真实ip地址
*/
String X_REAL_IP = "X-Real-IP";
public static final String X_REAL_IP = "X-Real-IP";

// nginx转发的请求头
/**
* 来自
*/
String X_FORWARDED_FOR = "X-Forwarded-For";
public static final String X_FORWARDED_FOR = "X-Forwarded-For";

private HttpRequestHeaderConstant() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2024-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fuhouyu.framework.exception;

/**
* <p>
* 文件异常
* </p>
*
* @author fuhouyu
* @since 2024/10/6 11:32
*/
public class FileException extends RuntimeException {

public FileException() {
this(null);
}

public FileException(Throwable cause) {
super("Cannot parse JSON", cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class RestResult<T> implements Serializable {
* 响应数据
*/
@Schema(name = "data", description = "响应数据,该值可能为空", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private T data;
private transient T data;

private RestResult() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static <T> Class<T> loadClass(String className) {
try {
return (Class<T>) Class.forName(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException(String.format("%s class not found", className), e);
throw new IllegalArgumentException(String.format("%s class not found", className), e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
package com.fuhouyu.framework.utils;


import com.fuhouyu.framework.exception.FileException;
import lombok.NonNull;

import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -59,7 +62,7 @@ public static void createDirectorIfNotExists(Path path) {
try {
Files.createDirectories(path);
} catch (IOException e) {
throw new RuntimeException(e);
throw new FileException(e);
}
}

Expand All @@ -72,7 +75,7 @@ public static void deleteFileIfExists(Path path) {
try {
Files.deleteIfExists(path);
} catch (IOException e) {
throw new RuntimeException(e);
throw new FileException(e);
}
}

Expand Down Expand Up @@ -186,13 +189,15 @@ public static void deleteDirect(Path directPath) throws IOException {
}
Files.walkFileTree(directPath, new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
@NonNull
public FileVisitResult visitFile(@NonNull Path file, @NonNull BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}


@Override
@NonNull
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
if (exc == null) {
Files.delete(dir);
Expand Down Expand Up @@ -265,7 +270,7 @@ public static String calculateFileDigest(Path path,
}
return HexUtil.encodeToHexString(digest.digest());
} catch (IOException e) {
throw new RuntimeException(e);
throw new FileException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
*/
public class JacksonUtil {

private JacksonUtil() {

}

private static final ObjectMapper OBJECT_MAPPER;

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,30 @@
*/
public abstract class AbstractThredLocalContextHolderStrategy<T> implements ContextHolderStrategy<Context<T>> {

private final ThreadLocal<Context<T>> THREAD_LOCAL;
private final ThreadLocal<Context<T>> threadLocal;

protected AbstractThredLocalContextHolderStrategy(ThreadLocal<Context<T>> threadLocal) {
THREAD_LOCAL = threadLocal;
this.threadLocal = threadLocal;
}

@Override
public void clearContext() {
THREAD_LOCAL.remove();
threadLocal.remove();
}

@Override
public Context<T> getContext() {
return THREAD_LOCAL.get();
return threadLocal.get();
}

@Override
public void setContext(Context<T> context) {
THREAD_LOCAL.set(context);
threadLocal.set(context);
}


@Override
public Boolean isEmptyContext() {
return THREAD_LOCAL.get() == null;
return threadLocal.get() == null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
*/
public class RequestContextHolder {

private RequestContextHolder() {

}

private static final ContextHolderStrategy<Context<Request>> CONTEXT_HOLDER_STRATEGY;

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ public class DefaultUserDetail implements Serializable, User {

private String refAccountId;

private Map<String, Object> additionalInformation;
private transient Map<String, Object> additionalInformation;

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
*/
public class UserContextHolder {

private UserContextHolder() {

}

private static final ContextHolderStrategy<Context<User>> CONTEXT_HOLDER_STRATEGY;

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
@ConditionalOnMissingBean(KmsService.class)
@EnableConfigurationProperties(KmsDefaultProperties.class)
public class DefaultKmsAutoConfigure {
private static final String SM2_KEYPAIR_STORE_PATH = "/tmp/keypair";

private final KmsDefaultProperties properties;

Expand Down Expand Up @@ -162,12 +161,11 @@ private CMac initCmac(SM4 sm4) {
*/
private SM2 generatorSm2() {
KmsDefaultProperties.Sm2Properties sm2Properties = this.properties.getSm2();
if (!sm2Properties.getAutoGenerate()) {
if (Boolean.FALSE.equals(sm2Properties.getAutoGenerate())) {
throw new KmsException("sm2 公私钥未设置,且未启用自动生成");
}

String parentPath = Objects.isNull(sm2Properties.getAutoGenerateLocalPath()) ?
SM2_KEYPAIR_STORE_PATH : sm2Properties.getAutoGenerateLocalPath();
String parentPath = sm2Properties.getAutoGenerateLocalPath();
Path publicKeyPath = Path.of(parentPath, "publicKey");
Path privateKeyPath = Path.of(parentPath, "privateKey");
if (Files.exists(publicKeyPath) && Files.exists(privateKeyPath)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static class Sm2Properties {
/**
* 自动生成后存储的路径
*/
private String autoGenerateLocalPath;
private String autoGenerateLocalPath = "/tmp/keypair";

/**
* 公钥key
Expand Down
Loading

0 comments on commit c41310c

Please sign in to comment.