no message

main
이범준 1 year ago
parent f9c8c01406
commit 2286f36e9f

@ -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<FileItem> fileItems = ((ServletFileUpload) fileUpload).parseRequest(request);
// 정해진 확장자만 사용이 가능하도록 처리
List<String> notAllowFileTypes = new ArrayList<String>();
String [] allowFileTypes = allowUploadFileTypes.split("[|]");
Iterator<FileItem> 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);
}
}
}
/*
<!-- File Upload -->
<bean id="multipartResolver" class="com.nbkorea.bo.common.resolver.CustomMultipartResolver">
<property name="defaultEncoding" value="UTF-8" />
<property name="maxUploadSizePerFile" value="10485760" />
<property name="allowUploadFileTypes" value="jpeg|jpg|png|gif|tif|tiff|jfif|bmp|txt|hwp|doc|docx|ppt|pptx|xls|xlsx|psd|pdf|ods|zip|rar|tar|7z|tbz|tgz|lzh|gz" />
</bean>
*/

@ -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());
}
}

@ -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 <String> notAllowFileTypeList;
public NotAllowContentTypeException(List <String> notAllowFileType) {
this(notAllowFileType, null);
}
public NotAllowContentTypeException(List <String> notAllowFileType, Throwable cause) {
super("허용되지 않은 파일 타입"+notAllowFileType.toString()+"이 존재합니다.", cause);
notAllowFileTypeList = notAllowFileType;
}
public List<String> getNotAllowFileTypeList () {
List<String> list = null;
if (this.notAllowFileTypeList != null) {
list = new ArrayList<String>();
Iterator <String> it = this.notAllowFileTypeList.iterator();
while(it.hasNext()) {
list.add(it.next());
}
}
return list;
}
}

@ -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=================================================");
}
}
Loading…
Cancel
Save