本文整理汇总了Java中org.springframework.http.HttpStatus.BAD_REQUEST属性的典型用法代码示例。如果您正苦于以下问题:Java HttpStatus.BAD_REQUEST属性的具体用法?Java HttpStatus.BAD_REQUEST怎么用?Java HttpStatus.BAD_REQUEST使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.springframework.http.HttpStatus
的用法示例。
在下文中一共展示了HttpStatus.BAD_REQUEST属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: post
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json;charset=utf-8")
public ResponseEntity<?> post(JwtAuthenticationToken token, @RequestBody Envelope envelope) {
UserContext userContext = (UserContext) token.getPrincipal();
if (envelope != null) {
List<Event> events = envelope.getData();
List<String> ids = null;
if (events != null && !events.isEmpty()) {
ids = new ArrayList<>();
for (Event event : events) {
try {
String savedId = this.eventService.save(userContext.getTenantId(), userContext.getOrgId(), event);
ids.add(savedId);
} catch (Exception e) {
logger.error("Unable to save event {}",event);
continue;
}
}
}
return new ResponseEntity<>(ids, null, HttpStatus.OK);
}
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
示例2: processValidationError
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public ErrorVM processValidationError(MethodArgumentNotValidException ex) {
BindingResult result = ex.getBindingResult();
List<FieldError> fieldErrors = result.getFieldErrors();
ErrorVM dto = new ErrorVM(ErrorConstants.ERR_VALIDATION);
for (FieldError fieldError : fieldErrors) {
dto.add(fieldError.getObjectName(), fieldError.getField(), fieldError.getCode());
}
return dto;
}
示例3: processMissingServletRequestParameterError
@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;
}
示例4: executeCustomCommand
@RequestMapping(value = "/customcommand", method = RequestMethod.POST)
public ResponseEntity<CustomResponse> executeCustomCommand(@RequestParam("command") String command,
@RequestHeader(value = "JHeapSessionId") String JHeapSessionId) {
if (command == null || command.isEmpty()) {
return new ResponseEntity<CustomResponse>(HttpStatus.BAD_REQUEST);
}
CustomResponse analysis = analysisService.executeCustomCommand(command);
return new ResponseEntity<CustomResponse>(analysis, HttpStatus.OK);
}
示例5: handleMessageException
/**
* Handles NorthboundException exception.
*
* @param exception the NorthboundException instance
* @param request the WebRequest caused exception
* @return the ResponseEntity object instance
*/
@ExceptionHandler(MessageException.class)
protected ResponseEntity<Object> handleMessageException(MessageException exception, WebRequest request) {
HttpStatus status;
switch (exception.getErrorType()) {
case NOT_FOUND:
status = HttpStatus.NOT_FOUND;
break;
case DATA_INVALID:
case PARAMETERS_INVALID:
status = HttpStatus.BAD_REQUEST;
break;
case ALREADY_EXISTS:
status = HttpStatus.CONFLICT;
break;
case AUTH_FAILED:
status = HttpStatus.UNAUTHORIZED;
break;
case OPERATION_TIMED_OUT:
case INTERNAL_ERROR:
default:
status = HttpStatus.INTERNAL_SERVER_ERROR;
break;
}
MessageError error = new MessageError(request.getHeader(CORRELATION_ID), exception.getTimestamp(),
exception.getErrorType().toString(), exception.getMessage(), exception.getErrorDescription());
return super.handleExceptionInternal(exception, error, new HttpHeaders(), status, request);
}
示例6: handleMethodArgumentTypeMismatch
@ExceptionHandler({ MethodArgumentTypeMismatchException.class })
public ResponseEntity<Object> handleMethodArgumentTypeMismatch(final MethodArgumentTypeMismatchException ex, final WebRequest request) {
logger.info(ex.getClass().getName());
//
final String error = ex.getName() + " should be of type " + ex.getRequiredType().getName();
final AitException AitException = new AitException(HttpStatus.BAD_REQUEST, ex.getLocalizedMessage(), error);
return new ResponseEntity<Object>(AitException, new HttpHeaders(), AitException.getStatus());
}
示例7: deleteImage
@GetMapping(path="/deleteImage")
@ResponseBody
public ResponseEntity<Object> deleteImage(@RequestParam int id){
ResponseEntity response;
try {
imageFormRepository.deleteById(id);
response = new ResponseEntity<>("Image successfully deleted.", HttpStatus.OK);
} catch (Exception e) {
response = new ResponseEntity<>("Error with request", HttpStatus.BAD_REQUEST);
}
return response;
}
示例8: register
@RequestMapping(value = "/register", method = RequestMethod.POST)
public ResponseEntity<?> register(@RequestBody UserRegisterDTO registerDTO) {
Optional<ValidationErrors> errors = validators.validate(registerDTO);
if (!errors.isPresent()) {
//return confirmation
UserCredentialDTO newUser = userService.regiserUser(registerDTO);
log.debug("New user[{}] created!",newUser.getUsername());
return new ResponseEntity<>(newUser, HttpStatus.OK);
} else {
log.warn("Missing or incorrect data on registration form.");
return new ResponseEntity<>(errors.get().getErrors(), HttpStatus.BAD_REQUEST);
}
}
示例9: paramMissErrorHandler
@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;
}
示例10: makeBid
@Secured(USER)
@RequestMapping(value = "/transport/{id}/bid", method = RequestMethod.POST)
public ResponseEntity<?> makeBid(@PathVariable("id") long transportId, @RequestBody PlaceBidDTO bidDTO, Principal principal) {
log.debug("{} trying to make a bid on transport({})",principal.getName(), transportId);
try {
auctionService.makeBid(transportId, bidDTO.getAmount(), principal.getName());
return new ResponseEntity<>("Bid placed.", HttpStatus.OK);
} catch (AuctionError auerr) {
log.error("Error happened during bidding: {}",auerr.getMessage());
return new ResponseEntity<>(auerr.getMessage(), HttpStatus.BAD_REQUEST);
}
}
示例11: handle
@ExceptionHandler(ServletRequestBindingException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public ErrorResponse handle(final ServletRequestBindingException ex) {
log.error("Missing parameter", ex);
return new ErrorResponse("MISSING_PARAMETER", ex.getMessage());
}
示例12: adminDeleteTransport
@Secured(ADMIN)
@RequestMapping(value = "/{id}/admin", method = DELETE)
public ResponseEntity<?> adminDeleteTransport(@PathVariable("id") long id) {
if (transportService.adminDelete(id)) {
log.debug("Transport({}) deleted by admin.", id);
return new ResponseEntity<>("Transport deleted.", HttpStatus.OK);
} else {
log.warn("Failed to delete transport({}).", id);
return new ResponseEntity<>("Failed to delete transport.", HttpStatus.BAD_REQUEST);
}
}
示例13: register
/**
* RFC7591
* Definitions this endpoint MAY be an OAuth 2.0 protected resource
* and it MAY accept an initial access token.
*
* As we are using open registration, these endpoint MAY be rate-limited to prevent a denial-of-service attack.
*/
@PostMapping("/register")
public ResponseEntity<Object> register(@RequestBody ClientRegistrationRequest clientMetadata) {
if (!redirectFlowSpecification.isSatisfiedBy(clientMetadata)) {
RegistrationError error = new RegistrationError(RegistrationError.INVALID_REDIRECT_URI);
error.setErrorDescription("You must specify redirect_uri when using flows with redirection");
return new ResponseEntity<>(error, HttpStatus.BAD_REQUEST);
}
DynamicClientDetails clientDetails = clientDetailsFactory.create(clientMetadata);
clientRegistration.addClientDetails(clientDetails);
return new ResponseEntity<>(createResponse(clientDetails), HttpStatus.CREATED);
}
示例14: newIllegalArgumentException
public static YggdrasilException newIllegalArgumentException(String message) {
return new YggdrasilException(HttpStatus.BAD_REQUEST, "IllegalArgumentException", message);
}
示例15: processParameterizedValidationError
@ExceptionHandler(CustomParameterizedException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public ParameterizedErrorVM processParameterizedValidationError(CustomParameterizedException ex) {
return ex.getErrorVM();
}