List of usage examples for org.springframework.http HttpStatus BAD_REQUEST
HttpStatus BAD_REQUEST
To view the source code for org.springframework.http HttpStatus BAD_REQUEST.
Click Source Link
From source file:reconf.server.services.property.ClientReadPropertyService.java
@RequestMapping(value = "/{prod}/{comp}/{prop}", method = RequestMethod.GET) @Transactional(readOnly = true)/*from w w w . j a v a 2 s . c o m*/ public ResponseEntity<String> doIt(@PathVariable("prod") String product, @PathVariable("comp") String component, @PathVariable("prop") String property, @RequestParam(value = "instance", required = false, defaultValue = "unknown") String instance) { PropertyKey key = new PropertyKey(product, component, property); List<String> errors = DomainValidator.checkForErrors(key); Property reqProperty = new Property(key); HttpHeaders headers = new HttpHeaders(); if (!errors.isEmpty()) { addErrorHeader(headers, errors, reqProperty); return new ResponseEntity<String>(headers, HttpStatus.BAD_REQUEST); } List<Property> dbProperties = properties .findByKeyProductAndKeyComponentAndKeyNameOrderByRulePriorityDescKeyRuleNameAsc(key.getProduct(), key.getComponent(), key.getName()); for (Property dbProperty : dbProperties) { try { if (isMatch(instance, dbProperty)) { addRuleHeader(headers, dbProperty); return new ResponseEntity<String>(dbProperty.getValue(), headers, HttpStatus.OK); } } catch (Exception e) { log.error("error applying rule", e); addRuleHeader(headers, dbProperty); addErrorHeader(headers, Collections.singletonList("rule error"), reqProperty); return new ResponseEntity<String>(headers, HttpStatus.INTERNAL_SERVER_ERROR); } } return new ResponseEntity<String>(HttpStatus.NOT_FOUND); }
From source file:edu.eci.arsw.pacm.controllers.PacmRESTController.java
@RequestMapping(path = "/{salanum}/protectores", method = RequestMethod.PUT) public ResponseEntity<?> agregarProtector(@PathVariable(name = "salanum") String salanum, @RequestBody Player p) {// w w w.java 2s .c om synchronized (this) { try { if (services.getProtectores(Integer.parseInt(salanum)).size() < 4) { services.registrarJugadorProtector(Integer.parseInt(salanum), p); } } catch (ServicesException ex) { Logger.getLogger(PacmRESTController.class.getName()).log(Level.SEVERE, null, ex); return new ResponseEntity<>(ex.getLocalizedMessage(), HttpStatus.BAD_REQUEST); } return new ResponseEntity<>(HttpStatus.CREATED); } }
From source file:plbtw.klmpk.barang.hilang.controller.LogController.java
@RequestMapping(method = RequestMethod.POST, produces = "application/json") public CustomResponseMessage addLog(@RequestBody LogRequest logRequest) { try {//from www. j a v a 2 s. co m Log log = new Log(); log.setId(logRequest.getIdLog()); log.setTimeRequest(logRequest.getTime_request()); log.setStatus(""); return new CustomResponseMessage(HttpStatus.CREATED, "Add Log berhasil"); } catch (Exception ex) { return new CustomResponseMessage(HttpStatus.BAD_REQUEST, ex.toString()); } }
From source file:uk.urchinly.wabi.ingest.UploadController.java
@RequestMapping(method = RequestMethod.POST, value = "/upload") public ResponseEntity<String> upload(@RequestParam("file") MultipartFile file) { if (file.isEmpty()) { logger.debug("Upload file is empty."); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Failed with empty file"); }/* w w w. jav a 2s . com*/ BufferedOutputStream outputStream = null; try { File outputFile = new File(appSharePath + "/" + file.getOriginalFilename()); outputStream = new BufferedOutputStream(new FileOutputStream(outputFile)); FileCopyUtils.copy(file.getInputStream(), outputStream); Asset asset = new Asset(file.getOriginalFilename(), file.getOriginalFilename(), (double) file.getSize(), file.getContentType(), Collections.emptyList()); this.saveAsset(asset); } catch (Exception e) { logger.warn(e.getMessage(), e); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Failed with error"); } finally { IOUtils.closeQuietly(outputStream); } return ResponseEntity.ok("File accepted"); }
From source file:com.linecorp.bot.spring.boot.interceptor.LineBotServerInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { HandlerMethod hm = (HandlerMethod) handler; MethodParameter[] methodParameters = hm.getMethodParameters(); for (MethodParameter methodParameter : methodParameters) { if (methodParameter.getParameterAnnotation(LineBotMessages.class) != null) { try { CallbackRequest callbackRequest = lineBotCallbackRequestParser.handle(request); LineBotServerArgumentProcessor.setValue(request, callbackRequest); return true; } catch (LineBotCallbackException e) { log.info("LINE Bot callback exception: {}", e.getMessage()); response.sendError(HttpStatus.BAD_REQUEST.value()); try (PrintWriter writer = response.getWriter()) { writer.println(e.getMessage()); }/* www . j a v a 2 s .co m*/ return false; } } } return true; }
From source file:md.ibanc.rm.controllers.request.RequestExchangeRateController.java
@RequestMapping(value = "/find/exchangeRate/Date", method = RequestMethod.POST) public ResponseEntity<ExchangeRateDetails> findExchangeRateByDate( @Valid @RequestBody ExchangeRateForm exchangeRateForm, BindingResult bindingResult, HttpServletRequest request) {/* w w w .ja v a2 s.com*/ //@RequestMapping(value = "/find/exchangeRate/Date", method = RequestMethod.GET) //public ResponseEntity<ExchangeRateDetails> findExchangeRateByDate() { // SimpleDateFormat formatater = new SimpleDateFormat("yyyy-MM-dd"); // String dateString = "2016-1216"; List<ExchangeRateList> rateLists; try { rateLists = exchangeRateService.findExchangeRateByDate(exchangeRateForm.getDateCurs()); } catch (Exception ex) { ExchangeRateDetails exchangeRateDetails = new ExchangeRateDetails(); exchangeRateDetails.setReturnCode(403); exchangeRateDetails.setReturnDescription(ex.getMessage()); return new ResponseEntity<>(exchangeRateDetails, HttpStatus.BAD_REQUEST); } ExchangeRateDetails exchangeRateDetails = new ExchangeRateDetails(); exchangeRateDetails.setExchangeRateList(rateLists); exchangeRateDetails.setReturnCode(RetCodeConst.RETCOD_OK); exchangeRateDetails.setReturnDescription(RetDescriptionConst.RETCOD_OK); return new ResponseEntity<>(exchangeRateDetails, HttpStatus.OK); }
From source file:fi.hsl.parkandride.itest.ErrorHandlingITest.java
@Test public void geolatte_json_mapping_violations_are_detected() { givenWithContent().body("{ \"name\": \"foo\", \"location\": \"this is not readable location\" }").when() .post(UrlSchema.FACILITIES).then() .spec(assertResponse(HttpStatus.BAD_REQUEST, HttpMessageNotReadableException.class)) .body("violations[0].path", is("location")); }
From source file:org.ff4j.spring.boot.exceptions.FF4jExceptionHandler.java
@ExceptionHandler(value = PropertiesBadRequestException.class) @ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "properties specified wrongly") public void propertiesBadRequestException() { // Not necessary to handle this exception }
From source file:org.apigw.authserver.web.admin.DefaultAdminExceptionHandler.java
@ExceptionHandler @ResponseStatus(HttpStatus.BAD_REQUEST) public void handle(HttpMessageNotReadableException e) { log.warn("Returning HTTP 400 Bad Request", e); }
From source file:be.bittich.quote.controller.impl.DefaultExceptionHandler.java
@RequestMapping(produces = APPLICATION_JSON) @ExceptionHandler({ MissingServletRequestParameterException.class, UnsatisfiedServletRequestParameterException.class, HttpRequestMethodNotSupportedException.class, ServletRequestBindingException.class }) @ResponseStatus(value = HttpStatus.BAD_REQUEST) public @ResponseBody Map<String, Object> handleRequestException(Exception ex) { Map<String, Object> map = newHashMap(); map.put("error", "Request Error"); map.put("cause", ex.getMessage()); return map;/*w w w .ja v a 2 s . c o m*/ }