diff --git a/pom.xml b/pom.xml
index eaf642f..89c4050 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
org.springframework.boot
spring-boot-starter-parent
- 3.0.5
+ 3.0.6
com.flagnote
@@ -20,7 +20,8 @@
17
17
2022.0.2
- flagnote
+ registry.openif.com:5000
+ flagnote
@@ -123,9 +124,13 @@
docker-maven-plugin
1.2.2
- http://rancher:42375
+ docker-openif
+ http://${docker.repository}
+ true
+ http://144.34.221.20:42375
- ${docker.image.prefix}/${project.artifactId}:${project.version}
+ ${docker.repostory}/${docker.registry.name}/${project.artifactId}:${project.version}
+
src/main/docker
diff --git a/src/main/java/com/flagnote/note/aop/AopConfig.java b/src/main/java/com/flagnote/note/aop/AopConfig.java
index 96559b8..cff91eb 100644
--- a/src/main/java/com/flagnote/note/aop/AopConfig.java
+++ b/src/main/java/com/flagnote/note/aop/AopConfig.java
@@ -1,11 +1,7 @@
package com.flagnote.note.aop;
-import java.util.concurrent.TimeUnit;
-
import org.aspectj.lang.JoinPoint;
-import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
-import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
@@ -18,25 +14,25 @@ import lombok.extern.slf4j.Slf4j;
@Component
@Slf4j
public class AopConfig {
- @Pointcut("@annotation(com.flagnote.note.aop.CountTime)")
- public void logTime() {
+ @Pointcut("@annotation(com.flagnote.note.aop.CountTime)")
+ public void logTime() {
- }
-
- private ThreadLocal stopWatchLocal = new ThreadLocal<>();
-
- @Before("logTime()")
- public void before() {
- StopWatch stopWatch = new StopWatch();
- stopWatchLocal.set(stopWatch);
- stopWatch.start();
- }
-
- @AfterReturning(value = "logTime()", returning = "val")
- public void afterReturning(JoinPoint joinPoint, Object val) {
- StopWatch stopWatch = stopWatchLocal.get();
- stopWatch.stop();
- log.info("method:"+ joinPoint.getSignature().getName()+">>> " + stopWatch.getLastTaskTimeMillis() + " ms.");
- }
+ }
+
+ private ThreadLocal stopWatchLocal = new ThreadLocal<>();
+
+ @Before("logTime()")
+ public void before() {
+ StopWatch stopWatch = new StopWatch();
+ stopWatchLocal.set(stopWatch);
+ stopWatch.start();
+ }
+
+ @AfterReturning(value = "logTime()", returning = "val")
+ public void afterReturning(JoinPoint joinPoint, Object val) {
+ StopWatch stopWatch = stopWatchLocal.get();
+ stopWatch.stop();
+ log.info("method:" + joinPoint.getSignature().getName() + ">>> " + stopWatch.getLastTaskTimeMillis() + " ms.");
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/flagnote/note/aop/CountTime.java b/src/main/java/com/flagnote/note/aop/CountTime.java
index 70dc500..80e4a29 100644
--- a/src/main/java/com/flagnote/note/aop/CountTime.java
+++ b/src/main/java/com/flagnote/note/aop/CountTime.java
@@ -1,11 +1,11 @@
package com.flagnote.note.aop;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
@Retention(RUNTIME)
@Target(METHOD)
public @interface CountTime {
diff --git a/src/main/java/com/flagnote/note/cache/NoteCache.java b/src/main/java/com/flagnote/note/cache/NoteCache.java
index e23d381..404a4a5 100644
--- a/src/main/java/com/flagnote/note/cache/NoteCache.java
+++ b/src/main/java/com/flagnote/note/cache/NoteCache.java
@@ -7,7 +7,7 @@ import cn.hutool.cache.impl.LFUCache;
public class NoteCache {
- private static final LFUCache CACHE = CacheUtil.newLFUCache(256,30*60*1000);
+ private static final LFUCache CACHE = CacheUtil.newLFUCache(256, 30 * 60 * 1000);
public static Note getNote(String mixKey) {
return CACHE.get(mixKey);
@@ -19,7 +19,7 @@ public class NoteCache {
public static void deleteNote(String mixKey) {
Note note = CACHE.get(mixKey);
- if(null!=note) {
+ if (null != note) {
note.setState(0);
note.setTextBytes(null);
}
diff --git a/src/main/java/com/flagnote/note/controller/NoteController.java b/src/main/java/com/flagnote/note/controller/NoteController.java
index cf8da1e..2ec3be1 100644
--- a/src/main/java/com/flagnote/note/controller/NoteController.java
+++ b/src/main/java/com/flagnote/note/controller/NoteController.java
@@ -22,25 +22,23 @@ import com.flagnote.note.service.NoteService;
import com.flagnote.note.utils.BizKeyUtils;
import com.flagnote.note.utils.JsonResult;
-import cn.hutool.core.util.ZipUtil;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
-
@Slf4j
@RestController
public class NoteController {
@Autowired
private NoteService noteService;
-
+
@RequestMapping(value = "/note/keyMeta", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public JsonResult getKeyMeta() {
KeyMeta c = new KeyMeta();
String key = BizKeyUtils.getKey();
c.setKey(key);
c.setServerTime(new Date().getTime());
- c.setCipher(BizKeyUtils.getCipher(key,c.getServerTime().toString()));
+ c.setCipher(BizKeyUtils.getCipher(key, c.getServerTime().toString()));
c.setSecretKey(BizKeyUtils.getSecretKey(key));
return JsonResult.ok(c);
}
@@ -51,21 +49,21 @@ public class NoteController {
Note note = noteService.getNote(key);
meta.setKey(key);
meta.setSecretKey(BizKeyUtils.getSecretKey(key));
-
+
if (null == note) {
return JsonResult.ok(meta);
}
-
+
meta.setServerTime(new Date().getTime());
meta.setLock(note.getLock());
meta.setMd5(note.getMd5());
meta.setState(note.getState());
meta.setTtl(note.getTtl());
- if(meta.getState()!=1) {
+ if (meta.getState() != 1) {
meta.setSecretKey(null);
}
-
+
return JsonResult.ok(meta);
}
@@ -73,11 +71,11 @@ public class NoteController {
public void getNote(@PathVariable("key") String key, HttpServletResponse response) {
Note note = noteService.getNote(key);
-
+
response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + key + "\"");
-
- if(null==note) {
+
+ if (null == note) {
return;
}
@@ -109,9 +107,10 @@ public class NoteController {
@RequestMapping(value = "/note/{key:[abcdefghijkmnopqrstuvwxyz23456789]{16}}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public JsonResult saveNote(@PathVariable("key") String key, @RequestPart("file") MultipartFile file,
- @RequestParam("lock") Integer lock, @RequestParam("md5") String md5,@RequestParam("initTime") String initTime) throws IOException {
+ @RequestParam("lock") Integer lock, @RequestParam("md5") String md5,
+ @RequestParam("initTime") String initTime) throws IOException {
Date pushTime = new Date();
-
+
Note note = new Note();
note.setKey(key);
note.setTextBytes(file.getBytes());
@@ -130,11 +129,10 @@ public class NoteController {
noteService.deleteNote(key);
return JsonResult.ok(key);
}
-
+
@RequestMapping(value = "/note/{key:[abcdefghijkmnopqrstuvwxyz23456789]{16}}.txt", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
public String getNoteText(@PathVariable("key") String key) {
return noteService.getNoteText(key);
}
-
}
diff --git a/src/main/java/com/flagnote/note/entity/KeyMeta.java b/src/main/java/com/flagnote/note/entity/KeyMeta.java
index 01d192b..b2f2b90 100644
--- a/src/main/java/com/flagnote/note/entity/KeyMeta.java
+++ b/src/main/java/com/flagnote/note/entity/KeyMeta.java
@@ -6,15 +6,15 @@ import lombok.Data;
@Data
public class KeyMeta implements Serializable {
-
+
private static final long serialVersionUID = -2816061962747625732L;
-
+
private String key;
-
+
private String secretKey;
-
+
private String cipher;
-
+
private Long serverTime;
}
diff --git a/src/main/java/com/flagnote/note/entity/Note.java b/src/main/java/com/flagnote/note/entity/Note.java
index 09ab5a3..30affa1 100644
--- a/src/main/java/com/flagnote/note/entity/Note.java
+++ b/src/main/java/com/flagnote/note/entity/Note.java
@@ -24,7 +24,7 @@ public class Note implements Serializable {
private String cipher;
private Integer state;
-
+
private Date initTime;
private Date pushTime;
diff --git a/src/main/java/com/flagnote/note/entity/NoteMeta.java b/src/main/java/com/flagnote/note/entity/NoteMeta.java
index 78ede53..80429af 100644
--- a/src/main/java/com/flagnote/note/entity/NoteMeta.java
+++ b/src/main/java/com/flagnote/note/entity/NoteMeta.java
@@ -6,21 +6,21 @@ import lombok.Data;
@Data
public class NoteMeta implements Serializable {
-
+
private static final long serialVersionUID = -8234044213813670440L;
private String key;
-
+
private String secretKey;
-
+
private Integer state;
-
+
private String cipher;
-
+
private Integer lock;
-
+
private String md5;
-
+
private Long serverTime;
private Long ttl;
diff --git a/src/main/java/com/flagnote/note/entity/Secret.java b/src/main/java/com/flagnote/note/entity/Secret.java
index f416b54..dab27c2 100644
--- a/src/main/java/com/flagnote/note/entity/Secret.java
+++ b/src/main/java/com/flagnote/note/entity/Secret.java
@@ -4,21 +4,18 @@ import java.io.Serializable;
import lombok.Data;
-
-
@Data
public class Secret implements Serializable {
-
/**
*
*/
private static final long serialVersionUID = -4125184146529253566L;
private String key;
-
+
private String password;
-
+
private String secret;
}
diff --git a/src/main/java/com/flagnote/note/repository/NoteMongoRepository.java b/src/main/java/com/flagnote/note/repository/NoteMongoRepository.java
index 29b08e3..0fcba4a 100644
--- a/src/main/java/com/flagnote/note/repository/NoteMongoRepository.java
+++ b/src/main/java/com/flagnote/note/repository/NoteMongoRepository.java
@@ -12,9 +12,8 @@ import com.flagnote.note.entity.Note;
@Repository
public interface NoteMongoRepository extends MongoRepository {
-
-
+
@Query(value = "{'state' : {'$eq' : 1},'expireTime' : {'$lt' : ?0}}")
- public Page findExpireNote(Date date,Pageable page);
+ public Page findExpireNote(Date date, Pageable page);
}
diff --git a/src/main/java/com/flagnote/note/schedule/NoteSchedule.java b/src/main/java/com/flagnote/note/schedule/NoteSchedule.java
index 3acc1b8..bf1d383 100644
--- a/src/main/java/com/flagnote/note/schedule/NoteSchedule.java
+++ b/src/main/java/com/flagnote/note/schedule/NoteSchedule.java
@@ -1,14 +1,11 @@
package com.flagnote.note.schedule;
import java.util.Date;
-import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
-import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Pageable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
@@ -19,29 +16,29 @@ import com.flagnote.note.repository.NoteMongoRepository;
@EnableScheduling
@Configuration
public class NoteSchedule {
-
+
@Autowired
private NoteMongoRepository noteMongoRepository;
@Scheduled(cron = "*/30 * * * * ?")
- public void updateExpiredNote() {
-
- while(true) {
-
- PageRequest pageRequest = PageRequest.of(0,5);
- Page noteList = noteMongoRepository.findExpireNote(new Date(),pageRequest);
-
- if(noteList.getNumberOfElements()>0) {
+ public void updateExpiredNote() {
+
+ while (true) {
+
+ PageRequest pageRequest = PageRequest.of(0, 5);
+ Page noteList = noteMongoRepository.findExpireNote(new Date(), pageRequest);
+
+ if (noteList.getNumberOfElements() > 0) {
for (Note note : noteList) {
note.setState(0);
note.setTextBytes(null);
NoteCache.deleteNote(note.getId());
}
noteMongoRepository.saveAll(noteList);
- }else {
+ } else {
break;
}
}
-
- }
+
+ }
}
diff --git a/src/main/java/com/flagnote/note/service/NoteServiceImpl.java b/src/main/java/com/flagnote/note/service/NoteServiceImpl.java
index 359d8bb..10e580e 100644
--- a/src/main/java/com/flagnote/note/service/NoteServiceImpl.java
+++ b/src/main/java/com/flagnote/note/service/NoteServiceImpl.java
@@ -1,13 +1,9 @@
package com.flagnote.note.service;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.Charset;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import org.springframework.util.Assert;
import com.flagnote.note.aop.CountTime;
import com.flagnote.note.cache.NoteCache;
@@ -18,7 +14,6 @@ import com.flagnote.note.utils.SecretUtils;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
-import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.ZipUtil;
@Service
@@ -37,7 +32,7 @@ public class NoteServiceImpl implements NoteService {
if (null == note) {
note = noteMongoRepository.findById(mixKey).orElse(null);
}
-
+
if (null == note) {
return null;
}
@@ -86,7 +81,7 @@ public class NoteServiceImpl implements NoteService {
if (null == exists) {
noteMongoRepository.save(note);
-
+
NoteCache.save(note);
} else {
if (!exists.getMd5().equals(note.getMd5())) {
@@ -98,9 +93,9 @@ public class NoteServiceImpl implements NoteService {
@Override
public void deleteNote(String key) {
String mixKey = BizKeyUtils.mixKey(key);
-
+
NoteCache.deleteNote(mixKey);
-
+
Note note = noteMongoRepository.findById(mixKey).orElse(null);
if (null != note) {
note.setState(0);
@@ -113,12 +108,12 @@ public class NoteServiceImpl implements NoteService {
if (null == note.getTextBytes()) {
return null;
}
-
+
String secretKey = BizKeyUtils.getSecretKey(key);
-
- byte[] bytes = SecretUtils.aesDecode(note.getTextBytes(),secretKey);
+
+ byte[] bytes = SecretUtils.aesDecode(note.getTextBytes(), secretKey);
bytes = ZipUtil.unGzip(bytes);
-
+
String result = new String(bytes);
if (result.startsWith("FLAGNOTE#")) {
return result.substring(9);
diff --git a/src/main/java/com/flagnote/note/utils/BizKeyUtils.java b/src/main/java/com/flagnote/note/utils/BizKeyUtils.java
index d0def81..e01386b 100644
--- a/src/main/java/com/flagnote/note/utils/BizKeyUtils.java
+++ b/src/main/java/com/flagnote/note/utils/BizKeyUtils.java
@@ -4,14 +4,13 @@ import java.io.UnsupportedEncodingException;
import java.util.Date;
import org.springframework.util.DigestUtils;
-import org.springframework.util.StringUtils;
public class BizKeyUtils {
public static final String MIX_STRING = "6v8muhqp8ta45ncsyi8y";
-
+
public static final String SECRET_KEY_STRING = "dswoun5atk2q363fmdfe";
-
+
public static final String RANGE_STRING = "abcdefhikmnopqstuvwxyz23456789";
public static String getKey() {
@@ -87,51 +86,46 @@ public class BizKeyUtils {
return Integer.parseInt(String.valueOf(new Date().getTime()).substring(0, 4));
}
- public static String getCipher(String key,String initTime) {
- return md5(key +"#"+ MIX_STRING + "#" + initTime);
+ public static String getCipher(String key, String initTime) {
+ return md5(key + "#" + MIX_STRING + "#" + initTime);
}
-
- public static Boolean validateCipher(String key,String initTime,String cipher) {
- return md5(key +"#"+ MIX_STRING + "#" + initTime).equals(cipher);
+
+ public static Boolean validateCipher(String key, String initTime, String cipher) {
+ return md5(key + "#" + MIX_STRING + "#" + initTime).equals(cipher);
}
-
public static String getSecretKey(String key) {
- return md5(key +"#"+SECRET_KEY_STRING);
+ return md5(key + "#" + SECRET_KEY_STRING);
}
-
+
public static void main(String[] args) {
-
+
int c = 0;
- while(true) {
+ while (true) {
c++;
StringBuffer sb = new StringBuffer();
for (int i = 0; i < 16; i++) {
sb.append(RANGE_STRING.charAt(RandomUtils.nextInt(30)));
}
-
+
Boolean result = validateKey(sb.toString());
-
- if(c%1000==0) {
- System.out.println(c);
+
+ if (c % 1000 == 0) {
+ System.out.println(c);
System.out.println(result);
System.out.println(sb.toString());
}
-
- if(result) {
- System.out.println(c);
+
+ if (result) {
+ System.out.println(c);
System.out.println(result);
System.out.println(sb.toString());
break;
}
}
-
-
-
-
}
}
\ No newline at end of file
diff --git a/src/main/java/com/flagnote/note/utils/GlobalExceptionHandler.java b/src/main/java/com/flagnote/note/utils/GlobalExceptionHandler.java
index 8a548e7..5c2b845 100644
--- a/src/main/java/com/flagnote/note/utils/GlobalExceptionHandler.java
+++ b/src/main/java/com/flagnote/note/utils/GlobalExceptionHandler.java
@@ -11,29 +11,27 @@ import lombok.extern.slf4j.Slf4j;
@RestControllerAdvice
public class GlobalExceptionHandler {
- @ExceptionHandler(RuntimeException.class)
- public Object businessExceptionHandler(HttpServletRequest request,HttpServletResponse response,Exception e)
- {
- log.error("ExceptionHandler(RuntimeException.class)",e);
- JsonResult jsonResult = new JsonResult();
- String message = e.getMessage();
- if (null!=message && message.matches("^E:\\d{6}$")) {
- jsonResult.setCode(message.substring(2, 8));
- }else {
+ @ExceptionHandler(RuntimeException.class)
+ public Object businessExceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception e) {
+ log.error("ExceptionHandler(RuntimeException.class)", e);
+ JsonResult jsonResult = new JsonResult();
+ String message = e.getMessage();
+ if (null != message && message.matches("^E:\\d{6}$")) {
+ jsonResult.setCode(message.substring(2, 8));
+ } else {
jsonResult.setCode("800000");
}
- jsonResult.setMessage("business exception");
- return jsonResult;
- }
+ jsonResult.setMessage("business exception");
+ return jsonResult;
+ }
- @ExceptionHandler(Exception.class)
- public Object exceptionHandler(HttpServletRequest request,HttpServletResponse response,Exception e)
- {
- log.error("ExceptionHandler(Exception.class)",e);
- JsonResult jsonResult = new JsonResult();
- jsonResult.setCode("900000");
- jsonResult.setMessage("exception");
- return jsonResult;
- }
+ @ExceptionHandler(Exception.class)
+ public Object exceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception e) {
+ log.error("ExceptionHandler(Exception.class)", e);
+ JsonResult jsonResult = new JsonResult();
+ jsonResult.setCode("900000");
+ jsonResult.setMessage("exception");
+ return jsonResult;
+ }
}
diff --git a/src/main/java/com/flagnote/note/utils/JsonUtils.java b/src/main/java/com/flagnote/note/utils/JsonUtils.java
index 500d306..7df36e6 100644
--- a/src/main/java/com/flagnote/note/utils/JsonUtils.java
+++ b/src/main/java/com/flagnote/note/utils/JsonUtils.java
@@ -14,99 +14,96 @@ import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import lombok.extern.slf4j.Slf4j;
-
+
@Slf4j
public class JsonUtils {
-
- private static ObjectMapper om = new ObjectMapper();
-
- static {
-
- // 对象的所有字段全部列入,还是其他的选项,可以忽略null等
- om.setSerializationInclusion(Include.ALWAYS);
- // 设置Date类型的序列化及反序列化格式
- om.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
-
- // 忽略空Bean转json的错误
- om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
- // 忽略未知属性,防止json字符串中存在,java对象中不存在对应属性的情况出现错误
- om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-
- // 注册一个时间序列化及反序列化的处理模块,用于解决jdk8中localDateTime等的序列化问题
- om.registerModule(new JavaTimeModule());
- }
-
- /**
- * 对象 => json字符串
- *
- * @param obj 源对象
- */
- public static String toJson(T obj) {
-
- String json = null;
- if (obj != null) {
- try {
- json = om.writeValueAsString(obj);
- } catch (JsonProcessingException e) {
- log.warn(e.getMessage(), e);
- throw new IllegalArgumentException(e.getMessage());
- }
- }
- return json;
- }
-
- /**
- * json字符串 => 对象
- *
- * @param json 源json串
- * @param clazz 对象类
- * @param 泛型
- */
- public static T parse(String json, Class clazz) {
-
- return parse(json, clazz, null);
- }
-
- /**
- * json字符串 => 对象
- *
- * @param json 源json串
- * @param type 对象类型
- * @param 泛型
- */
- public static T parse(String json, TypeReference type) {
-
- return parse(json, null, type);
- }
-
-
- /**
- * json => 对象处理方法
- *
- * 参数clazz和type必须一个为null,另一个不为null
- *
- * 此方法不对外暴露,访问权限为private
- *
- * @param json 源json串
- * @param clazz 对象类
- * @param type 对象类型
- * @param 泛型
- */
- private static T parse(String json, Class clazz, TypeReference type) {
-
- T obj = null;
- if (StringUtils.hasLength(json)) {
- try {
- if (clazz != null) {
- obj = om.readValue(json, clazz);
- } else {
- obj = om.readValue(json, type);
- }
- } catch (IOException e) {
- log.warn(e.getMessage(), e);
- throw new IllegalArgumentException(e.getMessage());
- }
- }
- return obj;
- }
+
+ private static ObjectMapper om = new ObjectMapper();
+
+ static {
+
+ // 对象的所有字段全部列入,还是其他的选项,可以忽略null等
+ om.setSerializationInclusion(Include.ALWAYS);
+ // 设置Date类型的序列化及反序列化格式
+ om.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
+
+ // 忽略空Bean转json的错误
+ om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
+ // 忽略未知属性,防止json字符串中存在,java对象中不存在对应属性的情况出现错误
+ om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+
+ // 注册一个时间序列化及反序列化的处理模块,用于解决jdk8中localDateTime等的序列化问题
+ om.registerModule(new JavaTimeModule());
+ }
+
+ /**
+ * 对象 => json字符串
+ *
+ * @param obj 源对象
+ */
+ public static String toJson(T obj) {
+
+ String json = null;
+ if (obj != null) {
+ try {
+ json = om.writeValueAsString(obj);
+ } catch (JsonProcessingException e) {
+ log.warn(e.getMessage(), e);
+ throw new IllegalArgumentException(e.getMessage());
+ }
+ }
+ return json;
+ }
+
+ /**
+ * json字符串 => 对象
+ *
+ * @param json 源json串
+ * @param clazz 对象类
+ * @param 泛型
+ */
+ public static T parse(String json, Class clazz) {
+
+ return parse(json, clazz, null);
+ }
+
+ /**
+ * json字符串 => 对象
+ *
+ * @param json 源json串
+ * @param type 对象类型
+ * @param 泛型
+ */
+ public static T parse(String json, TypeReference type) {
+
+ return parse(json, null, type);
+ }
+
+ /**
+ * json => 对象处理方法
+ * 参数clazz和type必须一个为null,另一个不为null
+ * 此方法不对外暴露,访问权限为private
+ *
+ * @param json 源json串
+ * @param clazz 对象类
+ * @param type 对象类型
+ * @param 泛型
+ */
+ private static T parse(String json, Class clazz, TypeReference type) {
+
+ T obj = null;
+ if (StringUtils.hasLength(json)) {
+ try {
+ if (clazz != null) {
+ obj = om.readValue(json, clazz);
+ } else {
+ obj = om.readValue(json, type);
+ }
+ } catch (IOException e) {
+ log.warn(e.getMessage(), e);
+ throw new IllegalArgumentException(e.getMessage());
+ }
+ }
+ return obj;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/flagnote/note/utils/RandomUtils.java b/src/main/java/com/flagnote/note/utils/RandomUtils.java
index 4c565eb..601dca5 100644
--- a/src/main/java/com/flagnote/note/utils/RandomUtils.java
+++ b/src/main/java/com/flagnote/note/utils/RandomUtils.java
@@ -6,15 +6,15 @@ import java.security.SecureRandom;
public class RandomUtils {
public static SecureRandom sr = null;
-
+
static {
- try {
- sr = SecureRandom.getInstanceStrong();
- } catch (NoSuchAlgorithmException e) {
- sr = new SecureRandom();
- }
+ try {
+ sr = SecureRandom.getInstanceStrong();
+ } catch (NoSuchAlgorithmException e) {
+ sr = new SecureRandom();
+ }
}
-
+
public static Integer nextInt(Integer num) {
return sr.nextInt(num);
}
diff --git a/src/main/java/com/flagnote/note/utils/SecretUtils.java b/src/main/java/com/flagnote/note/utils/SecretUtils.java
index efd37e9..24d0a9b 100644
--- a/src/main/java/com/flagnote/note/utils/SecretUtils.java
+++ b/src/main/java/com/flagnote/note/utils/SecretUtils.java
@@ -1,17 +1,10 @@
package com.flagnote.note.utils;
-import java.nio.ByteBuffer;
-import java.util.Arrays;
-
import javax.crypto.spec.SecretKeySpec;
-import cn.hutool.core.codec.Base64;
-import cn.hutool.core.util.PrimitiveArrayUtil;
-import cn.hutool.core.util.ZipUtil;
import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.symmetric.AES;
-import cn.hutool.crypto.symmetric.XXTEA;
public class SecretUtils {
@@ -24,10 +17,9 @@ public class SecretUtils {
// text = PrimitiveArrayUtil.addAll(prefix,text,suffix);
return text;
}
-
- public static byte[] aesDecode(byte[] bytes,String keyWord) {
- AES aes = new AES(Mode.ECB, Padding.NoPadding,
- new SecretKeySpec(keyWord.getBytes(), "AES"));
+
+ public static byte[] aesDecode(byte[] bytes, String keyWord) {
+ AES aes = new AES(Mode.ECB, Padding.NoPadding, new SecretKeySpec(keyWord.getBytes(), "AES"));
return aes.decrypt(bytes);
}
}
diff --git a/src/main/resources/bootstrap.yml b/src/main/resources/bootstrap.yml
index 68cedb7..d0dae9f 100644
--- a/src/main/resources/bootstrap.yml
+++ b/src/main/resources/bootstrap.yml
@@ -8,4 +8,3 @@ spring:
uri: http://flagnote-config-01:8080/flagnote-config,http://flagnote-config-02:8080/flagnote-config
config:
import: optional:configserver:http://flagnote-config-01:8080/,optional:configserver:http://flagnote-config-02:8080/
-
diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml
new file mode 100644
index 0000000..a0464d2
--- /dev/null
+++ b/src/main/resources/logback-spring.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+ ${pattern}
+ ${charsetEncoding}
+
+
+
+ true
+
+ ${pattern}
+ ${charsetEncoding}
+
+
+
+ ${LOG_HOME}${file.separator}%d{yyMMdd}_info_%i.log
+
+ 30
+ 20MB
+
+
+ INFO
+
+
+
+
+
+
+
+
\ No newline at end of file