本文整理汇总了Java中org.springframework.web.bind.MissingServletRequestParameterException类的典型用法代码示例。如果您正苦于以下问题:Java MissingServletRequestParameterException类的具体用法?Java MissingServletRequestParameterException怎么用?Java MissingServletRequestParameterException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MissingServletRequestParameterException类属于org.springframework.web.bind包,在下文中一共展示了MissingServletRequestParameterException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processMissingServletRequestParameterError
import org.springframework.web.bind.MissingServletRequestParameterException; //导入依赖的package包/类
@ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public FieldErrorVM processMissingServletRequestParameterError(MissingServletRequestParameterException ex) {
FieldErrorVM dto = new FieldErrorVM(ErrorConstants.ERR_VALIDATION, translate(ErrorConstants.ERR_VALIDATION));
dto.add(ex.getParameterType(), ex.getParameterName(), ex.getLocalizedMessage());
return dto;
}
示例2: handleMissingAndMalformedParametersValues
import org.springframework.web.bind.MissingServletRequestParameterException; //导入依赖的package包/类
@ExceptionHandler({
InvalidArgumentException.class,
MalformedTemplateException.class,
MissingServletRequestParameterException.class,
MissingServletRequestPartException.class,
ServletRequestBindingException.class })
@ResponseStatus(code = HttpStatus.BAD_REQUEST)
@ResponseBody
public void handleMissingAndMalformedParametersValues(Exception exception) {
log.error("Input parameters were missing/malformed:", exception);
}
示例3: paramMissErrorHandler
import org.springframework.web.bind.MissingServletRequestParameterException; //导入依赖的package包/类
@ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public Map<String,String> paramMissErrorHandler(MissingServletRequestParameterException e) throws Exception {
Map error = new HashMap();
error.put("error","参数" + e.getParameterName() + "不能为空");
return error;
}
示例4: onClientGenericBadRequest
import org.springframework.web.bind.MissingServletRequestParameterException; //导入依赖的package包/类
/**
* Client did not formulate a correct request.
* Log the exception message at warn level and stack trace as trace level.
* Return response status HttpStatus.BAD_REQUEST (400).
*/
@ExceptionHandler({
MissingServletRequestParameterException.class,
MethodArgumentTypeMismatchException.class,
InvalidStreamDefinitionException.class
})
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public VndErrors onClientGenericBadRequest(Exception e) {
String logref = logWarnLevelExceptionMessage(e);
if (logger.isTraceEnabled()) {
logTraceLevelStrackTrace(e);
}
String msg = getExceptionMessage(e);
return new VndErrors(logref, msg);
}
示例5: handleMissingValue
import org.springframework.web.bind.MissingServletRequestParameterException; //导入依赖的package包/类
@Override
protected void handleMissingValue(String name, MethodParameter parameter, NativeWebRequest request)
throws Exception {
HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);
if (MultipartResolutionDelegate.isMultipartArgument(parameter)) {
if (!MultipartResolutionDelegate.isMultipartRequest(servletRequest)) {
throw new MultipartException("Current request is not a multipart request");
} else {
throw new MissingServletRequestPartException(name);
}
} else {
throw new MissingServletRequestParameterException(name,
parameter.getNestedParameterType().getSimpleName());
}
}
示例6: BaseExceptionHandler
import org.springframework.web.bind.MissingServletRequestParameterException; //导入依赖的package包/类
public BaseExceptionHandler(final Logger log) {
this.log = log;
registerMapping(
MissingServletRequestParameterException.class,
"MISSING_PARAMETER",
"Missing request parameter",
BAD_REQUEST);
registerMapping(
MethodArgumentTypeMismatchException.class,
"ARGUMENT_TYPE_MISMATCH",
"Argument type mismatch",
BAD_REQUEST);
registerMapping(
HttpRequestMethodNotSupportedException.class,
"METHOD_NOT_SUPPORTED",
"HTTP method not supported",
METHOD_NOT_ALLOWED);
registerMapping(
ServletRequestBindingException.class,
"MISSING_HEADER",
"Missing header in request",
BAD_REQUEST);
}
示例7: testRequiredParameterMissing
import org.springframework.web.bind.MissingServletRequestParameterException; //导入依赖的package包/类
/**
* Test required parameter missing.
*/
@Test
public void testRequiredParameterMissing() {
RestAssured
.registerParser("text/plain", Parser.TEXT);
RestAssured
.given()
.param("radius", 0)
.param("longitude", -1)
.when()
.get(RESTAURANT_API)
.then()
.statusCode(200)
.body(Matchers.containsString(MissingServletRequestParameterException.class.toString()));
}
示例8: testRequiredParameterMissingAuthorizedCall
import org.springframework.web.bind.MissingServletRequestParameterException; //导入依赖的package包/类
/**
* Test required parameter missing.
*/
@Test
public void testRequiredParameterMissingAuthorizedCall() {
User user = getUserWithUserTypeKunde();
userRepository.save(user);
String authString = user.getUsername() + ":" + user.getPasswordconfirm();
byte[] base64Encoded = Base64.getEncoder().encode(authString.getBytes());
String encodedString = new String(base64Encoded);
RestAssured
.registerParser("text/plain", Parser.TEXT);
RestAssured
.given()
.header("Authorization", "Basic " + encodedString)
.param("radius", 0)
.param("longitude", -1)
.when()
.get(RESTAURANT_API)
.then()
.statusCode(200)
.body(Matchers.containsString(MissingServletRequestParameterException.class.toString()));
}
示例9: handleUncaughtException
import org.springframework.web.bind.MissingServletRequestParameterException; //导入依赖的package包/类
@ExceptionHandler(Exception.class)
public void handleUncaughtException(Exception ex, WebRequest request, HttpServletResponse response) throws IOException {
if (ex instanceof HttpMediaTypeNotAcceptableException) {
response.sendError(HttpStatus.NOT_ACCEPTABLE.value());
} else if (ex instanceof HttpMessageNotReadableException
|| ex instanceof MissingServletRequestParameterException
|| ex instanceof HttpMediaTypeNotSupportedException) {
response.sendError(HttpStatus.BAD_REQUEST.value(), ex.getLocalizedMessage().substring(0, ex.getLocalizedMessage().indexOf("\n")));
} else {
int hashValue = response.hashCode();
//Note: we are giving the user a generic message.
//Server logs can be used to troubleshoot problems.
String msgText = "Something bad happened. Contact us with Reference Number: " + hashValue;
LOG.error(msgText, ex);
response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(), msgText);
}
}
示例10: preHandle
import org.springframework.web.bind.MissingServletRequestParameterException; //导入依赖的package包/类
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception
{
// see if a handler is of the type that requires form context
if (handler instanceof FormContextRequired)
{
FormContextRequired controller = (FormContextRequired)handler;
try
{
Long formId = Long.valueOf(request.getParameter(FormContextRequired.FORM_ID_NAME));
controller.setFormId(formId);
request.setAttribute(FormContextRequired.FORM_ID_NAME, formId);
}
catch (Exception e)
{
// either parameter is missing or invalid value
throw new MissingServletRequestParameterException(FormContextRequired.FORM_ID_NAME, "Long");
}
}
return true;
}
示例11: handleMissingServletRequestParameter
import org.springframework.web.bind.MissingServletRequestParameterException; //导入依赖的package包/类
@Override
protected ResponseEntity<Object> handleMissingServletRequestParameter(final MissingServletRequestParameterException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
logger.info(ex.getClass().getName());
//
final String error = ex.getParameterName() + " parameter is missing";
final ApiError apiError = new ApiError(HttpStatus.BAD_REQUEST, ex.getLocalizedMessage(), error);
return new ResponseEntity<Object>(apiError, new HttpHeaders(), apiError.getStatus());
}
示例12: handle400Error
import org.springframework.web.bind.MissingServletRequestParameterException; //导入依赖的package包/类
@ExceptionHandler(value = {IllegalArgumentException.class,
BindException.class, // controller中参数绑定bean时异常,如数据类型不匹配等
MissingServletRequestParameterException.class,
MethodArgumentTypeMismatchException.class,
HttpRequestMethodNotSupportedException.class})
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
public Result handle400Error(HttpServletRequest req, Exception e) {
String url = req.getMethod() + " " + req.getRequestURL() + "?" + req.getQueryString();
logger.debug("不合法的url请求: {}", url);
ResultEnum badRequest = ResultEnum.BAD_REQUEST;
return ResultUtils.error(badRequest.getCode(), badRequest.getMessage(), url);
}
示例13: handleMissingServletRequestParameterError
import org.springframework.web.bind.MissingServletRequestParameterException; //导入依赖的package包/类
@Loggable
@ResponseStatus(code = HttpStatus.CONFLICT)
@ExceptionHandler(MissingServletRequestParameterException.class)
public ErrorDto handleMissingServletRequestParameterError(MissingServletRequestParameterException ex) {
return ErrorDto.builder()
.errorCode(ErrorCodes.MISSING_REQUEST_PARAM)
.errors(Collections.singleton(ex.getParameterName()))
.message(ex.getLocalizedMessage())
.build();
}
示例14: handleMissingServletRequestParameter
import org.springframework.web.bind.MissingServletRequestParameterException; //导入依赖的package包/类
@Override
protected ResponseEntity<Object> handleMissingServletRequestParameter(final MissingServletRequestParameterException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
logger.info(ex.getClass().getName());
//
final String error = ex.getParameterName() + " parameter is missing";
final AitException AitException = new AitException(HttpStatus.BAD_REQUEST, ex.getLocalizedMessage(), error);
return handleExceptionInternal(ex, AitException, headers, AitException.getStatus(), request);
}
示例15: handleMissingServletRequestParameterException
import org.springframework.web.bind.MissingServletRequestParameterException; //导入依赖的package包/类
/**
* 400 - Bad Request
*/
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MissingServletRequestParameterException.class)
public Response handleMissingServletRequestParameterException(MissingServletRequestParameterException e) {
log.error("缺少请求参数: {}", e);
return new Response().failure("required_parameter_is_not_present");
}