本文整理匯總了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");
}