Bladeren bron

[ST24PRJ-542] gagaframework AJAX 호출여부 체크 추가

card007 4 jaren geleden
bovenliggende
commit
c276be0487
1 gewijzigde bestanden met toevoegingen van 23 en 4 verwijderingen
  1. 23 4
      src/main/java/com/style24/core/support/controller/TscBaseController.java

+ 23 - 4
src/main/java/com/style24/core/support/controller/TscBaseController.java

@@ -5,6 +5,8 @@ import java.sql.SQLException;
 import java.sql.SQLRecoverableException;
 import java.util.Set;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.ConstraintViolation;
 import javax.validation.Validation;
 import javax.validation.Validator;
@@ -22,17 +24,18 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.InitBinder;
 import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
 
 import com.fasterxml.jackson.databind.JsonMappingException;
+import com.gagaframework.web.rest.exception.GagaRestException;
+import com.gagaframework.web.rest.server.GagaResponse;
+import com.gagaframework.web.rest.server.GagaResponseStatus;
 import com.style24.core.biz.thirdparty.KollusApi;
 import com.style24.core.support.message.TscMessageByLocale;
 
 import lombok.extern.slf4j.Slf4j;
 
-import com.gagaframework.web.rest.exception.GagaRestException;
-import com.gagaframework.web.rest.server.GagaResponse;
-import com.gagaframework.web.rest.server.GagaResponseStatus;
-
 /**
  * Controller Advice
  * 
@@ -129,6 +132,22 @@ public class TscBaseController {
 			throwable = rootCause;
 		}
 
+		// Ajax 호출인지 여부를 체크. 2021.11.16. gagamel
+		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
+		String reqWith = request.getHeader("x-requested-with");
+
+		if (StringUtils.isBlank(reqWith) || !"XMLHttpRequest".equals(reqWith)) {
+			HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
+
+			try {
+				// 에러 페이지로 forwarding
+				request.getRequestDispatcher("/error").forward(request, response);
+			} catch (Exception e) {
+				// Do nothing
+			}
+		}
+		// Ajax 호출인지 여부를 체크. 2021.11.16. gagamel
+
 		if (throwable instanceof SQLException || throwable instanceof BindingException
 			|| throwable instanceof JsonMappingException
 			|| throwable instanceof UndeclaredThrowableException) {