fix: instanceof 사용 fix

dev
gitea-관리자 1 year ago
parent 7c4adc2a34
commit d864e23fc9

@ -48,10 +48,9 @@ public class AuthentificationInterceptor implements AsyncHandlerInterceptor {//A
log.info("==== AuthentificationInterceptor checking ===="); log.info("==== AuthentificationInterceptor checking ====");
SecurityPolicy policy = null; SecurityPolicy policy = null;
if(handler instanceof HandlerMethod){ if(handler instanceof HandlerMethod method){
policy = SecurityPolicy.DEFAULT; policy = SecurityPolicy.DEFAULT;
HandlerMethod method = (HandlerMethod)handler;
Secured secured = method.getMethod().getAnnotation(Secured.class); Secured secured = method.getMethod().getAnnotation(Secured.class);
if(secured != null){ if(secured != null){

@ -188,7 +188,7 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(value = {RuntimeException.class}) @ExceptionHandler(value = {RuntimeException.class})
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR) @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
protected ApiResponseDTO handleRuntimeException(RuntimeException e) { protected ApiResponseDTO handleRuntimeException(RuntimeException e) {
log.error("==== throw RuntimeException ====================", e.getMessage()); log.error("==== throw RuntimeException ====================\n{}", e.getMessage());
return sendError(e); return sendError(e);
} }

@ -1,6 +1,7 @@
package kr.xit.core.spring.resolver; package kr.xit.core.spring.resolver;
import java.util.Locale; import java.util.Locale;
import java.util.Objects;
import org.springframework.web.servlet.View; import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.AbstractUrlBasedView; import org.springframework.web.servlet.view.AbstractUrlBasedView;
import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.InternalResourceViewResolver;
@ -25,9 +26,8 @@ public class HtmlViewResolver extends InternalResourceViewResolver {
protected View loadView(String viewName, Locale locale) throws Exception { protected View loadView(String viewName, Locale locale) throws Exception {
AbstractUrlBasedView view = buildView(viewName); AbstractUrlBasedView view = buildView(viewName);
View viewObj = (View) getApplicationContext().getAutowireCapableBeanFactory().initializeBean(view, viewName); View viewObj = (View) getApplicationContext().getAutowireCapableBeanFactory().initializeBean(view, viewName);
if (viewObj instanceof JstlView) { if (viewObj instanceof JstlView jv) {
JstlView jv = (JstlView) viewObj; if (!Objects.requireNonNull(jv.getBeanName()).contains(".html")) {
if (jv.getBeanName().indexOf(".html") == -1) {
return null; return null;
} }
} }

@ -2,6 +2,7 @@ package kr.xit.core.spring.resolver;
import java.util.Locale; import java.util.Locale;
import java.util.Objects;
import org.springframework.web.servlet.View; import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.AbstractUrlBasedView; import org.springframework.web.servlet.view.AbstractUrlBasedView;
import org.springframework.web.servlet.view.JstlView; import org.springframework.web.servlet.view.JstlView;
@ -26,9 +27,8 @@ public class JspViewResolver extends InternalResourceViewResolver {
protected View loadView(String viewName, Locale locale) throws Exception { protected View loadView(String viewName, Locale locale) throws Exception {
AbstractUrlBasedView view = buildView(viewName); AbstractUrlBasedView view = buildView(viewName);
View viewObj = (View) getApplicationContext().getAutowireCapableBeanFactory().initializeBean(view, viewName); View viewObj = (View) getApplicationContext().getAutowireCapableBeanFactory().initializeBean(view, viewName);
if (viewObj instanceof JstlView) { if (viewObj instanceof JstlView jv) {
JstlView jv = (JstlView) viewObj; if (!Objects.requireNonNull(jv.getBeanName()).contains(".jsp")) {
if (jv.getBeanName().indexOf(".jsp") == -1) {
return null; return null;
} }
} }

@ -27,23 +27,21 @@ import org.springframework.web.reactive.function.client.WebClientRequestExceptio
*/ */
public class ErrorParse { public class ErrorParse {
@SuppressWarnings("rawtypes")
public static ApiResponseDTO extractError(final Throwable e){ public static ApiResponseDTO extractError(final Throwable e){
String errCode = String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value()); String errCode = String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value());
String message = Checks.isNotNull(e) ? e.getLocalizedMessage() : StringUtils.EMPTY; String message = Checks.isNotNull(e) ? e.getLocalizedMessage() : StringUtils.EMPTY;
HttpStatus httpStatus = null; HttpStatus httpStatus = null;
if(e instanceof BizRuntimeException be) { if(e instanceof BizRuntimeException be) {
//BizRuntimeException be = (BizRuntimeException)e;
return ApiResponseDTO.error(be.getCode(), be.getMessage(), HttpStatus.BAD_REQUEST); return ApiResponseDTO.error(be.getCode(), be.getMessage(), HttpStatus.BAD_REQUEST);
} }
if(e instanceof ClientError) { if(e instanceof ClientError ce) {
ClientError ce = (ClientError)e;
return ApiResponseDTO.error(String.valueOf(ce.getStatus()), ce.getBody(), ce.getStatus()); return ApiResponseDTO.error(String.valueOf(ce.getStatus()), ce.getBody(), ce.getStatus());
} }
if(e instanceof ServerError) { if(e instanceof ServerError ce) {
ServerError ce = (ServerError) e;
return ApiResponseDTO.error(String.valueOf(ce.getStatus()), ce.getBody(), ce.getStatus()); return ApiResponseDTO.error(String.valueOf(ce.getStatus()), ce.getBody(), ce.getStatus());
} }

@ -43,8 +43,7 @@ public class ObjectTypeHandler extends BaseTypeHandler<Object> {
public Object getNullableResult(ResultSet rs, String columnName) throws SQLException { public Object getNullableResult(ResultSet rs, String columnName) throws SQLException {
Object object = rs.getObject(columnName); Object object = rs.getObject(columnName);
if (object instanceof Clob) { if (object instanceof Clob clob) {
Clob clob = (Clob) object;
try { try {
int size = (int) clob.length(); int size = (int) clob.length();
return clob.getSubString(1, size); return clob.getSubString(1, size);
@ -65,9 +64,8 @@ public class ObjectTypeHandler extends BaseTypeHandler<Object> {
throws SQLException { throws SQLException {
Object object = rs.getObject(columnIndex); Object object = rs.getObject(columnIndex);
if (object instanceof Clob) { if (object instanceof Clob clob) {
Clob clob = (Clob) object;
try { try {
int size = (int) clob.length(); int size = (int) clob.length();
return clob.getSubString(1, size); return clob.getSubString(1, size);

@ -195,10 +195,10 @@ public class JsonUtils {
for (Object key : json.keySet()) { for (Object key : json.keySet()) {
Object value = json.get(key); Object value = json.get(key);
if (value instanceof JSONObject) if (value instanceof JSONObject jo)
extractJsonKeyValue((JSONObject)value, keyName, valueName); extractJsonKeyValue(jo, keyName, valueName);
else if (value instanceof JSONArray) else if (value instanceof JSONArray ja)
((JSONArray)value).forEach(obj -> extractJsonKeyValue((JSONObject)obj, keyName, valueName)); ja.forEach(obj -> extractJsonKeyValue((JSONObject)obj, keyName, valueName));
else{ else{
//System.out.println(key + ", " + value); //System.out.println(key + ", " + value);
keys.add(String.valueOf(key)); keys.add(String.valueOf(key));
@ -238,10 +238,10 @@ public class JsonUtils {
for (Object key : json.keySet()) { for (Object key : json.keySet()) {
Object value = json.get(key); Object value = json.get(key);
if (value instanceof JSONObject) if (value instanceof JSONObject jo)
extractJsonKeyValue((JSONObject)value, keyName, valueName); extractJsonKeyValue(jo, keyName, valueName);
else if (value instanceof JSONArray) else if (value instanceof JSONArray ja)
((JSONArray)value).forEach(obj -> extractJsonKeyValue((JSONObject)obj, keyName, valueName)); ja.forEach(obj -> extractJsonKeyValue((JSONObject)obj, keyName, valueName));
else{ else{
//System.out.println(key + ", " + value); //System.out.println(key + ", " + value);
keys.add(String.valueOf(key)); keys.add(String.valueOf(key));

Loading…
Cancel
Save