本文整理汇总了Java中org.springframework.beans.ConversionNotSupportedException类的典型用法代码示例。如果您正苦于以下问题:Java ConversionNotSupportedException类的具体用法?Java ConversionNotSupportedException怎么用?Java ConversionNotSupportedException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConversionNotSupportedException类属于org.springframework.beans包,在下文中一共展示了ConversionNotSupportedException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMethodArgument
import org.springframework.beans.ConversionNotSupportedException; //导入依赖的package包/类
/**
* Gets properly typed method argument.
* @param parameterType
* @param value
* @return
*/
private <T> T getMethodArgument(Class<T> parameterType, Object value) {
if (parameterType.isInstance(value)) {
return parameterType.cast(value);
}
try {
return new SimpleTypeConverter().convertIfNecessary(value, parameterType);
} catch (ConversionNotSupportedException e) {
if (String.class.equals(parameterType)) {
return (T) String.valueOf(value);
}
throw new ApplicationRuntimeException("Unable to convert method argument type", e);
}
}
示例2: ConversionNotSupportedExceptionHandler
import org.springframework.beans.ConversionNotSupportedException; //导入依赖的package包/类
/**
* 500错误
*/
@ResponseBody
@ExceptionHandler({ ConversionNotSupportedException.class })
public ResultResponse ConversionNotSupportedExceptionHandler(ConversionNotSupportedException ex) {
logger.error(ResultMessage.F5000.getMessage(), ex);
return resultResponse.failure(ResultMessage.F5000);
}
示例3: handleConversionNotSupportedException
import org.springframework.beans.ConversionNotSupportedException; //导入依赖的package包/类
@Test
public void handleConversionNotSupportedException() throws Exception {
ConversionNotSupportedException ex =
new ConversionNotSupportedException(new Object(), String.class, new Exception());
ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex);
assertNotNull("No ModelAndView returned", mav);
assertTrue("No Empty ModelAndView returned", mav.isEmpty());
assertEquals("Invalid status code", 500, response.getStatus());
// SPR-9653
assertSame(ex, request.getAttribute("javax.servlet.error.exception"));
}
示例4: setFieldValue
import org.springframework.beans.ConversionNotSupportedException; //导入依赖的package包/类
public static void setFieldValue(Field field, Object bean, Object value)
throws IllegalAccessException {
// Set it on the field
field.setAccessible(true);
// Perform type conversion if possible..
SimpleTypeConverter converter = new SimpleTypeConverter();
try {
value = converter.convertIfNecessary(value, field.getType());
}
catch (ConversionNotSupportedException e) {
// If conversion isn't supported, ignore and try and set anyway.
}
field.set(bean, value);
}
示例5: handleConversionNotSupported
import org.springframework.beans.ConversionNotSupportedException; //导入依赖的package包/类
@Override
protected ResponseEntity<Object> handleConversionNotSupported( ConversionNotSupportedException ex, HttpHeaders headers, HttpStatus status, WebRequest request )
{
headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE );
return new ResponseEntity<>( MessageUtils.jsonMessage(
Integer.toString( status.value() ), ex.getMessage() ), status );
}
示例6: handleResourceNotFound
import org.springframework.beans.ConversionNotSupportedException; //导入依赖的package包/类
@ExceptionHandler({ NoSuchRequestHandlingMethodException.class,
ConversionNotSupportedException.class })
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public String handleResourceNotFound(ModelMap model) {
model.put("advancedSearchData", new SearchData());
return "resourceNotFound";
}
示例7: handle
import org.springframework.beans.ConversionNotSupportedException; //导入依赖的package包/类
/**
* {@link ConversionNotSupportedException}をハンドリングします。
* @param e {@link ConversionNotSupportedException}
* @return {@link ErrorMessage}
* HTTPステータス 500 でレスポンスを返却します。
*/
@ExceptionHandler(ConversionNotSupportedException.class)
@ResponseBody
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@Override
public ErrorMessage handle(ConversionNotSupportedException e) {
if (L.isDebugEnabled()) {
L.debug(R.getString("D-SPRINGMVC-REST-HANDLER#0007"), e);
}
ErrorMessage error = createServerErrorMessage(HttpStatus.INTERNAL_SERVER_ERROR);
error(error, e);
return error;
}
示例8: ConversionNotSupportedException
import org.springframework.beans.ConversionNotSupportedException; //导入依赖的package包/类
@Test
public void ConversionNotSupportedExceptionをハンドリングできる() {
ConversionNotSupportedException ex = new ConversionNotSupportedException(new Object(), Class.class, new Throwable());
ErrorMessage message = this.exceptionHandlerSupport.handle(ex);
assertThat(message, notNullValue());
assertThat(message.getStatus(), is(500));
assertThat(message.getMessage(), is("予期しない例外が発生しました。"));
}
示例9: getDefaultHandlers
import org.springframework.beans.ConversionNotSupportedException; //导入依赖的package包/类
private Map<Class, RestExceptionHandler> getDefaultHandlers() {
Map<Class, RestExceptionHandler> map = new HashMap<>();
map.put( NoSuchRequestHandlingMethodException.class, new NoSuchRequestHandlingMethodExceptionHandler() );
map.put( HttpRequestMethodNotSupportedException.class, new HttpRequestMethodNotSupportedExceptionHandler() );
map.put( HttpMediaTypeNotSupportedException.class, new HttpMediaTypeNotSupportedExceptionHandler() );
map.put( MethodArgumentNotValidException.class, new MethodArgumentNotValidExceptionHandler() );
if (ClassUtils.isPresent("javax.validation.ConstraintViolationException", getClass().getClassLoader())) {
map.put( ConstraintViolationException.class, new ConstraintViolationExceptionHandler() );
}
addHandlerTo( map, HttpMediaTypeNotAcceptableException.class, NOT_ACCEPTABLE );
addHandlerTo( map, MissingServletRequestParameterException.class, BAD_REQUEST );
addHandlerTo( map, ServletRequestBindingException.class, BAD_REQUEST );
addHandlerTo( map, ConversionNotSupportedException.class, INTERNAL_SERVER_ERROR );
addHandlerTo( map, TypeMismatchException.class, BAD_REQUEST );
addHandlerTo( map, HttpMessageNotReadableException.class, UNPROCESSABLE_ENTITY );
addHandlerTo( map, HttpMessageNotWritableException.class, INTERNAL_SERVER_ERROR );
addHandlerTo( map, MissingServletRequestPartException.class, BAD_REQUEST );
addHandlerTo(map, Exception.class, INTERNAL_SERVER_ERROR);
// this class didn't exist before Spring 4.0
try {
Class clazz = Class.forName("org.springframework.web.servlet.NoHandlerFoundException");
addHandlerTo(map, clazz, NOT_FOUND);
} catch (ClassNotFoundException ex) {
// ignore
}
return map;
}
开发者ID:jirutka,项目名称:spring-rest-exception-handler,代码行数:33,代码来源:RestHandlerExceptionResolverBuilder.java
示例10: doResolveException
import org.springframework.beans.ConversionNotSupportedException; //导入依赖的package包/类
@Override
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response,
Object handler, Exception ex) {
try {
if (ex instanceof NoSuchRequestHandlingMethodException) {
return handleNoSuchRequestHandlingMethod((NoSuchRequestHandlingMethodException) ex, request, response,
handler);
}
else if (ex instanceof HttpRequestMethodNotSupportedException) {
return handleHttpRequestMethodNotSupported((HttpRequestMethodNotSupportedException) ex, request,
response, handler);
}
else if (ex instanceof HttpMediaTypeNotSupportedException) {
return handleHttpMediaTypeNotSupported((HttpMediaTypeNotSupportedException) ex, request, response,
handler);
}
else if (ex instanceof HttpMediaTypeNotAcceptableException) {
return handleHttpMediaTypeNotAcceptable((HttpMediaTypeNotAcceptableException) ex, request, response,
handler);
}
else if (ex instanceof MissingPathVariableException) {
return handleMissingPathVariable((MissingPathVariableException) ex, request,
response, handler);
}
else if (ex instanceof MissingServletRequestParameterException) {
return handleMissingServletRequestParameter((MissingServletRequestParameterException) ex, request,
response, handler);
}
else if (ex instanceof ServletRequestBindingException) {
return handleServletRequestBindingException((ServletRequestBindingException) ex, request, response,
handler);
}
else if (ex instanceof ConversionNotSupportedException) {
return handleConversionNotSupported((ConversionNotSupportedException) ex, request, response, handler);
}
else if (ex instanceof TypeMismatchException) {
return handleTypeMismatch((TypeMismatchException) ex, request, response, handler);
}
else if (ex instanceof HttpMessageNotReadableException) {
return handleHttpMessageNotReadable((HttpMessageNotReadableException) ex, request, response, handler);
}
else if (ex instanceof HttpMessageNotWritableException) {
return handleHttpMessageNotWritable((HttpMessageNotWritableException) ex, request, response, handler);
}
else if (ex instanceof MethodArgumentNotValidException) {
return handleMethodArgumentNotValidException((MethodArgumentNotValidException) ex, request, response,
handler);
}
else if (ex instanceof MissingServletRequestPartException) {
return handleMissingServletRequestPartException((MissingServletRequestPartException) ex, request,
response, handler);
}
else if (ex instanceof BindException) {
return handleBindException((BindException) ex, request, response, handler);
}
else if (ex instanceof NoHandlerFoundException) {
return handleNoHandlerFoundException((NoHandlerFoundException) ex, request, response, handler);
}
}
catch (Exception handlerException) {
if (logger.isWarnEnabled()) {
logger.warn("Handling of [" + ex.getClass().getName() + "] resulted in Exception", handlerException);
}
}
return null;
}
示例11: conversionNotSupported
import org.springframework.beans.ConversionNotSupportedException; //导入依赖的package包/类
@Test
public void conversionNotSupported() {
Exception ex = new ConversionNotSupportedException(new Object(), Object.class, null);
testException(ex);
}
示例12: handleException
import org.springframework.beans.ConversionNotSupportedException; //导入依赖的package包/类
@ExceptionHandler({NoSuchRequestHandlingMethodException.class,
HttpRequestMethodNotSupportedException.class,
HttpMediaTypeNotSupportedException.class,
HttpMediaTypeNotAcceptableException.class,
MissingServletRequestParameterException.class,
ServletRequestBindingException.class,
ConversionNotSupportedException.class,
TypeMismatchException.class,
HttpMessageNotReadableException.class,
HttpMessageNotWritableException.class,
MethodArgumentNotValidException.class,
MissingServletRequestPartException.class,
BindException.class,
NoHandlerFoundException.class})
public final ResponseEntity<Object> handleException(Exception ex, HttpServletRequest request) {
HttpHeaders headers = new HttpHeaders();
HttpStatus status;
if(ex instanceof NoSuchRequestHandlingMethodException) {
status = HttpStatus.NOT_FOUND;
return handleNoSuchRequestHandlingMethod((NoSuchRequestHandlingMethodException)ex, headers, status, request);
} else if(ex instanceof HttpRequestMethodNotSupportedException) {
status = HttpStatus.METHOD_NOT_ALLOWED;
return handleHttpRequestMethodNotSupported((HttpRequestMethodNotSupportedException)ex, headers, status, request);
} else if(ex instanceof HttpMediaTypeNotSupportedException) {
status = HttpStatus.UNSUPPORTED_MEDIA_TYPE;
return handleHttpMediaTypeNotSupported((HttpMediaTypeNotSupportedException)ex, headers, status, request);
} else if(ex instanceof HttpMediaTypeNotAcceptableException) {
status = HttpStatus.NOT_ACCEPTABLE;
return handleHttpMediaTypeNotAcceptable((HttpMediaTypeNotAcceptableException)ex, headers, status, request);
} else if(ex instanceof MissingServletRequestParameterException) {
status = HttpStatus.BAD_REQUEST;
return handleMissingServletRequestParameter((MissingServletRequestParameterException)ex, headers, status, request);
} else if(ex instanceof ServletRequestBindingException) {
status = HttpStatus.BAD_REQUEST;
return handleServletRequestBindingException((ServletRequestBindingException)ex, headers, status, request);
} else if(ex instanceof ConversionNotSupportedException) {
status = HttpStatus.INTERNAL_SERVER_ERROR;
return handleConversionNotSupported((ConversionNotSupportedException)ex, headers, status, request);
} else if(ex instanceof TypeMismatchException) {
status = HttpStatus.BAD_REQUEST;
return handleTypeMismatch((TypeMismatchException)ex, headers, status, request);
} else if(ex instanceof HttpMessageNotReadableException) {
status = HttpStatus.BAD_REQUEST;
return handleHttpMessageNotReadable((HttpMessageNotReadableException)ex, headers, status, request);
} else if(ex instanceof HttpMessageNotWritableException) {
status = HttpStatus.INTERNAL_SERVER_ERROR;
return handleHttpMessageNotWritable((HttpMessageNotWritableException)ex, headers, status, request);
} else if(ex instanceof MethodArgumentNotValidException) {
status = HttpStatus.BAD_REQUEST;
return handleMethodArgumentNotValid((MethodArgumentNotValidException)ex, headers, status, request);
} else if(ex instanceof MissingServletRequestPartException) {
status = HttpStatus.BAD_REQUEST;
return handleMissingServletRequestPart((MissingServletRequestPartException)ex, headers, status, request);
} else if(ex instanceof BindException) {
status = HttpStatus.BAD_REQUEST;
return handleBindingResult(((BindException) ex).getBindingResult(), (BindException)ex, null, headers, status, request);
} else if(ex instanceof NoHandlerFoundException) {
status = HttpStatus.NOT_FOUND;
return handleNoHandlerFoundException((NoHandlerFoundException)ex, headers, status, request);
} else {
logger.warn("Unknown exception type: " + ex.getClass().getName());
status = HttpStatus.INTERNAL_SERVER_ERROR;
return handleExceptionInternal(ex, (Object)null, headers, status, request);
}
}
示例13: handleConversionNotSupported
import org.springframework.beans.ConversionNotSupportedException; //导入依赖的package包/类
protected ResponseEntity<Object> handleConversionNotSupported(ConversionNotSupportedException ex, HttpHeaders headers, HttpStatus status, HttpServletRequest request) {
return handleExceptionInternal(ex, (Object) null, headers, status, request);
}
示例14: testCopyList
import org.springframework.beans.ConversionNotSupportedException; //导入依赖的package包/类
@Test
public void testCopyList(){
Date now = new Date();
Date createTime = new Date(now.getTime()+3600000);
String userName = "testName";
long id = 111333L;
CapitalBean srcBean = new CapitalBean();
srcBean.setId(id);
srcBean.setUserName(userName);
srcBean.setBirthday(now);
srcBean.setCreateTime(createTime);
long dataId = 2342332;
String subName = "subNameTest";
CapitalBean2 srcData = new CapitalBean2();
srcData.setId(dataId);
srcData.setSubName(subName);
srcData.setCreateTime(createTime);
List<CapitalBean2> datas = new ArrayList<CopyUtilsTest.CapitalBean2>();
datas.add(srcData);
srcBean.setDatas(datas);
try {
UnderlineBeanWithoutCloneable underlineBeanWithoutCloneable = CopyUtils.copy(UnderlineBeanWithoutCloneable.class, srcBean);
Assert.fail("it should be faield");
} catch (Exception e) {
Assert.assertTrue(ConversionNotSupportedException.class.isInstance(e));
}
UnderlineBean target = CopyUtils.copy(UnderlineBean.class, srcBean);
Assert.assertEquals(userName, target.getUser_name());
Assert.assertEquals(id, target.getId());
Assert.assertEquals(createTime, target.getCreate_time());
Assert.assertEquals(now, target.getBirthday());
Assert.assertEquals(srcBean.getId(), target.getId());
Assert.assertEquals(srcBean.getUserName(), target.getUser_name());
Assert.assertEquals(srcBean.getBirthday(), target.getBirthday());
Assert.assertEquals(srcBean.getCreateTime(), target.getCreate_time());
Assert.assertNotNull(target.getDatas());
Assert.assertEquals(1, target.getDatas().size());
UnderlineBean2 targetData = target.getDatas().get(0);
Assert.assertEquals(dataId, targetData.getId());
Assert.assertEquals(subName, targetData.getSub_name());
Assert.assertEquals(createTime, targetData.getCreate_time());
srcBean = CopyUtils.copy(new CapitalBean(), target);
Assert.assertEquals(userName, srcBean.getUserName());
Assert.assertEquals(id, srcBean.getId());
Assert.assertEquals(createTime, srcBean.getCreateTime());
Assert.assertEquals(now, srcBean.getBirthday());
Assert.assertEquals(srcBean.getId(), target.getId());
Assert.assertEquals(srcBean.getUserName(), target.getUser_name());
Assert.assertEquals(srcBean.getBirthday(), target.getBirthday());
Assert.assertEquals(srcBean.getCreateTime(), target.getCreate_time());
}
示例15: handleConversionNotSupported
import org.springframework.beans.ConversionNotSupportedException; //导入依赖的package包/类
@Override
protected ModelAndView handleConversionNotSupported(ConversionNotSupportedException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
super.handleConversionNotSupported(ex, request, response, handler);
return contentNegotiatingModelAndView(createErrorResponse(request, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex));
}