当前位置: 首页>>代码示例>>Java>>正文


Java HttpStatus.BAD_REQUEST属性代码示例

本文整理汇总了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);
}
 
开发者ID:Apereo-Learning-Analytics-Initiative,项目名称:OpenLRW,代码行数:25,代码来源:CaliperController.java

示例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;
}
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:12,代码来源:ExceptionTranslator.java

示例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;
}
 
开发者ID:xm-online,项目名称:xm-commons,代码行数:7,代码来源:ExceptionTranslator.java

示例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);
}
 
开发者ID:mgbiedma,项目名称:java-heap-analyzer-api,代码行数:9,代码来源:RestApiController.java

示例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);
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:36,代码来源:NorthboundExceptionHandler.java

示例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());
}
 
开发者ID:allianzit,项目名称:ait-platform,代码行数:9,代码来源:AitRestExceptionHandler.java

示例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;
}
 
开发者ID:KobePig,项目名称:NutriBuddi,代码行数:14,代码来源:ImageFormController.java

示例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);
    }
}
 
开发者ID:RFTDevGroup,项目名称:RFTBackend,代码行数:13,代码来源:RegistrationController.java

示例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;
}
 
开发者ID:Nbsaw,项目名称:miaohu,代码行数:7,代码来源:GlobalExceptionAdvice.java

示例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);
    }
}
 
开发者ID:RFTDevGroup,项目名称:RFTBackend,代码行数:12,代码来源:AuctionController.java

示例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());
}
 
开发者ID:nielsutrecht,项目名称:spring-boot-aop,代码行数:7,代码来源:ExceptionHandlers.java

示例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);
    }
}
 
开发者ID:RFTDevGroup,项目名称:RFTBackend,代码行数:11,代码来源:TransportController.java

示例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);
}
 
开发者ID:PacktPublishing,项目名称:OAuth-2.0-Cookbook,代码行数:21,代码来源:DynamicClientRegistrationController.java

示例14: newIllegalArgumentException

public static YggdrasilException newIllegalArgumentException(String message) {
	return new YggdrasilException(HttpStatus.BAD_REQUEST, "IllegalArgumentException", message);
}
 
开发者ID:to2mbn,项目名称:yggdrasil-mock,代码行数:3,代码来源:YggdrasilException.java

示例15: processParameterizedValidationError

@ExceptionHandler(CustomParameterizedException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public ParameterizedErrorVM processParameterizedValidationError(CustomParameterizedException ex) {
    return ex.getErrorVM();
}
 
开发者ID:ElectronicArmory,项目名称:Armory,代码行数:6,代码来源:ExceptionTranslator.java


注:本文中的org.springframework.http.HttpStatus.BAD_REQUEST属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。