Commit 4e7ec544 authored by liaozan's avatar liaozan 🏀

Remove unused code

parent 3fca98bd
......@@ -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) {
......
......@@ -24,7 +24,6 @@ import static org.springframework.core.annotation.AnnotationUtils.getAnnotation;
public class ResponseBodyHandler implements ResponseBodyAdvice<Object> {
private final List<String> basePackages;
private final Map<Method, Boolean> methodCache = new ConcurrentHashMap<>();
public ResponseBodyHandler(List<String> basePackages) {
......
......@@ -13,14 +13,25 @@ import lombok.Data;
@Data
public class ResponseDTO<T> {
/**
* 错误码
*/
private int code;
/**
* 前端需要执行的动作
*/
private int action;
/**
* 错误信息
*/
private String message;
/**
* 返回数据
*/
private T data;
/**
* 请求ID
*/
private String requestId = TraceIdUtils.get();
public static <T> ResponseDTO<T> success() {
......
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.
* <p>
* 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);
}
}
}
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;
}
}
}
......@@ -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;
}
......
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 <T> ResponseDTO<T> buildAccessDeniedResponse() {
......
......@@ -109,7 +109,7 @@
<!-- dingtalk -->
<alibaba-dingtalk-service-sdk.version>2.0.0</alibaba-dingtalk-service-sdk.version>
<cube-sdk-java.version>1.0.2-RELEASE</cube-sdk-java.version>
<cube-sdk-java.version>1.0.5.1-RELEASE</cube-sdk-java.version>
<dingtalk.version>2.0.40</dingtalk.version>
<!-- maven settings -->
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment