Example usage for org.springframework.web.bind MissingServletRequestParameterException getMessage

List of usage examples for org.springframework.web.bind MissingServletRequestParameterException getMessage

Introduction

In this page you can find the example usage for org.springframework.web.bind MissingServletRequestParameterException getMessage.

Prototype

@Override
    public String getMessage() 

Source Link

Usage

From source file:io.kamax.mxisd.controller.DefaultExceptionHandler.java

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MissingServletRequestParameterException.class)
public String handle(HttpServletRequest req, MissingServletRequestParameterException e) {
    return handle(req, "M_INCOMPLETE_REQUEST", e.getMessage());
}

From source file:nz.net.catalyst.mobile.dds.CapabilitySerivceControllerTest.java

@Test
public void testRequiredParams() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/services/v1/get_capabilities");
    MockHttpServletResponse response = new MockHttpServletResponse();

    HashMap<String, String> headers = new HashMap<String, String>();
    headers.put("user-agent",
            "Mozilla/5.0 (SymbianOS/9.2; U; Series60/3.1 NokiaE71-1/100.07.57; Profile/MIDP-2.0 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413");
    String headersStr = mapper.writeValueAsString(headers);

    request.addParameter("headers", headersStr);

    try {//from   ww w .  j a va2s . c  o  m
        handlerAdapter.handle(request, response, csController);
        fail("exception expected");
    } catch (MissingServletRequestParameterException e) {
        assertEquals("Required String[] parameter 'capability' is not present", e.getMessage());
    }

    request = new MockHttpServletRequest("GET", "/services/v1/get_capabilities");
    request.addParameter("capability", "device_id");

    try {
        handlerAdapter.handle(request, response, csController);
        fail("exception expected");
    } catch (MissingServletRequestParameterException e) {
        assertEquals("Required String parameter 'headers' is not present", e.getMessage());
        csController.handleMissingParameters(e, response);

        assertEquals(400, response.getStatus());
    }

}

From source file:nz.net.catalyst.mobile.dds.CapabilityServiceController.java

@ExceptionHandler(MissingServletRequestParameterException.class)
public ModelAndView handleMissingParameters(MissingServletRequestParameterException ex,
        HttpServletResponse response) {//from   w  w  w  . ja v a  2s .co m
    logger.warn("parse problems on input data", ex);

    ModelAndView mav = new ModelAndView();
    mav.addObject("error_message", ex.getMessage());

    mav.setViewName("error");
    response.setStatus(400);

    return mav;
}

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/*from w  ww.  j a  v  a  2s . 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.springframework.batch.admin.web.RestControllerAdvice.java

/**
 * Handles the case where client submitted an ill valued request (missing parameter).
 *
 * @param e exception to be handled//w w w  .  java  2  s . c o  m
 *
 * @return VndErrors see {@link VndErrors}
 */
@ExceptionHandler
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public VndErrors onMissingServletRequestParameterException(MissingServletRequestParameterException e) {
    String logref = logDebug(e);
    return new VndErrors(logref, e.getMessage());
}

From source file:org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.java

/**
 * Handle the case when a required parameter is missing.
 * <p>The default implementation sends an HTTP 400 error, and returns an empty {@code ModelAndView}.
 * Alternatively, a fallback view could be chosen, or the MissingServletRequestParameterException
 * could be rethrown as-is./*from  ww w.ja va2  s  .  c o  m*/
 * @param ex the MissingServletRequestParameterException to be handled
 * @param request current HTTP request
 * @param response current HTTP response
 * @param handler the executed handler
 * @return an empty ModelAndView indicating the exception was handled
 * @throws IOException potentially thrown from response.sendError()
 */
protected ModelAndView handleMissingServletRequestParameter(MissingServletRequestParameterException ex,
        HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {

    response.sendError(HttpServletResponse.SC_BAD_REQUEST, ex.getMessage());
    return new ModelAndView();
}