From 2286f36e9fb99b4ec55d9b1ba91fb81e4315643b Mon Sep 17 00:00:00 2001 From: leebeomjun Date: Wed, 14 Jun 2023 09:48:07 +0900 Subject: [PATCH] no message --- .../support/CustomMultipartResolver.java | 90 ------------------- .../fims/framework/support/LoggerHelper.java | 25 ------ .../support/NotAllowContentTypeException.java | 34 ------- ...RestTemplateLoggingRequestInterceptor.java | 60 ------------- 4 files changed, 209 deletions(-) delete mode 100644 src/main/java/cokr/xit/fims/framework/support/CustomMultipartResolver.java delete mode 100644 src/main/java/cokr/xit/fims/framework/support/LoggerHelper.java delete mode 100644 src/main/java/cokr/xit/fims/framework/support/NotAllowContentTypeException.java delete mode 100644 src/main/java/cokr/xit/fims/framework/support/RestTemplateLoggingRequestInterceptor.java diff --git a/src/main/java/cokr/xit/fims/framework/support/CustomMultipartResolver.java b/src/main/java/cokr/xit/fims/framework/support/CustomMultipartResolver.java deleted file mode 100644 index 6c55fb08..00000000 --- a/src/main/java/cokr/xit/fims/framework/support/CustomMultipartResolver.java +++ /dev/null @@ -1,90 +0,0 @@ -package cokr.xit.fims.framework.support; - -import cokr.xit.fims.framework.support.util.Checks; -import lombok.Setter; -import org.apache.commons.fileupload.FileItem; -import org.apache.commons.fileupload.FileUpload; -import org.apache.commons.fileupload.FileUploadBase; -import org.apache.commons.fileupload.FileUploadException; -import org.apache.commons.fileupload.servlet.ServletFileUpload; -import org.apache.commons.lang3.StringUtils; -import org.springframework.web.multipart.MaxUploadSizeExceededException; -import org.springframework.web.multipart.MultipartException; -import org.springframework.web.multipart.commons.CommonsMultipartResolver; - -import javax.servlet.http.HttpServletRequest; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Objects; - -public class CustomMultipartResolver extends CommonsMultipartResolver { - - @Setter - private String allowUploadFileTypes; - - @Override - protected MultipartParsingResult parseRequest(HttpServletRequest request) throws MultipartException { - String encoding = determineEncoding(request); - FileUpload fileUpload = prepareFileUpload(encoding); - try { - List fileItems = ((ServletFileUpload) fileUpload).parseRequest(request); - - // 정해진 확장자만 사용이 가능하도록 처리 - List notAllowFileTypes = new ArrayList(); - String [] allowFileTypes = allowUploadFileTypes.split("[|]"); - - Iterator it = fileItems.iterator(); - if (it.hasNext()) { - do { - FileItem fileItem = it.next(); - String fileName = fileItem.getName(); - - if (Checks.isNotEmpty(fileName)) { - String extension = ""; - int i = fileName.lastIndexOf('.'); - if (i >= 0) { - extension = fileName.substring(i + 1); - extension = extension.toLowerCase(); - } - - boolean isAllowFile = false; - for (String ext : allowFileTypes) { - if (Objects.equals(StringUtils.EMPTY, extension) || Objects.equals(extension, ext)) { - isAllowFile = true; - break; - } - } - - if (!isAllowFile) { - notAllowFileTypes.add(extension); - } - } - } while (it.hasNext()); - } - - if (notAllowFileTypes.size() > 0) { - throw new NotAllowContentTypeException(notAllowFileTypes); - } - - return parseFileItems(fileItems, encoding); - } - catch (FileUploadBase.SizeLimitExceededException ex) { - throw new MaxUploadSizeExceededException(fileUpload.getSizeMax(), ex); - } - catch (FileUploadException ex) { - throw new MultipartException("Could not parse multipart servlet request", ex); - } - } -} - -/* - - - - - - - - - */ diff --git a/src/main/java/cokr/xit/fims/framework/support/LoggerHelper.java b/src/main/java/cokr/xit/fims/framework/support/LoggerHelper.java deleted file mode 100644 index e137e236..00000000 --- a/src/main/java/cokr/xit/fims/framework/support/LoggerHelper.java +++ /dev/null @@ -1,25 +0,0 @@ -package cokr.xit.fims.framework.support; - -//import org.apache.log4j.Logger; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class LoggerHelper { - - /** - * Returns a org.slf4j.Logger logger configured as the calling class. This ensures - * copy-paste safe code to get a logger instance, an ensures the logger is - * always fetched in a consistent manner. - * usage: - * private final static Logger log = LoggerHelper.getLogger(); - * - * Since the logger is found by accessing the call stack it is important, - * that references are static. - * @return Logger Logger - */ - public static Logger getLogger() { - final Throwable t = new Throwable(); - t.fillInStackTrace(); - return LoggerFactory.getLogger(t.getStackTrace()[1].getClassName()); - } -} diff --git a/src/main/java/cokr/xit/fims/framework/support/NotAllowContentTypeException.java b/src/main/java/cokr/xit/fims/framework/support/NotAllowContentTypeException.java deleted file mode 100644 index 97d13bb0..00000000 --- a/src/main/java/cokr/xit/fims/framework/support/NotAllowContentTypeException.java +++ /dev/null @@ -1,34 +0,0 @@ -package cokr.xit.fims.framework.support; - -import org.springframework.web.multipart.MultipartException; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -@SuppressWarnings("serial") -public class NotAllowContentTypeException extends MultipartException { - - private final List notAllowFileTypeList; - - public NotAllowContentTypeException(List notAllowFileType) { - this(notAllowFileType, null); - } - - public NotAllowContentTypeException(List notAllowFileType, Throwable cause) { - super("허용되지 않은 파일 타입"+notAllowFileType.toString()+"이 존재합니다.", cause); - notAllowFileTypeList = notAllowFileType; - } - - public List getNotAllowFileTypeList () { - List list = null; - if (this.notAllowFileTypeList != null) { - list = new ArrayList(); - Iterator it = this.notAllowFileTypeList.iterator(); - while(it.hasNext()) { - list.add(it.next()); - } - } - return list; - } -} diff --git a/src/main/java/cokr/xit/fims/framework/support/RestTemplateLoggingRequestInterceptor.java b/src/main/java/cokr/xit/fims/framework/support/RestTemplateLoggingRequestInterceptor.java deleted file mode 100644 index 0e94b891..00000000 --- a/src/main/java/cokr/xit/fims/framework/support/RestTemplateLoggingRequestInterceptor.java +++ /dev/null @@ -1,60 +0,0 @@ -package cokr.xit.fims.framework.support; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpRequest; -import org.springframework.http.client.ClientHttpRequestExecution; -import org.springframework.http.client.ClientHttpRequestInterceptor; -import org.springframework.http.client.ClientHttpResponse; -import org.springframework.util.StreamUtils; - -import java.io.IOException; -import java.nio.charset.Charset; - -/** - * Restful Logging - * 반드시 RestTemplate의 Factory 변경 필요 - * - */ -@Slf4j -public class RestTemplateLoggingRequestInterceptor implements ClientHttpRequestInterceptor { - - /** - * RestTemplate 로깅 Interceptor - * - * @param request HttpRequest - * @param body Request Body - * @param execution ClientHttpRequestExecution - * @return ClientHttpResponse - */ - @Override - public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { - logRequest(request, body); - ClientHttpResponse response = execution.execute(request, body); - logResponse(response); - return response; - } - - private void logRequest(HttpRequest request, byte[] body) throws IOException { - log.debug( - "===========================request begin================================================"); - log.debug("URI : {}", request.getURI()); - log.debug("Method : {}", request.getMethod()); - log.debug("Headers : {}", request.getHeaders()); - log.debug("Request body: {}", new String(body, Charset.defaultCharset())); - log.debug( - "==========================request end================================================"); - } - - private void logResponse(ClientHttpResponse response) throws IOException { - log.debug( - "============================response begin=========================================="); - log.debug("Status code : {}", response.getStatusCode()); - log.debug("Status text : {}", response.getStatusText()); - log.debug("Headers : {}", response.getHeaders()); - log.debug("Response body: {}", - StreamUtils.copyToString(response.getBody(), Charset.defaultCharset())); - log.debug( - "=======================response end================================================="); - } -} -