spring boot 3.0.6
This commit is contained in:
13
pom.xml
13
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>3.0.5</version>
|
<version>3.0.6</version>
|
||||||
<relativePath /> <!-- lookup parent from repository -->
|
<relativePath /> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.flagnote</groupId>
|
<groupId>com.flagnote</groupId>
|
||||||
@@ -20,7 +20,8 @@
|
|||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
<maven.compiler.compilerVersion>17</maven.compiler.compilerVersion>
|
<maven.compiler.compilerVersion>17</maven.compiler.compilerVersion>
|
||||||
<spring-cloud.version>2022.0.2</spring-cloud.version>
|
<spring-cloud.version>2022.0.2</spring-cloud.version>
|
||||||
<docker.image.prefix>flagnote</docker.image.prefix>
|
<docker.repostory>registry.openif.com:5000</docker.repostory>
|
||||||
|
<docker.registry.name>flagnote</docker.registry.name>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -123,9 +124,13 @@
|
|||||||
<artifactId>docker-maven-plugin</artifactId>
|
<artifactId>docker-maven-plugin</artifactId>
|
||||||
<version>1.2.2</version>
|
<version>1.2.2</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<dockerHost>http://rancher:42375</dockerHost>
|
<serverId>docker-openif</serverId>
|
||||||
|
<registryUrl>http://${docker.repository}</registryUrl>
|
||||||
|
<pushImage>true</pushImage>
|
||||||
|
<dockerHost>http://144.34.221.20:42375</dockerHost>
|
||||||
<imageName>
|
<imageName>
|
||||||
${docker.image.prefix}/${project.artifactId}:${project.version}</imageName>
|
${docker.repostory}/${docker.registry.name}/${project.artifactId}:${project.version}
|
||||||
|
</imageName>
|
||||||
<dockerDirectory>src/main/docker</dockerDirectory>
|
<dockerDirectory>src/main/docker</dockerDirectory>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
package com.flagnote.note.aop;
|
package com.flagnote.note.aop;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
|
||||||
import org.aspectj.lang.annotation.AfterReturning;
|
import org.aspectj.lang.annotation.AfterReturning;
|
||||||
import org.aspectj.lang.annotation.Around;
|
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Before;
|
import org.aspectj.lang.annotation.Before;
|
||||||
import org.aspectj.lang.annotation.Pointcut;
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
@@ -18,25 +14,25 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class AopConfig {
|
public class AopConfig {
|
||||||
@Pointcut("@annotation(com.flagnote.note.aop.CountTime)")
|
@Pointcut("@annotation(com.flagnote.note.aop.CountTime)")
|
||||||
public void logTime() {
|
public void logTime() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ThreadLocal<StopWatch> stopWatchLocal = new ThreadLocal<>();
|
private ThreadLocal<StopWatch> stopWatchLocal = new ThreadLocal<>();
|
||||||
|
|
||||||
@Before("logTime()")
|
@Before("logTime()")
|
||||||
public void before() {
|
public void before() {
|
||||||
StopWatch stopWatch = new StopWatch();
|
StopWatch stopWatch = new StopWatch();
|
||||||
stopWatchLocal.set(stopWatch);
|
stopWatchLocal.set(stopWatch);
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterReturning(value = "logTime()", returning = "val")
|
@AfterReturning(value = "logTime()", returning = "val")
|
||||||
public void afterReturning(JoinPoint joinPoint, Object val) {
|
public void afterReturning(JoinPoint joinPoint, Object val) {
|
||||||
StopWatch stopWatch = stopWatchLocal.get();
|
StopWatch stopWatch = stopWatchLocal.get();
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
log.info("method:"+ joinPoint.getSignature().getName()+">>> " + stopWatch.getLastTaskTimeMillis() + " ms.");
|
log.info("method:" + joinPoint.getSignature().getName() + ">>> " + stopWatch.getLastTaskTimeMillis() + " ms.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
package com.flagnote.note.aop;
|
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.ElementType.METHOD;
|
||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
@Target(METHOD)
|
@Target(METHOD)
|
||||||
public @interface CountTime {
|
public @interface CountTime {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import cn.hutool.cache.impl.LFUCache;
|
|||||||
|
|
||||||
public class NoteCache {
|
public class NoteCache {
|
||||||
|
|
||||||
private static final LFUCache<String, Note> CACHE = CacheUtil.newLFUCache(256,30*60*1000);
|
private static final LFUCache<String, Note> CACHE = CacheUtil.newLFUCache(256, 30 * 60 * 1000);
|
||||||
|
|
||||||
public static Note getNote(String mixKey) {
|
public static Note getNote(String mixKey) {
|
||||||
return CACHE.get(mixKey);
|
return CACHE.get(mixKey);
|
||||||
@@ -19,7 +19,7 @@ public class NoteCache {
|
|||||||
|
|
||||||
public static void deleteNote(String mixKey) {
|
public static void deleteNote(String mixKey) {
|
||||||
Note note = CACHE.get(mixKey);
|
Note note = CACHE.get(mixKey);
|
||||||
if(null!=note) {
|
if (null != note) {
|
||||||
note.setState(0);
|
note.setState(0);
|
||||||
note.setTextBytes(null);
|
note.setTextBytes(null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,9 @@ import com.flagnote.note.service.NoteService;
|
|||||||
import com.flagnote.note.utils.BizKeyUtils;
|
import com.flagnote.note.utils.BizKeyUtils;
|
||||||
import com.flagnote.note.utils.JsonResult;
|
import com.flagnote.note.utils.JsonResult;
|
||||||
|
|
||||||
import cn.hutool.core.util.ZipUtil;
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
public class NoteController {
|
public class NoteController {
|
||||||
@@ -40,7 +38,7 @@ public class NoteController {
|
|||||||
String key = BizKeyUtils.getKey();
|
String key = BizKeyUtils.getKey();
|
||||||
c.setKey(key);
|
c.setKey(key);
|
||||||
c.setServerTime(new Date().getTime());
|
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));
|
c.setSecretKey(BizKeyUtils.getSecretKey(key));
|
||||||
return JsonResult.ok(c);
|
return JsonResult.ok(c);
|
||||||
}
|
}
|
||||||
@@ -62,7 +60,7 @@ public class NoteController {
|
|||||||
meta.setState(note.getState());
|
meta.setState(note.getState());
|
||||||
meta.setTtl(note.getTtl());
|
meta.setTtl(note.getTtl());
|
||||||
|
|
||||||
if(meta.getState()!=1) {
|
if (meta.getState() != 1) {
|
||||||
meta.setSecretKey(null);
|
meta.setSecretKey(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +75,7 @@ public class NoteController {
|
|||||||
response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||||
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + key + "\"");
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + key + "\"");
|
||||||
|
|
||||||
if(null==note) {
|
if (null == note) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +107,8 @@ public class NoteController {
|
|||||||
|
|
||||||
@RequestMapping(value = "/note/{key:[abcdefghijkmnopqrstuvwxyz23456789]{16}}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
@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,
|
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();
|
Date pushTime = new Date();
|
||||||
|
|
||||||
Note note = new Note();
|
Note note = new Note();
|
||||||
@@ -136,5 +135,4 @@ public class NoteController {
|
|||||||
return noteService.getNoteText(key);
|
return noteService.getNoteText(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,9 @@ import java.io.Serializable;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class Secret implements Serializable {
|
public class Secret implements Serializable {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ import com.flagnote.note.entity.Note;
|
|||||||
@Repository
|
@Repository
|
||||||
public interface NoteMongoRepository extends MongoRepository<Note, String> {
|
public interface NoteMongoRepository extends MongoRepository<Note, String> {
|
||||||
|
|
||||||
|
|
||||||
@Query(value = "{'state' : {'$eq' : 1},'expireTime' : {'$lt' : ?0}}")
|
@Query(value = "{'state' : {'$eq' : 1},'expireTime' : {'$lt' : ?0}}")
|
||||||
public Page<Note> findExpireNote(Date date,Pageable page);
|
public Page<Note> findExpireNote(Date date, Pageable page);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
package com.flagnote.note.schedule;
|
package com.flagnote.note.schedule;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.domain.Example;
|
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
|
||||||
@@ -24,24 +21,24 @@ public class NoteSchedule {
|
|||||||
private NoteMongoRepository noteMongoRepository;
|
private NoteMongoRepository noteMongoRepository;
|
||||||
|
|
||||||
@Scheduled(cron = "*/30 * * * * ?")
|
@Scheduled(cron = "*/30 * * * * ?")
|
||||||
public void updateExpiredNote() {
|
public void updateExpiredNote() {
|
||||||
|
|
||||||
while(true) {
|
while (true) {
|
||||||
|
|
||||||
PageRequest pageRequest = PageRequest.of(0,5);
|
PageRequest pageRequest = PageRequest.of(0, 5);
|
||||||
Page<Note> noteList = noteMongoRepository.findExpireNote(new Date(),pageRequest);
|
Page<Note> noteList = noteMongoRepository.findExpireNote(new Date(), pageRequest);
|
||||||
|
|
||||||
if(noteList.getNumberOfElements()>0) {
|
if (noteList.getNumberOfElements() > 0) {
|
||||||
for (Note note : noteList) {
|
for (Note note : noteList) {
|
||||||
note.setState(0);
|
note.setState(0);
|
||||||
note.setTextBytes(null);
|
note.setTextBytes(null);
|
||||||
NoteCache.deleteNote(note.getId());
|
NoteCache.deleteNote(note.getId());
|
||||||
}
|
}
|
||||||
noteMongoRepository.saveAll(noteList);
|
noteMongoRepository.saveAll(noteList);
|
||||||
}else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
package com.flagnote.note.service;
|
package com.flagnote.note.service;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.CharBuffer;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
import com.flagnote.note.aop.CountTime;
|
import com.flagnote.note.aop.CountTime;
|
||||||
import com.flagnote.note.cache.NoteCache;
|
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.date.DateUtil;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.core.util.CharsetUtil;
|
|
||||||
import cn.hutool.core.util.ZipUtil;
|
import cn.hutool.core.util.ZipUtil;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -116,7 +111,7 @@ public class NoteServiceImpl implements NoteService {
|
|||||||
|
|
||||||
String secretKey = BizKeyUtils.getSecretKey(key);
|
String secretKey = BizKeyUtils.getSecretKey(key);
|
||||||
|
|
||||||
byte[] bytes = SecretUtils.aesDecode(note.getTextBytes(),secretKey);
|
byte[] bytes = SecretUtils.aesDecode(note.getTextBytes(), secretKey);
|
||||||
bytes = ZipUtil.unGzip(bytes);
|
bytes = ZipUtil.unGzip(bytes);
|
||||||
|
|
||||||
String result = new String(bytes);
|
String result = new String(bytes);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import java.io.UnsupportedEncodingException;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.springframework.util.DigestUtils;
|
import org.springframework.util.DigestUtils;
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
public class BizKeyUtils {
|
public class BizKeyUtils {
|
||||||
|
|
||||||
@@ -87,23 +86,22 @@ public class BizKeyUtils {
|
|||||||
return Integer.parseInt(String.valueOf(new Date().getTime()).substring(0, 4));
|
return Integer.parseInt(String.valueOf(new Date().getTime()).substring(0, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCipher(String key,String initTime) {
|
public static String getCipher(String key, String initTime) {
|
||||||
return md5(key +"#"+ MIX_STRING + "#" + initTime);
|
return md5(key + "#" + MIX_STRING + "#" + initTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Boolean validateCipher(String key,String initTime,String cipher) {
|
public static Boolean validateCipher(String key, String initTime, String cipher) {
|
||||||
return md5(key +"#"+ MIX_STRING + "#" + initTime).equals(cipher);
|
return md5(key + "#" + MIX_STRING + "#" + initTime).equals(cipher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String getSecretKey(String key) {
|
public static String getSecretKey(String key) {
|
||||||
return md5(key +"#"+SECRET_KEY_STRING);
|
return md5(key + "#" + SECRET_KEY_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
int c = 0;
|
int c = 0;
|
||||||
while(true) {
|
while (true) {
|
||||||
c++;
|
c++;
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
@@ -113,13 +111,13 @@ public class BizKeyUtils {
|
|||||||
|
|
||||||
Boolean result = validateKey(sb.toString());
|
Boolean result = validateKey(sb.toString());
|
||||||
|
|
||||||
if(c%1000==0) {
|
if (c % 1000 == 0) {
|
||||||
System.out.println(c);
|
System.out.println(c);
|
||||||
System.out.println(result);
|
System.out.println(result);
|
||||||
System.out.println(sb.toString());
|
System.out.println(sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(result) {
|
if (result) {
|
||||||
System.out.println(c);
|
System.out.println(c);
|
||||||
System.out.println(result);
|
System.out.println(result);
|
||||||
System.out.println(sb.toString());
|
System.out.println(sb.toString());
|
||||||
@@ -128,10 +126,6 @@ public class BizKeyUtils {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -11,29 +11,27 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
@RestControllerAdvice
|
@RestControllerAdvice
|
||||||
public class GlobalExceptionHandler {
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
@ExceptionHandler(RuntimeException.class)
|
@ExceptionHandler(RuntimeException.class)
|
||||||
public Object businessExceptionHandler(HttpServletRequest request,HttpServletResponse response,Exception e)
|
public Object businessExceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception e) {
|
||||||
{
|
log.error("ExceptionHandler(RuntimeException.class)", e);
|
||||||
log.error("ExceptionHandler(RuntimeException.class)",e);
|
JsonResult jsonResult = new JsonResult();
|
||||||
JsonResult jsonResult = new JsonResult();
|
String message = e.getMessage();
|
||||||
String message = e.getMessage();
|
if (null != message && message.matches("^E:\\d{6}$")) {
|
||||||
if (null!=message && message.matches("^E:\\d{6}$")) {
|
jsonResult.setCode(message.substring(2, 8));
|
||||||
jsonResult.setCode(message.substring(2, 8));
|
} else {
|
||||||
}else {
|
|
||||||
jsonResult.setCode("800000");
|
jsonResult.setCode("800000");
|
||||||
}
|
}
|
||||||
jsonResult.setMessage("business exception");
|
jsonResult.setMessage("business exception");
|
||||||
return jsonResult;
|
return jsonResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(Exception.class)
|
@ExceptionHandler(Exception.class)
|
||||||
public Object exceptionHandler(HttpServletRequest request,HttpServletResponse response,Exception e)
|
public Object exceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception e) {
|
||||||
{
|
log.error("ExceptionHandler(Exception.class)", e);
|
||||||
log.error("ExceptionHandler(Exception.class)",e);
|
JsonResult jsonResult = new JsonResult();
|
||||||
JsonResult jsonResult = new JsonResult();
|
jsonResult.setCode("900000");
|
||||||
jsonResult.setCode("900000");
|
jsonResult.setMessage("exception");
|
||||||
jsonResult.setMessage("exception");
|
return jsonResult;
|
||||||
return jsonResult;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,95 +18,92 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class JsonUtils {
|
public class JsonUtils {
|
||||||
|
|
||||||
private static ObjectMapper om = new ObjectMapper();
|
private static ObjectMapper om = new ObjectMapper();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
||||||
// 对象的所有字段全部列入,还是其他的选项,可以忽略null等
|
// 对象的所有字段全部列入,还是其他的选项,可以忽略null等
|
||||||
om.setSerializationInclusion(Include.ALWAYS);
|
om.setSerializationInclusion(Include.ALWAYS);
|
||||||
// 设置Date类型的序列化及反序列化格式
|
// 设置Date类型的序列化及反序列化格式
|
||||||
om.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
|
om.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
|
||||||
|
|
||||||
// 忽略空Bean转json的错误
|
// 忽略空Bean转json的错误
|
||||||
om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
||||||
// 忽略未知属性,防止json字符串中存在,java对象中不存在对应属性的情况出现错误
|
// 忽略未知属性,防止json字符串中存在,java对象中不存在对应属性的情况出现错误
|
||||||
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
|
||||||
// 注册一个时间序列化及反序列化的处理模块,用于解决jdk8中localDateTime等的序列化问题
|
// 注册一个时间序列化及反序列化的处理模块,用于解决jdk8中localDateTime等的序列化问题
|
||||||
om.registerModule(new JavaTimeModule());
|
om.registerModule(new JavaTimeModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对象 => json字符串
|
* 对象 => json字符串
|
||||||
*
|
*
|
||||||
* @param obj 源对象
|
* @param obj 源对象
|
||||||
*/
|
*/
|
||||||
public static <T> String toJson(T obj) {
|
public static <T> String toJson(T obj) {
|
||||||
|
|
||||||
String json = null;
|
String json = null;
|
||||||
if (obj != null) {
|
if (obj != null) {
|
||||||
try {
|
try {
|
||||||
json = om.writeValueAsString(obj);
|
json = om.writeValueAsString(obj);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
log.warn(e.getMessage(), e);
|
log.warn(e.getMessage(), e);
|
||||||
throw new IllegalArgumentException(e.getMessage());
|
throw new IllegalArgumentException(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* json字符串 => 对象
|
* json字符串 => 对象
|
||||||
*
|
*
|
||||||
* @param json 源json串
|
* @param json 源json串
|
||||||
* @param clazz 对象类
|
* @param clazz 对象类
|
||||||
* @param <T> 泛型
|
* @param <T> 泛型
|
||||||
*/
|
*/
|
||||||
public static <T> T parse(String json, Class<T> clazz) {
|
public static <T> T parse(String json, Class<T> clazz) {
|
||||||
|
|
||||||
return parse(json, clazz, null);
|
return parse(json, clazz, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* json字符串 => 对象
|
* json字符串 => 对象
|
||||||
*
|
*
|
||||||
* @param json 源json串
|
* @param json 源json串
|
||||||
* @param type 对象类型
|
* @param type 对象类型
|
||||||
* @param <T> 泛型
|
* @param <T> 泛型
|
||||||
*/
|
*/
|
||||||
public static <T> T parse(String json, TypeReference<T> type) {
|
public static <T> T parse(String json, TypeReference<T> type) {
|
||||||
|
|
||||||
return parse(json, null, type);
|
return parse(json, null, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* json => 对象处理方法 <br>
|
||||||
|
* 参数clazz和type必须一个为null,另一个不为null <br>
|
||||||
|
* 此方法不对外暴露,访问权限为private
|
||||||
|
*
|
||||||
|
* @param json 源json串
|
||||||
|
* @param clazz 对象类
|
||||||
|
* @param type 对象类型
|
||||||
|
* @param <T> 泛型
|
||||||
|
*/
|
||||||
|
private static <T> T parse(String json, Class<T> clazz, TypeReference<T> type) {
|
||||||
|
|
||||||
/**
|
T obj = null;
|
||||||
* json => 对象处理方法
|
if (StringUtils.hasLength(json)) {
|
||||||
* <br>
|
try {
|
||||||
* 参数clazz和type必须一个为null,另一个不为null
|
if (clazz != null) {
|
||||||
* <br>
|
obj = om.readValue(json, clazz);
|
||||||
* 此方法不对外暴露,访问权限为private
|
} else {
|
||||||
*
|
obj = om.readValue(json, type);
|
||||||
* @param json 源json串
|
}
|
||||||
* @param clazz 对象类
|
} catch (IOException e) {
|
||||||
* @param type 对象类型
|
log.warn(e.getMessage(), e);
|
||||||
* @param <T> 泛型
|
throw new IllegalArgumentException(e.getMessage());
|
||||||
*/
|
}
|
||||||
private static <T> T parse(String json, Class<T> clazz, TypeReference<T> type) {
|
}
|
||||||
|
return obj;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -8,11 +8,11 @@ public class RandomUtils {
|
|||||||
public static SecureRandom sr = null;
|
public static SecureRandom sr = null;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
sr = SecureRandom.getInstanceStrong();
|
sr = SecureRandom.getInstanceStrong();
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
sr = new SecureRandom();
|
sr = new SecureRandom();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Integer nextInt(Integer num) {
|
public static Integer nextInt(Integer num) {
|
||||||
|
|||||||
@@ -1,17 +1,10 @@
|
|||||||
package com.flagnote.note.utils;
|
package com.flagnote.note.utils;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
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.Mode;
|
||||||
import cn.hutool.crypto.Padding;
|
import cn.hutool.crypto.Padding;
|
||||||
import cn.hutool.crypto.symmetric.AES;
|
import cn.hutool.crypto.symmetric.AES;
|
||||||
import cn.hutool.crypto.symmetric.XXTEA;
|
|
||||||
|
|
||||||
public class SecretUtils {
|
public class SecretUtils {
|
||||||
|
|
||||||
@@ -25,9 +18,8 @@ public class SecretUtils {
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] aesDecode(byte[] bytes,String keyWord) {
|
public static byte[] aesDecode(byte[] bytes, String keyWord) {
|
||||||
AES aes = new AES(Mode.ECB, Padding.NoPadding,
|
AES aes = new AES(Mode.ECB, Padding.NoPadding, new SecretKeySpec(keyWord.getBytes(), "AES"));
|
||||||
new SecretKeySpec(keyWord.getBytes(), "AES"));
|
|
||||||
return aes.decrypt(bytes);
|
return aes.decrypt(bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,4 +8,3 @@ spring:
|
|||||||
uri: http://flagnote-config-01:8080/flagnote-config,http://flagnote-config-02:8080/flagnote-config
|
uri: http://flagnote-config-01:8080/flagnote-config,http://flagnote-config-02:8080/flagnote-config
|
||||||
config:
|
config:
|
||||||
import: optional:configserver:http://flagnote-config-01:8080/,optional:configserver:http://flagnote-config-02:8080/
|
import: optional:configserver:http://flagnote-config-01:8080/,optional:configserver:http://flagnote-config-02:8080/
|
||||||
|
|
||||||
|
|||||||
35
src/main/resources/logback-spring.xml
Normal file
35
src/main/resources/logback-spring.xml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<springProperty scope="context" name="logPath" source="logback.logPath"/>
|
||||||
|
<property name="pattern" value="[%date{yyyy-MM-dd HH:mm:ss.SSS}] %X{logthreadId} %-5level %logger{80} %method %line - %msg%n"/>
|
||||||
|
<property name="charsetEncoding" value="UTF-8"/>
|
||||||
|
<property name="LOG_HOME" value="${logPath}"/>
|
||||||
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>${pattern}</pattern>
|
||||||
|
<charset>${charsetEncoding}</charset>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
<appender name="infoLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<append>true</append>
|
||||||
|
<encoder>
|
||||||
|
<pattern>${pattern}</pattern>
|
||||||
|
<charset>${charsetEncoding}</charset>
|
||||||
|
</encoder>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||||
|
<fileNamePattern>
|
||||||
|
${LOG_HOME}${file.separator}%d{yyMMdd}_info_%i.log
|
||||||
|
</fileNamePattern>
|
||||||
|
<maxHistory>30</maxHistory>
|
||||||
|
<maxFileSize>20MB</maxFileSize>
|
||||||
|
</rollingPolicy>
|
||||||
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||||
|
<level>INFO</level>
|
||||||
|
</filter>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="console"/>
|
||||||
|
<appender-ref ref="infoLog"/>
|
||||||
|
</root>
|
||||||
|
</configuration>
|
||||||
Reference in New Issue
Block a user