List of usage examples for org.springframework.web.bind MissingServletRequestParameterException getParameterName
public final String getParameterName()
From source file:org.openmhealth.dsu.controller.GenericExceptionHandlingControllerAdvice.java
@ExceptionHandler(MissingServletRequestParameterException.class) @ResponseStatus(HttpStatus.BAD_REQUEST)//from w ww.j av a 2s . com public void handleMissingServletRequestParameterException(MissingServletRequestParameterException e, HttpServletRequest request) { log.debug("A {} request for '{}' failed because parameter '{}' is missing.", request.getMethod(), request.getPathInfo(), e.getParameterName(), e); }
From source file:net.duckling.ddl.web.agent.csp.CspBaseController.java
@ExceptionHandler public void exp(HttpServletRequest request, HttpServletResponse response, Exception ex) { if (ex instanceof MissingServletRequestParameterException) { MissingServletRequestParameterException me = (MissingServletRequestParameterException) ex; ErrorMsg msg = ErrorMsg.MISSING_PARAMETER; msg.setMsg("Required parameter [" + me.getParameterName() + "] is missing."); writeError(msg, request, response); } else if (ex instanceof TypeMismatchException) { TypeMismatchException te = (TypeMismatchException) ex; ErrorMsg msg = ErrorMsg.TYPE_MISMATCH; msg.setMsg("Value [" + te.getValue() + "] of type is mismatch."); writeError(msg, request, response); } else {/*from ww w.j a v a2 s .co m*/ writeError(ErrorMsg.UNKNOW_ERROR, request, response); } }
From source file:com.hyphenated.card.controller.ExceptionController.java
/** * MissingServletRequestParameterException handler. This exception will occur whenever * a controller method does not receive a required request parameter. * @param e Exception being thrown/* w ww. jav a 2 s .c om*/ * @return JSON Error messages specific to the missing parameter exception. */ @ExceptionHandler(MissingServletRequestParameterException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public @ResponseBody Map<String, String> handleBadParameterExcpetion( MissingServletRequestParameterException e) { Map<String, String> error = new HashMap<String, String>(); error.put("error", "Required parameter not present."); error.put("errorDetails", "The parameter " + e.getParameterName() + " is required and not present in the request."); log.error("Error: " + e.getMessage()); return error; }
From source file:org.broadleafcommerce.core.web.api.BroadleafSpringRestExceptionMapper.java
@ExceptionHandler(MissingServletRequestParameterException.class) public @ResponseBody ErrorWrapper handleMissingServletRequestParameterException(HttpServletRequest request, HttpServletResponse response, Exception ex) { ErrorWrapper errorWrapper = (ErrorWrapper) context.getBean(ErrorWrapper.class.getName()); Locale locale = null;//ww w. ja v a 2 s.c o m String parameterType = null; String parameterName = null; BroadleafRequestContext requestContext = BroadleafRequestContext.getBroadleafRequestContext(); if (requestContext != null) { locale = requestContext.getJavaLocale(); } if (ex instanceof MissingServletRequestParameterException) { MissingServletRequestParameterException castedException = (MissingServletRequestParameterException) ex; parameterType = castedException.getParameterType(); parameterName = castedException.getParameterName(); } LOG.error("An error occured invoking a REST service", ex); if (locale == null) { locale = Locale.getDefault(); } if (parameterType == null) { parameterType = "String"; } if (parameterName == null) { parameterName = "[unknown name]"; } errorWrapper.setHttpStatusCode(HttpStatus.SC_BAD_REQUEST); response.setStatus(resolveResponseStatusCode(ex, errorWrapper)); ErrorMessageWrapper errorMessageWrapper = (ErrorMessageWrapper) context .getBean(ErrorMessageWrapper.class.getName()); errorMessageWrapper .setMessageKey(resolveClientMessageKey(BroadleafWebServicesException.QUERY_PARAMETER_NOT_PRESENT)); errorMessageWrapper .setMessage(messageSource.getMessage(BroadleafWebServicesException.QUERY_PARAMETER_NOT_PRESENT, new String[] { parameterType, parameterName }, BroadleafWebServicesException.QUERY_PARAMETER_NOT_PRESENT, locale)); errorWrapper.getMessages().add(errorMessageWrapper); return errorWrapper; }