From 4e7ec544b32c2fc95a3d74f47d85ba9974d2b8a5 Mon Sep 17 00:00:00 2001 From: liaozan <378024053@qq.com> Date: Tue, 19 Sep 2023 19:31:29 +0800 Subject: [PATCH] Remove unused code --- ...ParamArgumentResolverWebMvcConfigurer.java | 2 +- .../ExceptionHandingWebMvcConfigurer.java | 1 - .../web/result/ResponseBodyHandler.java | 1 - .../common/web/result/ResponseDTO.java | 19 ++++-- ...cterEncodingServletContextInitializer.java | 2 +- .../web/servlet/ContentCachingRequest.java | 58 ----------------- .../TraceIdInitializeServletListener.java | 2 +- .../servlet/WrappedByteArrayInputStream.java | 62 ------------------- .../web/support/BaseHandlerInterceptor.java | 2 +- .../authentication/AbstractAuthenticator.java | 4 +- .../AuthenticationInterceptor.java | 5 +- .../support/authentication/Authenticator.java | 2 +- .../utils/HandlerMethodAnnotationUtils.java | 2 +- pom.xml | 2 +- 14 files changed, 26 insertions(+), 138 deletions(-) delete mode 100644 commons/web-common/src/main/java/com/schbrain/common/web/servlet/ContentCachingRequest.java delete mode 100644 commons/web-common/src/main/java/com/schbrain/common/web/servlet/WrappedByteArrayInputStream.java diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/argument/BodyParamArgumentResolverWebMvcConfigurer.java b/commons/web-common/src/main/java/com/schbrain/common/web/argument/BodyParamArgumentResolverWebMvcConfigurer.java index a68cbff..2ddac53 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/argument/BodyParamArgumentResolverWebMvcConfigurer.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/argument/BodyParamArgumentResolverWebMvcConfigurer.java @@ -16,4 +16,4 @@ public class BodyParamArgumentResolverWebMvcConfigurer implements WebMvcConfigur resolvers.add(new BodyParamMethodArgumentResolver()); } -} \ No newline at end of file +} diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/exception/ExceptionHandingWebMvcConfigurer.java b/commons/web-common/src/main/java/com/schbrain/common/web/exception/ExceptionHandingWebMvcConfigurer.java index bd8eccd..9413379 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/exception/ExceptionHandingWebMvcConfigurer.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/exception/ExceptionHandingWebMvcConfigurer.java @@ -16,7 +16,6 @@ import java.util.List; public class ExceptionHandingWebMvcConfigurer implements WebMvcConfigurer { private final WebProperties webProperties; - private final GlobalExceptionHandler globalExceptionHandler; public ExceptionHandingWebMvcConfigurer(WebProperties webProperties, GlobalExceptionHandler globalExceptionHandler) { diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/result/ResponseBodyHandler.java b/commons/web-common/src/main/java/com/schbrain/common/web/result/ResponseBodyHandler.java index b021425..0e4726d 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/result/ResponseBodyHandler.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/result/ResponseBodyHandler.java @@ -24,7 +24,6 @@ import static org.springframework.core.annotation.AnnotationUtils.getAnnotation; public class ResponseBodyHandler implements ResponseBodyAdvice { private final List basePackages; - private final Map methodCache = new ConcurrentHashMap<>(); public ResponseBodyHandler(List basePackages) { diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/result/ResponseDTO.java b/commons/web-common/src/main/java/com/schbrain/common/web/result/ResponseDTO.java index 4ea19fc..934e332 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/result/ResponseDTO.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/result/ResponseDTO.java @@ -13,14 +13,25 @@ import lombok.Data; @Data public class ResponseDTO { + /** + * 错误码 + */ private int code; - + /** + * 前端需要执行的动作 + */ private int action; - + /** + * 错误信息 + */ private String message; - + /** + * 返回数据 + */ private T data; - + /** + * 请求ID + */ private String requestId = TraceIdUtils.get(); public static ResponseDTO success() { diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/servlet/CharacterEncodingServletContextInitializer.java b/commons/web-common/src/main/java/com/schbrain/common/web/servlet/CharacterEncodingServletContextInitializer.java index 9dd3822..82c1c5d 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/servlet/CharacterEncodingServletContextInitializer.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/servlet/CharacterEncodingServletContextInitializer.java @@ -22,4 +22,4 @@ public class CharacterEncodingServletContextInitializer implements ServletContex servletContext.setResponseCharacterEncoding(encoding); } -} \ No newline at end of file +} diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/servlet/ContentCachingRequest.java b/commons/web-common/src/main/java/com/schbrain/common/web/servlet/ContentCachingRequest.java deleted file mode 100644 index 7d772c1..0000000 --- a/commons/web-common/src/main/java/com/schbrain/common/web/servlet/ContentCachingRequest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.schbrain.common.web.servlet; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.util.StreamUtils; - -import javax.servlet.ServletInputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletRequestWrapper; -import java.io.IOException; - -/** - * @author liaozan - * @since 2023/8/22 - */ -@Slf4j -public class ContentCachingRequest extends HttpServletRequestWrapper { - - private final WrappedByteArrayInputStream inputStream; - - public ContentCachingRequest(HttpServletRequest request) { - super(request); - this.inputStream = createWrappedInputStream(request); - } - - @Override - public ServletInputStream getInputStream() { - return inputStream; - } - - /** - * Return the cached request content as a String. - *

- * The Charset used to decode the cached content is the same as returned by getCharacterEncoding. - */ - public String getContentAsString() { - return getContentAsString(getCharacterEncoding()); - } - - /** - * Return the cached request content as a String - */ - public String getContentAsString(String charset) { - return inputStream.getContentAsString(charset); - } - - /** - * Wrap request inputStream to WrappedByteArrayInputStream - */ - private WrappedByteArrayInputStream createWrappedInputStream(HttpServletRequest request) { - try { - byte[] bytes = StreamUtils.copyToByteArray(request.getInputStream()); - return new WrappedByteArrayInputStream(bytes); - } catch (IOException e) { - throw new IllegalStateException(e.getMessage(), e); - } - } - -} diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/servlet/TraceIdInitializeServletListener.java b/commons/web-common/src/main/java/com/schbrain/common/web/servlet/TraceIdInitializeServletListener.java index 82cf298..c8e25aa 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/servlet/TraceIdInitializeServletListener.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/servlet/TraceIdInitializeServletListener.java @@ -23,4 +23,4 @@ public class TraceIdInitializeServletListener implements ServletRequestListener TraceIdUtils.get(); } -} \ No newline at end of file +} diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/servlet/WrappedByteArrayInputStream.java b/commons/web-common/src/main/java/com/schbrain/common/web/servlet/WrappedByteArrayInputStream.java deleted file mode 100644 index 5834e7a..0000000 --- a/commons/web-common/src/main/java/com/schbrain/common/web/servlet/WrappedByteArrayInputStream.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.schbrain.common.web.servlet; - -import javax.servlet.ReadListener; -import javax.servlet.ServletInputStream; -import java.io.ByteArrayInputStream; -import java.nio.charset.Charset; - -/** - * @author liaozan - * @since 2023/8/22 - */ -class WrappedByteArrayInputStream extends ServletInputStream { - - private final ByteArrayInputStreamWrapper delegate; - - public WrappedByteArrayInputStream(byte[] bytes) { - this.delegate = new ByteArrayInputStreamWrapper(bytes); - } - - @Override - public boolean isFinished() { - return delegate.available() == 0; - } - - @Override - public boolean isReady() { - return true; - } - - @Override - public void setReadListener(ReadListener ignore) { - - } - - @Override - public int read() { - return delegate.read(); - } - - /** - * Return the cached request content as a String - */ - public String getContentAsString(String charset) { - return new String(delegate.getBytes(), Charset.forName(charset)); - } - - /** - * Simple {@link ByteArrayInputStream} wrapper that exposes the underlying byte array. - */ - private static class ByteArrayInputStreamWrapper extends ByteArrayInputStream { - - public ByteArrayInputStreamWrapper(byte[] bytes) { - super(bytes); - } - - public byte[] getBytes() { - return buf; - } - - } - -} diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/support/BaseHandlerInterceptor.java b/commons/web-common/src/main/java/com/schbrain/common/web/support/BaseHandlerInterceptor.java index 9214303..dfbd8ab 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/support/BaseHandlerInterceptor.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/support/BaseHandlerInterceptor.java @@ -62,4 +62,4 @@ public class BaseHandlerInterceptor implements AsyncHandlerInterceptor { } -} \ No newline at end of file +} diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AbstractAuthenticator.java b/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AbstractAuthenticator.java index 4aa0da2..09defea 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AbstractAuthenticator.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AbstractAuthenticator.java @@ -3,7 +3,6 @@ package com.schbrain.common.web.support.authentication; import cn.hutool.extra.spring.SpringUtil; import com.schbrain.common.annotation.IgnoreLogin; import com.schbrain.common.web.properties.WebProperties; -import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.util.Assert; @@ -19,7 +18,6 @@ import static com.schbrain.common.web.utils.HandlerMethodAnnotationUtils.hasAnno * @author liaozan * @since 2022/11/12 */ -@Data @Slf4j public abstract class AbstractAuthenticator implements Authenticator { @@ -55,7 +53,7 @@ public abstract class AbstractAuthenticator implements Authenticator { authentication = request.getParameter(authenticationVariableName); } if (StringUtils.isBlank(authentication)) { - log.warn("Can not get authentication from request, authenticationVariableName: {}", authenticationVariableName); + log.warn("Can not get {} from request", authenticationVariableName); } return authentication; } diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AuthenticationInterceptor.java b/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AuthenticationInterceptor.java index 757b740..909c382 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AuthenticationInterceptor.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AuthenticationInterceptor.java @@ -1,6 +1,7 @@ package com.schbrain.common.web.support.authentication; import cn.hutool.extra.servlet.ServletUtil; +import cn.hutool.http.ContentType; import com.schbrain.common.util.JacksonUtils; import com.schbrain.common.util.ValidateUtils; import com.schbrain.common.web.result.ResponseDTO; @@ -8,11 +9,11 @@ import com.schbrain.common.web.support.BaseHandlerInterceptor; import lombok.Data; import lombok.EqualsAndHashCode; import org.springframework.core.Ordered; -import org.springframework.http.MediaType; import org.springframework.web.method.HandlerMethod; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.nio.charset.StandardCharsets; import static com.schbrain.common.constants.ResponseActionConstants.ALERT; import static com.schbrain.common.constants.ResponseCodeConstants.LOGIN_REQUIRED; @@ -53,7 +54,7 @@ public class AuthenticationInterceptor extends BaseHandlerInterceptor implements protected void writeResult(HttpServletResponse response, ResponseDTO result) { String resultString = JacksonUtils.toJsonString(result); - ServletUtil.write(response, resultString, MediaType.APPLICATION_JSON_VALUE); + ServletUtil.write(response, resultString, ContentType.JSON.toString(StandardCharsets.UTF_8)); } protected ResponseDTO buildAccessDeniedResponse() { diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/Authenticator.java b/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/Authenticator.java index c9064c2..fe706c8 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/Authenticator.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/Authenticator.java @@ -21,4 +21,4 @@ public interface Authenticator { */ void afterCompletion(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod, Exception exception); -} \ No newline at end of file +} diff --git a/commons/web-common/src/main/java/com/schbrain/common/web/utils/HandlerMethodAnnotationUtils.java b/commons/web-common/src/main/java/com/schbrain/common/web/utils/HandlerMethodAnnotationUtils.java index f0f0780..2335f64 100644 --- a/commons/web-common/src/main/java/com/schbrain/common/web/utils/HandlerMethodAnnotationUtils.java +++ b/commons/web-common/src/main/java/com/schbrain/common/web/utils/HandlerMethodAnnotationUtils.java @@ -29,4 +29,4 @@ public class HandlerMethodAnnotationUtils { return hasAnnotation; } -} \ No newline at end of file +} diff --git a/pom.xml b/pom.xml index 27aed40..be4c208 100644 --- a/pom.xml +++ b/pom.xml @@ -109,7 +109,7 @@ 2.0.0 - 1.0.2-RELEASE + 1.0.5.1-RELEASE 2.0.40 -- GitLab