View와 ViewResolver에 대한 재설계 반영 및 예외처리 로직 추가
This commit is contained in:
@@ -5,16 +5,22 @@ import org.springframework.web.bind.annotation.ControllerAdvice;
|
|||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
|
import com.terry.xplatform.config.xplatform.web.XplatformView;
|
||||||
|
|
||||||
@ControllerAdvice
|
@ControllerAdvice
|
||||||
public class GlobalExceptionHandler {
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
@ExceptionHandler(value={DataAccessException.class})
|
@ExceptionHandler(value={DataAccessException.class})
|
||||||
public ModelAndView processDataAccessException(DataAccessException ex){
|
public XplatformView processDataAccessException(DataAccessException ex){
|
||||||
|
/*
|
||||||
ModelAndView modelAndView = new ModelAndView();
|
ModelAndView modelAndView = new ModelAndView();
|
||||||
modelAndView.addObject("ErrorCode", "-1");
|
modelAndView.addObject("ErrorCode", "-1");
|
||||||
modelAndView.addObject("ErrorMsg", ex.getMessage());
|
modelAndView.addObject("ErrorMsg", ex.getMessage());
|
||||||
modelAndView.setViewName("errorView");
|
modelAndView.setViewName("errorView");
|
||||||
return modelAndView;
|
return modelAndView;
|
||||||
|
*/
|
||||||
|
XplatformView xplatformView = new XplatformView("30", ex.getMessage());
|
||||||
|
return xplatformView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(value={Exception.class})
|
@ExceptionHandler(value={Exception.class})
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ package com.terry.xplatform.config.xplatform;
|
|||||||
|
|
||||||
import com.tobesoft.xplatform.tx.PlatformType;
|
import com.tobesoft.xplatform.tx.PlatformType;
|
||||||
|
|
||||||
public class XplatformConstants implements PlatformType {
|
public interface XplatformConstants extends PlatformType {
|
||||||
public static final String CONTENT_TYPE_CSV = "csv";
|
public static final String CONTENT_TYPE_CSV = "csv";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,9 @@ import java.util.Map.Entry;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import org.springframework.validation.BeanPropertyBindingResult;
|
import org.springframework.validation.BeanPropertyBindingResult;
|
||||||
|
import org.springframework.web.servlet.View;
|
||||||
import org.springframework.web.servlet.support.RequestContext;
|
import org.springframework.web.servlet.support.RequestContext;
|
||||||
import org.springframework.web.servlet.view.AbstractTemplateView;
|
|
||||||
|
|
||||||
import com.terry.xplatform.config.utils.XplatformReflectionUtils;
|
import com.terry.xplatform.config.utils.XplatformReflectionUtils;
|
||||||
import com.terry.xplatform.config.xplatform.XplatformConstants;
|
import com.terry.xplatform.config.xplatform.XplatformConstants;
|
||||||
@@ -27,7 +26,7 @@ import com.tobesoft.xplatform.data.VariableList;
|
|||||||
import com.tobesoft.xplatform.data.datatype.PlatformDataType;
|
import com.tobesoft.xplatform.data.datatype.PlatformDataType;
|
||||||
import com.tobesoft.xplatform.tx.HttpPlatformResponse;
|
import com.tobesoft.xplatform.tx.HttpPlatformResponse;
|
||||||
|
|
||||||
public class XplatformView extends AbstractTemplateView {
|
public class XplatformView implements View {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Xplatform의 작업결과가 성공적이었을때의 ErrorCode 값을 설정한다
|
* Xplatform의 작업결과가 성공적이었을때의 ErrorCode 값을 설정한다
|
||||||
@@ -49,65 +48,75 @@ public class XplatformView extends AbstractTemplateView {
|
|||||||
this.ERROR_MSG_VALUE = errorMsgValue;
|
this.ERROR_MSG_VALUE = errorMsgValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderMergedTemplateModel(Map<String, Object> model, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
|
public String getContentType() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
String contentType = StringUtils.hasText((String)model.get("contentType")) ? (String)model.get("contentType") : XplatformConstants.CONTENT_TYPE_XML;
|
return null;
|
||||||
model.remove("contentType");
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
String contentType = request.getHeader("Content-Type").startsWith("text/xml;") ? XplatformConstants.CONTENT_TYPE_XML
|
||||||
|
: request.getHeader("Content-Type");
|
||||||
|
|
||||||
if(contentType == XplatformConstants.CONTENT_TYPE_XML) {
|
if(contentType == XplatformConstants.CONTENT_TYPE_XML) {
|
||||||
VariableList variableList = new VariableList();
|
VariableList variableList = new VariableList();
|
||||||
DataSetList dataSetList = new DataSetList();
|
DataSetList dataSetList = new DataSetList();
|
||||||
HttpPlatformResponse httpPlatformResponse = new HttpPlatformResponse(httpServletResponse, XplatformConstants.CONTENT_TYPE_XML);
|
HttpPlatformResponse httpPlatformResponse = new HttpPlatformResponse(response, XplatformConstants.CONTENT_TYPE_XML);
|
||||||
|
|
||||||
for(Entry<String, Object> entry : model.entrySet()) {
|
if(model != null) {
|
||||||
String key = entry.getKey();
|
|
||||||
Object object = entry.getValue();
|
|
||||||
if(object instanceof Collection) {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
DataSet dataSet = makeDataSet(key, (Collection<Object>)object);
|
|
||||||
dataSetList.add(dataSet);
|
|
||||||
} else {
|
|
||||||
Variable variable = null;
|
|
||||||
if(object instanceof Integer) {
|
|
||||||
variable = new Variable(key, PlatformDataType.INT, (Integer)object);
|
|
||||||
} else if(object instanceof Long) {
|
|
||||||
variable = new Variable(key, PlatformDataType.LONG, (Long)object);
|
|
||||||
} else if(object instanceof Float) {
|
|
||||||
variable = new Variable(key, PlatformDataType.FLOAT, (Float)object);
|
|
||||||
} else if(object instanceof Double) {
|
|
||||||
variable = new Variable(key, PlatformDataType.DOUBLE, (Double)object);
|
|
||||||
} else if(object instanceof Date) {
|
|
||||||
variable = new Variable(key, PlatformDataType.DATE, (Date)object);
|
|
||||||
} else if(object instanceof String){
|
|
||||||
variable = new Variable(key, PlatformDataType.STRING, (String)object);
|
|
||||||
} else if(object instanceof Variable) {
|
|
||||||
variable = (Variable)object;
|
|
||||||
} else {
|
|
||||||
// model에 들어있는 클래스 객체중에 DataSet으로 변환할 수 없는 클래스 객체가 들어있는것은 bypass 하게끔 한다
|
|
||||||
|
|
||||||
if(skipDataSet(object)) {
|
for(Entry<String, ?> entry : model.entrySet()) {
|
||||||
continue;
|
String key = entry.getKey();
|
||||||
}
|
Object object = entry.getValue();
|
||||||
|
if(object instanceof Collection) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
DataSet dataSet = makeDataSet(key, (Collection<Object>)object);
|
||||||
|
dataSetList.add(dataSet);
|
||||||
|
} else {
|
||||||
|
Variable variable = null;
|
||||||
|
if(object instanceof Integer) {
|
||||||
|
variable = new Variable(key, PlatformDataType.INT, (Integer)object);
|
||||||
|
} else if(object instanceof Long) {
|
||||||
|
variable = new Variable(key, PlatformDataType.LONG, (Long)object);
|
||||||
|
} else if(object instanceof Float) {
|
||||||
|
variable = new Variable(key, PlatformDataType.FLOAT, (Float)object);
|
||||||
|
} else if(object instanceof Double) {
|
||||||
|
variable = new Variable(key, PlatformDataType.DOUBLE, (Double)object);
|
||||||
|
} else if(object instanceof Date) {
|
||||||
|
variable = new Variable(key, PlatformDataType.DATE, (Date)object);
|
||||||
|
} else if(object instanceof String){
|
||||||
|
variable = new Variable(key, PlatformDataType.STRING, (String)object);
|
||||||
|
} else if(object instanceof Variable) {
|
||||||
|
variable = (Variable)object;
|
||||||
|
} else {
|
||||||
|
// model에 들어있는 클래스 객체중에 DataSet으로 변환할 수 없는 클래스 객체가 들어있는것은 bypass 하게끔 한다
|
||||||
|
|
||||||
// 객체의 멤버변수들 값을 읽어서 한 행짜리 데이터셋으로 return 하는 방법을 고민해보자
|
if(skipDataSet(object)) {
|
||||||
DataSet dataSet = makeDataSet(key, object);
|
continue;
|
||||||
dataSetList.add(dataSet);
|
}
|
||||||
}
|
|
||||||
if(variable != null) {
|
|
||||||
variableList.add(variable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// XplatformView를 만든다는 것은 그 이전단계까지는 예외없이 진행되었다는 뜻이기 때문에 Xplatform에서 읽어들일변수인 ErrorCode 와 ErrorMsg 변수에 작업이 성공했다는 내용을 설정한다
|
// 객체의 멤버변수들 값을 읽어서 한 행짜리 데이터셋으로 return 하는 방법을 고민해보자
|
||||||
// Controller에서 ErrorCode와 ErrorMsg를 설정한 것이 없으면 XplatformView에서 설정하도록 한다
|
DataSet dataSet = makeDataSet(key, object);
|
||||||
if(!model.containsKey("ErrorCode")) {
|
dataSetList.add(dataSet);
|
||||||
variableList.add("ErrorCode", ERROR_CODE_VALUE);
|
}
|
||||||
}
|
if(variable != null) {
|
||||||
|
variableList.add(variable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!model.containsKey("ErrorMsg")) {
|
// XplatformView를 만든다는 것은 그 이전단계까지는 예외없이 진행되었다는 뜻이기 때문에 Xplatform에서 읽어들일변수인 ErrorCode 와 ErrorMsg 변수에 작업이 성공했다는 내용을 설정한다
|
||||||
variableList.add("ErrorMsg", ERROR_MSG_VALUE);
|
// Controller에서 ErrorCode와 ErrorMsg를 설정한 것이 없으면 XplatformView에서 설정하도록 한다
|
||||||
|
if(!model.containsKey("ErrorCode")) {
|
||||||
|
variableList.add("ErrorCode", ERROR_CODE_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!model.containsKey("ErrorMsg")) {
|
||||||
|
variableList.add("ErrorMsg", ERROR_MSG_VALUE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PlatformData platformData = new PlatformData();
|
PlatformData platformData = new PlatformData();
|
||||||
@@ -119,11 +128,9 @@ public class XplatformView extends AbstractTemplateView {
|
|||||||
} else if(contentType == XplatformConstants.CONTENT_TYPE_CSV) {
|
} else if(contentType == XplatformConstants.CONTENT_TYPE_CSV) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Collection 객체와 DataSet 이름을 파라미터로 받아 해당 객체가 들어있는 DataSet을 return 한다
|
* Collection 객체와 DataSet 이름을 파라미터로 받아 해당 객체가 들어있는 DataSet을 return 한다
|
||||||
* @param dataSetName
|
* @param dataSetName
|
||||||
* @param collection
|
* @param collection
|
||||||
@@ -313,5 +320,4 @@ public class XplatformView extends AbstractTemplateView {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,30 @@
|
|||||||
package com.terry.xplatform.config.xplatform.web;
|
package com.terry.xplatform.config.xplatform.web;
|
||||||
|
|
||||||
import org.springframework.web.servlet.view.AbstractTemplateViewResolver;
|
import java.util.Locale;
|
||||||
import org.springframework.web.servlet.view.AbstractUrlBasedView;
|
|
||||||
|
|
||||||
public class XplatformViewResolver extends AbstractTemplateViewResolver {
|
import org.springframework.core.Ordered;
|
||||||
|
import org.springframework.web.servlet.View;
|
||||||
|
import org.springframework.web.servlet.ViewResolver;
|
||||||
|
|
||||||
@Override
|
public class XplatformViewResolver implements ViewResolver, Ordered {
|
||||||
protected Class getViewClass() {
|
|
||||||
|
private int order = Ordered.LOWEST_PRECEDENCE;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View resolveViewName(String viewName, Locale locale) throws Exception {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return XplatformView.class;
|
XplatformView xplatformView = new XplatformView();
|
||||||
}
|
return xplatformView;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
|
public int getOrder() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
XplatformView view = (XplatformView)super.buildView(viewName);
|
return order;
|
||||||
return view;
|
}
|
||||||
}
|
|
||||||
|
public void setOrder(int order) {
|
||||||
|
this.order = order;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ public class SampleServiceImpl implements SampleService {
|
|||||||
@Override
|
@Override
|
||||||
public List<SampleVO> list(SampleDefaultVO sampleDefaultVO) throws DataAccessException {
|
public List<SampleVO> list(SampleDefaultVO sampleDefaultVO) throws DataAccessException {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
// throw new DataAccessException("Test DataAccessException Message") {};
|
||||||
List<SampleVO> result = sampleDAO.selectSampleList(sampleDefaultVO);
|
List<SampleVO> result = sampleDAO.selectSampleList(sampleDefaultVO);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class SampleController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
SampleService sampleService;
|
SampleService sampleService;
|
||||||
|
|
||||||
@RequestMapping("/egovSampleSelect")
|
@RequestMapping("egovSampleSelect")
|
||||||
public void list(Model model
|
public void list(Model model
|
||||||
, SampleVO sampleVO
|
, SampleVO sampleVO
|
||||||
, @RequestVariable SampleVO requestVariableSampleVO
|
, @RequestVariable SampleVO requestVariableSampleVO
|
||||||
|
|||||||
Reference in New Issue
Block a user