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