Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright 2009-2018 Wudao Software Studio(wudaosoft.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.wudaosoft.commons.mvc.rest;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.ConversionNotSupportedException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.MissingPathVariableException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import com.wudaosoft.commons.mvc.ResultData;
import com.wudaosoft.commons.mvc.exception.ServiceException;
import com.wudaosoft.commons.mvc.i18n.Lang;
import com.wudaosoft.commons.mvc.i18n.LangType;
import com.wudaosoft.commons.mvc.i18n.RestErrorI18N;
/**
* @author changsoul.wu
*
*/
@ControllerAdvice
public class RestExceptionControllerAdvice extends ResponseEntityExceptionHandler {
private Class> resultClazz;
private Method codeMethod;
private Method messageMethod;
private RestErrorI18N i18nBean;
private Lang lang = new Lang();
@Autowired(required = false)
public void setI18nBean(RestErrorI18N i18nBean) {
this.i18nBean = i18nBean;
}
public void setLang(Lang lang) {
this.lang = lang;
}
/**
*
*/
public RestExceptionControllerAdvice() {
super();
}
/**
* @param resultClazz
* @param codeName
* @param messageName
* @throws NoSuchMethodException
* @throws SecurityException
*/
public RestExceptionControllerAdvice(Class> resultClazz, String codeName, String messageName)
throws SecurityException, NoSuchMethodException {
super();
Assert.notNull(resultClazz, "resultClazz must not be null");
Assert.hasText(codeName, "codeName must not be empty");
Assert.hasText(messageName, "messageName must not be empty");
this.resultClazz = resultClazz;
String codeNameSetterMethodName = "set" + com.wudaosoft.commons.utils.StringUtils.capitalize(codeName);
String messageNameSetterMethodName = "set" + com.wudaosoft.commons.utils.StringUtils.capitalize(messageName);
this.codeMethod = resultClazz.getMethod(codeNameSetterMethodName, int.class);
this.messageMethod = resultClazz.getMethod(messageNameSetterMethodName, String.class);
makeAccessible(this.codeMethod);
makeAccessible(this.messageMethod);
}
@Override
protected ResponseEntity