13 changed files with 50 additions and 259 deletions
@ -1,52 +0,0 @@ |
|||||
package org.mobidgim.mobidigimproject.common.api; |
|
||||
|
|
||||
import jakarta.validation.Valid; |
|
||||
import lombok.AllArgsConstructor; |
|
||||
import lombok.Data; |
|
||||
import lombok.NoArgsConstructor; |
|
||||
import org.mobidgim.mobidigimproject.common.error.ErrorCodeIfs; |
|
||||
|
|
||||
@AllArgsConstructor |
|
||||
@NoArgsConstructor |
|
||||
@Data |
|
||||
public class Api<T> { |
|
||||
|
|
||||
private Result result; |
|
||||
@Valid |
|
||||
private T body; |
|
||||
|
|
||||
public static <T> Api<T> OK(T Data){ |
|
||||
var api = new Api<T>(); |
|
||||
api.result = Result.OK(); |
|
||||
api.body = Data; |
|
||||
return api; |
|
||||
} |
|
||||
|
|
||||
public static Api<Object> ERROR(String description){ |
|
||||
var api = new Api<Object>(); |
|
||||
api.result = Result.ERROR(description); |
|
||||
return api; |
|
||||
} |
|
||||
public static Api<Object> ERROR(Result result){ |
|
||||
var api = new Api<Object>(); |
|
||||
api.result = result; |
|
||||
return api; |
|
||||
} |
|
||||
public static Api<Object> ERROR(ErrorCodeIfs errorCodeIfs){ |
|
||||
var api = new Api<Object>(); |
|
||||
api.result = Result.ERROR(errorCodeIfs); |
|
||||
return api; |
|
||||
} |
|
||||
public static Api<Object> ERROR(ErrorCodeIfs errorCodeIfs, Throwable tx){ |
|
||||
var api = new Api<Object>(); |
|
||||
api.result = Result.ERROR(errorCodeIfs,tx); |
|
||||
return api; |
|
||||
} |
|
||||
public static Api<Object> ERROR(ErrorCodeIfs errorCodeIfs, String description){ |
|
||||
var api = new Api<Object>(); |
|
||||
api.result = Result.ERROR(errorCodeIfs,description); |
|
||||
return api; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
} |
|
||||
@ -1,54 +0,0 @@ |
|||||
package org.mobidgim.mobidigimproject.common.api; |
|
||||
|
|
||||
import lombok.AllArgsConstructor; |
|
||||
import lombok.Builder; |
|
||||
import lombok.Data; |
|
||||
import lombok.NoArgsConstructor; |
|
||||
import org.mobidgim.mobidigimproject.common.error.ErrorCode; |
|
||||
import org.mobidgim.mobidigimproject.common.error.ErrorCodeIfs; |
|
||||
|
|
||||
@AllArgsConstructor |
|
||||
@NoArgsConstructor |
|
||||
@Data |
|
||||
@Builder |
|
||||
public class Result { |
|
||||
private Integer resultCode; |
|
||||
private String resultMessage; |
|
||||
private String resultDescription; |
|
||||
|
|
||||
public static Result OK(){ |
|
||||
return Result.builder() |
|
||||
.resultCode(ErrorCode.OK.getErrorCode()) |
|
||||
.resultMessage(ErrorCode.OK.getErrorDescription()) |
|
||||
.resultDescription("성공") |
|
||||
.build(); |
|
||||
} |
|
||||
public static Result ERROR(String description){ |
|
||||
return Result.builder() |
|
||||
.resultDescription(description) |
|
||||
.build(); |
|
||||
} |
|
||||
|
|
||||
public static Result ERROR(ErrorCodeIfs errorCodeIfs){ |
|
||||
return Result.builder() |
|
||||
.resultCode(errorCodeIfs.getErrorCode()) |
|
||||
.resultMessage(errorCodeIfs.getErrorDescription()) |
|
||||
.resultDescription("에러") |
|
||||
.build(); |
|
||||
} |
|
||||
public static Result ERROR(ErrorCodeIfs errorCodeIfs,Throwable tx){ |
|
||||
return Result.builder() |
|
||||
.resultCode(errorCodeIfs.getErrorCode()) |
|
||||
.resultMessage(errorCodeIfs.getErrorDescription()) |
|
||||
.resultDescription(tx.getLocalizedMessage()) |
|
||||
.build(); |
|
||||
} |
|
||||
public static Result ERROR(ErrorCodeIfs errorCodeIfs,String Description){ |
|
||||
return Result.builder() |
|
||||
.resultCode(errorCodeIfs.getErrorCode()) |
|
||||
.resultMessage(errorCodeIfs.getErrorDescription()) |
|
||||
.resultDescription(Description) |
|
||||
.build(); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
@ -1,20 +0,0 @@ |
|||||
package org.mobidgim.mobidigimproject.common.error; |
|
||||
|
|
||||
import lombok.AllArgsConstructor; |
|
||||
import lombok.Getter; |
|
||||
import org.springframework.http.HttpStatus; |
|
||||
|
|
||||
@AllArgsConstructor |
|
||||
@Getter |
|
||||
public enum ErrorCode implements ErrorCodeIfs { |
|
||||
|
|
||||
OK(200, 200, "성공"), |
|
||||
BAD_REQUEST(HttpStatus.BAD_REQUEST.value(), 400, "잘못된 요청"), |
|
||||
NULL_POINT(HttpStatus.INTERNAL_SERVER_ERROR.value(), 512, "NULL POINT"), |
|
||||
SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR.value(), 500, "서버 에러"); |
|
||||
|
|
||||
private final Integer httpStatusCode; |
|
||||
private final Integer errorCode; |
|
||||
private final String errorDescription; |
|
||||
|
|
||||
} |
|
||||
@ -1,10 +0,0 @@ |
|||||
package org.mobidgim.mobidigimproject.common.error; |
|
||||
|
|
||||
public interface ErrorCodeIfs { |
|
||||
|
|
||||
Integer getHttpStatusCode(); |
|
||||
|
|
||||
Integer getErrorCode(); |
|
||||
|
|
||||
String getErrorDescription(); |
|
||||
} |
|
||||
@ -1,18 +0,0 @@ |
|||||
package org.mobidgim.mobidigimproject.config.filterconfig; |
|
||||
|
|
||||
import org.mobidgim.mobidigimproject.filter.LoggerFilter; |
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean; |
|
||||
import org.springframework.context.annotation.Bean; |
|
||||
import org.springframework.context.annotation.Configuration; |
|
||||
|
|
||||
@Configuration |
|
||||
public class FilterConfig { |
|
||||
@Bean |
|
||||
public FilterRegistrationBean<LoggerFilter> loggerFilter() { |
|
||||
FilterRegistrationBean<LoggerFilter> registration = new FilterRegistrationBean<>(); |
|
||||
registration.setFilter(new LoggerFilter()); |
|
||||
registration.addUrlPatterns("/*"); |
|
||||
registration.setOrder(1); |
|
||||
return registration; |
|
||||
} |
|
||||
} |
|
||||
@ -1,15 +1,15 @@ |
|||||
package org.mobidgim.mobidigimproject.config.swagger; |
//package org.mobidgim.mobidigimproject.config.swagger;
|
||||
|
//
|
||||
import com.fasterxml.jackson.databind.ObjectMapper; |
//import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.swagger.v3.core.jackson.ModelResolver; |
//import io.swagger.v3.core.jackson.ModelResolver;
|
||||
import org.springframework.context.annotation.Bean; |
//import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration; |
//import org.springframework.context.annotation.Configuration;
|
||||
|
//
|
||||
@Configuration |
//@Configuration
|
||||
public class SwaggerConfig { |
//public class SwaggerConfig {
|
||||
@Bean |
// @Bean
|
||||
public ModelResolver modelResolver(ObjectMapper objectMapper) { |
// public ModelResolver modelResolver(ObjectMapper objectMapper) {
|
||||
return new ModelResolver(objectMapper); |
// return new ModelResolver(objectMapper);
|
||||
} |
// }
|
||||
} |
//}
|
||||
|
//
|
||||
|
|||||
@ -1,63 +0,0 @@ |
|||||
package org.mobidgim.mobidigimproject.filter; |
|
||||
|
|
||||
import jakarta.servlet.*; |
|
||||
import jakarta.servlet.http.HttpServletRequest; |
|
||||
import jakarta.servlet.http.HttpServletResponse; |
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.springframework.web.util.ContentCachingRequestWrapper; |
|
||||
import org.springframework.web.util.ContentCachingResponseWrapper; |
|
||||
|
|
||||
import java.io.IOException; |
|
||||
|
|
||||
@Slf4j |
|
||||
public class LoggerFilter implements Filter { |
|
||||
|
|
||||
@Override |
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { |
|
||||
|
|
||||
|
|
||||
var req = new ContentCachingRequestWrapper((HttpServletRequest) request); |
|
||||
var res = new ContentCachingResponseWrapper((HttpServletResponse) response); |
|
||||
log.info("INIT URI: {}", req.getRequestURI()); |
|
||||
chain.doFilter(req,res); |
|
||||
|
|
||||
var headersNames = req.getHeaderNames(); |
|
||||
var headersValues = new StringBuilder(); |
|
||||
|
|
||||
headersNames.asIterator().forEachRemaining(headerKey->{ |
|
||||
var headerValue = req.getHeader(headerKey); |
|
||||
|
|
||||
headersValues.append("[") |
|
||||
.append(headerKey) |
|
||||
.append(":") |
|
||||
.append(headerValue) |
|
||||
.append("]"); |
|
||||
}); |
|
||||
|
|
||||
var requestBody = new String(req.getContentAsByteArray()); |
|
||||
|
|
||||
var uri = req.getRequestURI(); |
|
||||
var method = req.getMethod(); |
|
||||
log.info(">>>> uri: {}, method: {}, header: {}, body: {}",uri,method,headersValues,requestBody); |
|
||||
|
|
||||
var responseHeadersValues = new StringBuilder(); |
|
||||
|
|
||||
res.getHeaderNames().forEach(headerKey ->{ |
|
||||
var headerValue = req.getHeader(headerKey); |
|
||||
|
|
||||
responseHeadersValues.append("[") |
|
||||
.append(headerKey) |
|
||||
.append(":") |
|
||||
.append(headerValue) |
|
||||
.append("]"); |
|
||||
}); |
|
||||
var responseBody = new String(res.getContentAsByteArray()); |
|
||||
log.info("<<<< uri: {}, method: {}, header: {}, body: {}",uri,method,responseHeadersValues,responseBody); |
|
||||
|
|
||||
res.copyBodyToResponse(); |
|
||||
|
|
||||
|
|
||||
} |
|
||||
|
|
||||
|
|
||||
} |
|
||||
Loading…
Reference in new issue