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:com.infinity.controller.CandidatController.java
@RequestMapping(value = { "/candidat/get/{candidatName}" }, method = RequestMethod.GET, produces = "application/json") public ResponseEntity<ArrayList<Candidat>> getByName(@PathVariable String candidatName) { ArrayList<Candidat> byName = null; ResponseEntity<ArrayList<Candidat>> responseEntity = null; try {/* ww w.ja va2s. c om*/ byName = candidatService.getByName(candidatName); responseEntity = new ResponseEntity<>(byName, HttpStatus.OK); } catch (Exception e) { LOG.error(e.getMessage()); responseEntity = new ResponseEntity<>(byName, HttpStatus.BAD_REQUEST); } return responseEntity; }
From source file:cn.dsgrp.field.stock.functional.rest.TaskRestFT.java
@Test public void invalidInput() { // create//from w w w .ja v a 2 s.c om Task titleBlankTask = new Task(); try { restTemplate.postForLocation(resourceUrl, titleBlankTask); fail("Create should fail while title is blank"); } catch (HttpStatusCodeException e) { assertThat(e.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); Map messages = jsonMapper.fromJson(e.getResponseBodyAsString(), Map.class); assertThat(messages).hasSize(1); assertThat(messages.get("title")).isIn("may not be empty", "?"); } // update titleBlankTask.setId(BigInteger.valueOf(1)); try { restTemplate.put(resourceUrl + "/1", titleBlankTask); fail("Update should fail while title is blank"); } catch (HttpStatusCodeException e) { assertThat(e.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); Map messages = jsonMapper.fromJson(e.getResponseBodyAsString(), Map.class); assertThat(messages).hasSize(1); assertThat(messages.get("title")).isIn("may not be empty", "?"); } }
From source file:org.nekorp.workflow.backend.security.controller.imp.UsuarioClienteWebControllerImp.java
/**{@inheritDoc}*/ @Override/*from ww w. ja v a 2 s. c om*/ @RequestMapping(method = RequestMethod.POST) public void crear(@Valid @RequestBody final UsuarioClienteWeb datos, final HttpServletResponse response) { datos.setAlias(StringUtils.lowerCase(datos.getAlias())); UsuarioClienteWeb resultado = usuarioClienteWebDAO.consultar(datos.getAlias()); if (resultado != null) { response.setStatus(HttpStatus.BAD_REQUEST.value()); return; } Cliente cliente = clienteDao.consultar(datos.getIdCliente()); if (cliente == null) { response.setStatus(HttpStatus.BAD_REQUEST.value()); return; } this.usuarioClienteWebDAO.guardar(datos); response.setStatus(HttpStatus.CREATED.value()); response.setHeader("Location", "/cliente/web/usuarios/" + datos.getAlias()); }
From source file:org.fineract.module.stellar.controller.BridgeController.java
@RequestMapping(value = "", method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" }) @Transactional//from w w w . j av a 2 s . c om public ResponseEntity<String> createStellarBridgeConfiguration( @RequestBody final AccountBridgeConfiguration stellarBridgeConfig) { if (stellarBridgeConfig.getMifosTenantId() == null || stellarBridgeConfig.getMifosToken() == null || stellarBridgeConfig.getEndpoint() == null) { return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } try { StellarAddress.parse(stellarBridgeConfig.getMifosTenantId() + "*some-syntactically-valid-domain.com"); } catch (final InvalidStellarAddressException e) { return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } final String newApiKey = this.securityService.generateApiKey(stellarBridgeConfig.getMifosTenantId()); bridgeService.createStellarBridgeConfig(stellarBridgeConfig.getMifosTenantId(), stellarBridgeConfig.getMifosToken(), stellarBridgeConfig.getEndpoint()); return new ResponseEntity<>(newApiKey, HttpStatus.CREATED); }
From source file:it.polimi.diceH2020.launcher.controller.rest.RestFilesController.java
@RequestMapping(value = "/upload", method = RequestMethod.POST) public ResponseEntity<BaseResponseBody> multipleSave(@RequestParam("file[]") List<MultipartFile> files, @RequestParam("scenario") String scenarioStringRepresentation) { BaseResponseBody body = new BaseResponseBody(); PendingSubmission submission = new PendingSubmission(); Scenario scenario = Scenario.generateScenario(scenarioStringRepresentation); body.setScenario(scenario);//from www .ja v a2 s .c om submission.setScenario(scenario); body.setAcceptedFiles(new LinkedList<>()); ResponseEntity<BaseResponseBody> response = new ResponseEntity<>(body, HttpStatus.INTERNAL_SERVER_ERROR); boolean good_status = true; List<String> additionalFileNames = new LinkedList<>(); List<File> allSavedFiles = new LinkedList<>(); if (files == null || files.isEmpty()) { String message = "No files to process!"; logger.error(message); body.setMessage(message); response = new ResponseEntity<>(body, HttpStatus.BAD_REQUEST); good_status = false; } else { Iterator<MultipartFile> multipartFileIterator = files.iterator(); while (good_status && multipartFileIterator.hasNext()) { MultipartFile multipartFile = multipartFileIterator.next(); String fileName = new File(multipartFile.getOriginalFilename()).getName(); logger.trace("Analyzing file " + fileName); File savedFile = null; try { savedFile = saveFile(multipartFile, fileName); allSavedFiles.add(savedFile); } catch (FileNameClashException e) { String message = String.format("'%s' already exists", fileName); logger.error(message, e); body.setMessage(message); response = new ResponseEntity<>(body, HttpStatus.BAD_REQUEST); good_status = false; } catch (IOException e) { String message = String.format("Error handling '%s'", fileName); logger.error(message, e); body.setMessage(message); response = new ResponseEntity<>(body, HttpStatus.INTERNAL_SERVER_ERROR); good_status = false; } if (good_status) { if (fileName.contains(".json")) { Optional<InstanceDataMultiProvider> idmp = validator .readInstanceDataMultiProvider(savedFile.toPath()); if (idmp.isPresent()) { if (idmp.get().validate()) { submission.setInstanceData(savedFile.getPath()); body.getAcceptedFiles().add(savedFile.getName()); } else { logger.error(idmp.get().getValidationError()); body.setMessage(idmp.get().getValidationError()); response = new ResponseEntity<>(body, HttpStatus.BAD_REQUEST); good_status = false; } } else { String message = "You have submitted an invalid json!"; logger.error(message); body.setMessage(message); response = new ResponseEntity<>(body, HttpStatus.BAD_REQUEST); good_status = false; } } else if (fileName.contains(".txt") || fileName.contains(".jsimg") || fileName.contains(".def") || fileName.contains(".net") || fileName.contains(".stat")) { additionalFileNames.add(savedFile.getPath()); body.getAcceptedFiles().add(savedFile.getName()); } } } } if (good_status) { body.setMessage("Successful file upload"); submission.setPaths(additionalFileNames); diceService.updateSubmission(submission); body.setSubmissionId(submission.getId()); Link submissionLink = ControllerLinkBuilder.linkTo(ControllerLinkBuilder .methodOn(RestLaunchAnalysisController.class).submitById(submission.getId())).withRel("submit"); body.add(submissionLink); logger.info(body); response = new ResponseEntity<>(body, HttpStatus.OK); } else { if (fileUtility.delete(allSavedFiles)) { logger.debug("Deleted the files created during a failed submission"); } } return response; }
From source file:com.asiainfo.tfsPlatform.web.functional.rest.TaskRestFT.java
@Test public void invalidInput() { // create// w w w . j av a 2 s . c o m TaskDto titleBlankTask = new TaskDto(); try { restTemplate.postForLocation(resourceUrl, titleBlankTask); fail("Create should fail while title is blank"); } catch (HttpStatusCodeException e) { assertThat(e.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); Map messages = jsonMapper.fromJson(e.getResponseBodyAsString(), Map.class); assertThat(messages).hasSize(1); assertThat(messages.get("title")).isIn("may not be empty", "?"); } // update titleBlankTask.setId(1L); try { restTemplate.put(resourceUrl + "/1", titleBlankTask); fail("Update should fail while title is blank"); } catch (HttpStatusCodeException e) { assertThat(e.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); Map messages = jsonMapper.fromJson(e.getResponseBodyAsString(), Map.class); assertThat(messages).hasSize(1); assertThat(messages.get("title")).isIn("may not be empty", "?"); } }
From source file:dk.skogemann.airline.project.ApiController.java
@ExceptionHandler public ResponseEntity<JsonError> handleException(Exception e) { e.printStackTrace();// w w w .j a v a 2 s.c o m JsonError msg = new JsonError(); msg.setMessage(e.getMessage()); return new ResponseEntity<>(msg, HttpStatus.BAD_REQUEST); }
From source file:com.phoenixnap.oss.sample.server.controllers.DrinkControllerImpl.java
@Override public ResponseEntity createDrink(CreateDrinkRequest createDrinkRequest) { LOG.debug("Entered createDrink endpoint"); try {//from w w w . j a v a 2s .c o m DrinkTypeEnum drinkType = DrinkTypeEnum.valueOf(String.valueOf(createDrinkRequest.getType())); AbstractDrink drink = null; switch (drinkType) { case ALCOHOL: drink = new AlcoholicDrink(createDrinkRequest.getName()); break; case SOFT_DRINK: drink = new SoftDrink(createDrinkRequest.getName()); break; default: LOG.error("Incorrect drink type passed: [{}] ", createDrinkRequest.getType()); return new ResponseEntity(HttpStatus.BAD_REQUEST); } this.drinksService.addDrink(drink); LOG.info("Returning from createDrink"); return new ResponseEntity(HttpStatus.ACCEPTED); } catch (DrinkNotFoundException dex) { return new ResponseEntity(HttpStatus.NOT_FOUND); } }
From source file:com.bill99.yn.webmgmt.functional.rest.TaskRestFT.java
@Test public void invalidInput() { // create//from w w w .j a v a 2s. c om Task titleBlankTask = new Task(); try { restTemplate.postForLocation(resoureUrl, titleBlankTask); fail("Create should fail while title is blank"); } catch (HttpStatusCodeException e) { assertThat(e.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); Map messages = jsonMapper.fromJson(e.getResponseBodyAsString(), Map.class); assertThat(messages).hasSize(1); assertThat(messages.get("title")).isIn("may not be empty", "?"); } // update titleBlankTask.setId(1L); try { restTemplate.put(resoureUrl + "/1", titleBlankTask); fail("Update should fail while title is blank"); } catch (HttpStatusCodeException e) { assertThat(e.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); Map messages = jsonMapper.fromJson(e.getResponseBodyAsString(), Map.class); assertThat(messages).hasSize(1); assertThat(messages.get("title")).isIn("may not be empty", "?"); } }
From source file:plbtw.klmpk.barang.hilang.controller.KategoriBarangController.java
@RequestMapping(method = RequestMethod.DELETE, produces = "application/json") public CustomResponseMessage deleteKategoriBarang(@RequestBody KategoriBarangRequest kategoriBarangRequest) { try {/*from www .jav a 2 s .c om*/ kategoriBarangService.deleteKategoriBarang(kategoriBarangRequest.getId()); return new CustomResponseMessage(HttpStatus.CREATED, "Delete Kategori Barang Succesfull"); } catch (Exception ex) { return new CustomResponseMessage(HttpStatus.BAD_REQUEST, ex.toString()); } }