本文整理汇总了Java中org.springframework.web.servlet.NoHandlerFoundException类的典型用法代码示例。如果您正苦于以下问题:Java NoHandlerFoundException类的具体用法?Java NoHandlerFoundException怎么用?Java NoHandlerFoundException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NoHandlerFoundException类属于org.springframework.web.servlet包,在下文中一共展示了NoHandlerFoundException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleNoHandlerFoundException
import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@ExceptionHandler(NoHandlerFoundException.class)
public @ResponseBody ErrorWrapper handleNoHandlerFoundException(HttpServletRequest request, HttpServletResponse response, Exception ex){
ErrorWrapper errorWrapper = (ErrorWrapper) context.getBean(ErrorWrapper.class.getName());
Locale locale = null;
BroadleafRequestContext requestContext = BroadleafRequestContext.getBroadleafRequestContext();
if (requestContext != null) {
locale = requestContext.getJavaLocale();
}
LOG.error("An error occured invoking a REST service", ex);
if (locale == null) {
locale = Locale.getDefault();
}
errorWrapper.setHttpStatusCode(HttpStatus.SC_NOT_FOUND);
response.setStatus(resolveResponseStatusCode(ex, errorWrapper));
ErrorMessageWrapper errorMessageWrapper = (ErrorMessageWrapper) context.getBean(ErrorMessageWrapper.class.getName());
errorMessageWrapper.setMessageKey(resolveClientMessageKey(BroadleafWebServicesException.NOT_FOUND));
errorMessageWrapper.setMessage(messageSource.getMessage(BroadleafWebServicesException.NOT_FOUND, null,
BroadleafWebServicesException.NOT_FOUND, locale));
errorWrapper.getMessages().add(errorMessageWrapper);
return errorWrapper;
}
示例2: handleUnmapped
import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@ExceptionHandler(NoHandlerFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public ModelAndView handleUnmapped(HttpServletRequest req) {
ModelAndView mav = new ModelAndView();
mav.addObject("page", new Page("mzTabValidator", versionNumber, gaId));
mav.addObject("error", "Resource not found!");
mav.addObject("url", req.getRequestURL());
mav.addObject("timestamp", new Date().toString());
mav.addObject("status", 404);
mav.setViewName("error");
return mav;
}
示例3: requestHandlingNoHandlerFound
import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@ExceptionHandler(NoHandlerFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public Map<String,String> requestHandlingNoHandlerFound() {
Map message = new HashMap();
message.put("error","router is not exists");
return message;
}
示例4: configureHandlerExceptionResolvers
import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@Override
public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
exceptionResolvers.add(new HandlerExceptionResolver() {
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) {
Result result = new Result();
logger.warn(e.getMessage());
if (e instanceof ServiceException) {//业务失败的异常,如“账号或密码错误”
result.setCode(ResultCode.FAIL).setMessage(e.getMessage());
} else if (e instanceof IllegalArgumentException) { //参数检查异常
result.setCode(ResultCode.FAIL).setMessage(e.getMessage());
}else if (e instanceof NoHandlerFoundException) {
result.setCode(ResultCode.NOT_FOUND).setMessage("接口 [" + request.getRequestURI() + "] 不存在");
} else if (e instanceof ServletException) {
result.setCode(ResultCode.FAIL).setMessage(e.getMessage());
} else if (e instanceof AccessDeniedException){
result.setCode(ResultCode.PERMIT).setMessage(e.getMessage());
} else {
result.setCode(ResultCode.INTERNAL_SERVER_ERROR).setMessage("接口 [" + request.getRequestURI() + "] 内部错误,请联系管理员");
String message;
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
message = String.format("接口 [%s] 出现异常,方法:%s.%s,异常摘要:%s",
request.getRequestURI(),
handlerMethod.getBean().getClass().getName(),
handlerMethod.getMethod().getName(),
e.getMessage());
} else {
message = e.getMessage();
}
logger.error(message, e);
}
responseResult(response, result);
return new ModelAndView();
}
});
}
示例5: configureHandlerExceptionResolvers
import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@Override
public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
exceptionResolvers.add(new HandlerExceptionResolver() {
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) {
Result result = new Result();
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
if (e instanceof ServiceException) {//业务失败的异常,如“账号或密码错误”
result.setCode(ResultCode.FAIL).setMessage(e.getMessage());
logger.info(e.getMessage());
} else {
result.setCode(ResultCode.INTERNAL_SERVER_ERROR).setMessage("接口 [" + request.getRequestURI() + "] 内部错误,请联系管理员");
String message = String.format("接口 [%s] 出现异常,方法:%s.%s,异常摘要:%s",
request.getRequestURI(),
handlerMethod.getBean().getClass().getName(),
handlerMethod.getMethod().getName(),
e.getMessage());
logger.error(message, e);
}
} else {
if (e instanceof NoHandlerFoundException) {
result.setCode(ResultCode.NOT_FOUND).setMessage("接口 [" + request.getRequestURI() + "] 不存在");
} else {
result.setCode(ResultCode.INTERNAL_SERVER_ERROR).setMessage(e.getMessage());
logger.error(e.getMessage(), e);
}
}
responseResult(response, result);
return new ModelAndView();
}
});
}
示例6: handleNoHandlerFoundException
import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@Override
protected ResponseEntity<Object> handleNoHandlerFoundException(final NoHandlerFoundException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
logger.info(ex.getClass().getName());
//
final String error = "No handler found for " + ex.getHttpMethod() + " " + ex.getRequestURL();
final ApiError apiError = new ApiError(HttpStatus.NOT_FOUND, ex.getLocalizedMessage(), error);
return new ResponseEntity<Object>(apiError, new HttpHeaders(), apiError.getStatus());
}
示例7: handleError404
import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
/**
* Exception Controller.
* Catches various exceptions thrown throughout the application runtime.
*
* @author Ant Kaynak - Github/Exercon
*/
@ExceptionHandler(NoHandlerFoundException.class)
public String handleError404(Exception e , RedirectAttributes attr) {
attr.addFlashAttribute("error","Requested page does not exist!");
return "redirect:/error";
}
示例8: handleError404
import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
/**
* Exception Controller.
* Catches various exceptions thrown throughout the application runtime.
*
* @author Ant Kaynak - Github/Exercon
*/
@ExceptionHandler(NoHandlerFoundException.class)
public String handleError404(Exception e , RedirectAttributes attr) {
e.printStackTrace();
attr.addFlashAttribute("error","Requested page does not exist!");
return "redirect:/oups";
}
示例9: handleNoHandlerFoundException
import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@ResponseStatus(code = HttpStatus.NOT_FOUND)
@ExceptionHandler(NoHandlerFoundException.class)
public ErrorDto handleNoHandlerFoundException(NoHandlerFoundException ex) {
return ErrorDto.builder()
.errorCode(ErrorCodes.NOT_FOUND)
.message(ex.getLocalizedMessage())
.build();
}
示例10: handleNoHandlerFoundException
import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@Override
protected ResponseEntity<Object> handleNoHandlerFoundException(final NoHandlerFoundException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
logger.info(ex.getClass().getName());
//
final String error = "No handler found for " + ex.getHttpMethod() + " " + ex.getRequestURL();
final AitException AitException = new AitException(HttpStatus.NOT_FOUND, ex.getLocalizedMessage(), error);
return handleExceptionInternal(ex, AitException, headers, AitException.getStatus(), request);
}
示例11: defaultNotFoundHandler
import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@ExceptionHandler(value = NoHandlerFoundException.class)
public ModelAndView defaultNotFoundHandler(HttpServletRequest req, Exception e) throws Exception {
e.printStackTrace();
ModelAndView mav = new ModelAndView();
mav.addObject("exception", e);
mav.addObject("url", req.getRequestURL());
mav.setViewName("/404");
return mav;
}
示例12: handleNoHandlerFoundException
import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@Test
public void handleNoHandlerFoundException() throws Exception {
ServletServerHttpRequest req = new ServletServerHttpRequest(
new MockHttpServletRequest("GET","/resource"));
NoHandlerFoundException ex = new NoHandlerFoundException(req.getMethod().name(),
req.getServletRequest().getRequestURI(),req.getHeaders());
ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex);
assertNotNull("No ModelAndView returned", mav);
assertTrue("No Empty ModelAndView returned", mav.isEmpty());
assertEquals("Invalid status code", 404, response.getStatus());
}
示例13: noHandlerFoundException
import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@Test
public void noHandlerFoundException() {
ServletServerHttpRequest req = new ServletServerHttpRequest(
new MockHttpServletRequest("GET","/resource"));
Exception ex = new NoHandlerFoundException(req.getMethod().toString(),
req.getServletRequest().getRequestURI(),req.getHeaders());
testException(ex);
}
示例14: hmsException
import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@ExceptionHandler( NoHandlerFoundException.class )
@ResponseStatus( value = HttpStatus.BAD_REQUEST )
@ResponseBody
public BaseResponse hmsException( HttpServletRequest req, NoHandlerFoundException exception )
{
return new BaseResponse( HttpStatus.BAD_REQUEST.value(), HttpStatus.BAD_REQUEST.getReasonPhrase(),
exception.getMessage() );
}
示例15: shouldHandleException_should_return_not_found_error_when_passed_NoHandlerFoundException
import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@Test
public void shouldHandleException_should_return_not_found_error_when_passed_NoHandlerFoundException() {
// given
NoHandlerFoundException ex = new NoHandlerFoundException("GET", "/some/url", mock(HttpHeaders.class));
// when
ApiExceptionHandlerListenerResult result = listener.shouldHandleException(ex);
// then
validateResponse(result, true, Collections.singletonList(testProjectApiErrors.getNotFoundApiError()));
}