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:org.swarmcom.jsynapse.controller.client.api.v1.AuthenticationRestApiTest.java
@Test public void testMissingKeys() throws Exception { postAndCheckStatus("/_matrix/client/api/v1/register", postMisingKeys, HttpStatus.BAD_REQUEST); postAndCheckStatus("/_matrix/client/api/v1/login", postMisingKeys, HttpStatus.BAD_REQUEST); }
From source file:locksdemo.LocksController.java
@ExceptionHandler(LockExistsException.class) @ResponseBody//from w w w .j av a 2 s. c o m public ResponseEntity<Map<String, Object>> lockExists() { Map<String, Object> body = new HashMap<String, Object>(); body.put("status", "INVALID"); body.put("description", "Lock already exists"); return new ResponseEntity<Map<String, Object>>(body, HttpStatus.BAD_REQUEST); }
From source file:com.chevres.rss.restapi.controller.UserController.java
@CrossOrigin @RequestMapping(path = "/user/{username}", method = RequestMethod.GET) @ResponseBody/*w ww . j a v a 2 s .c om*/ public ResponseEntity<String> getUser(@RequestHeader(value = "User-token") String userToken, @PathVariable String username) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); UserDAO userDAO = context.getBean(UserDAO.class); UserAuthDAO userAuthDAO = context.getBean(UserAuthDAO.class); UserAuth userAuth = userAuthDAO.findByToken(userToken); if (userAuth == null) { context.close(); return new ResponseEntity(new ErrorMessageResponse("invalid_token"), HttpStatus.BAD_REQUEST); } User user = userDAO.findByUsername(username); if (user == null) { context.close(); return new ResponseEntity(HttpStatus.NOT_FOUND); } boolean isAdmin = userDAO.isAdmin(userAuth.getIdUser()); if (!isAdmin && (userAuth.getIdUser() != user.getId())) { return new ResponseEntity(new ErrorMessageResponse("admin_required"), HttpStatus.FORBIDDEN); } context.close(); return new ResponseEntity(new SuccessGetUserResponse(user.getUsername(), user.getType()), HttpStatus.OK); }
From source file:com.acc.controller.VouchersController.java
/** * Handles Vouchers controller specific exceptions * //from ww w.j av a 2 s . c o m * @param excp * to support basic exception marshaling to JSON and XML. It will determine the format based on the * request's Accept header. * @param request * @param writer * @throws java.io.IOException * * @return {@link com.acc.error.data.ErrorData} as a response body */ @ResponseStatus(value = HttpStatus.BAD_REQUEST) @ResponseBody @ExceptionHandler({ VoucherOperationException.class }) public ErrorData handleCartException(final Exception excp, final HttpServletRequest request, final Writer writer) throws IOException { LOG.info("Handling Exception for this request - " + excp.getClass().getSimpleName() + " - " + excp.getMessage()); if (LOG.isDebugEnabled()) { LOG.debug(excp); } final ErrorData errorData = handleErrorInternal(excp.getClass().getSimpleName(), excp.getMessage()); return errorData; }
From source file:br.upe.community.ui.ControllerDoacao.java
@RequestMapping(value = "/remover", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ResponseEntity<?> removerDoacao(long id) { try {//from ww w. ja va 2 s . c o m fachada.removerDoacao(id); return new ResponseEntity<String>(HttpStatus.OK); } catch (DoacaoInexistenteException e) { return new ResponseEntity<DoacaoInexistenteException>(e, HttpStatus.BAD_REQUEST); } }
From source file:eu.freme.broker.eservices.EPublishing.java
@RequestMapping(value = "/e-publishing/html", method = RequestMethod.POST) public ResponseEntity<byte[]> htmlToEPub(@RequestParam("htmlZip") MultipartFile file, @RequestParam("metadata") String jMetadata) throws InvalidZipException, EPubCreationException, IOException, MissingMetadataException { if (file.getSize() > maxUploadSize) { double size = maxUploadSize / (1024.0 * 1024); return new ResponseEntity<>(new byte[0], HttpStatus.BAD_REQUEST); //throw new BadRequestException(String.format("The uploaded file is too large. The maximum file size for uploads is %.2f MB", size)); }//from ww w.j a va2 s . c om Gson gson = new Gson(); Metadata metadata = gson.fromJson(jMetadata, Metadata.class); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.add("Content-Type", "application/epub+zip"); try { return new ResponseEntity<>(entityAPI.createEPUB(metadata, file.getInputStream()), HttpStatus.OK); } catch (InvalidZipException | EPubCreationException | IOException | MissingMetadataException ex) { logger.log(Level.SEVERE, ex.getMessage()); throw ex; } }
From source file:io.syndesis.runtime.ConnectionsITCase.java
@Test public void nullNamesShouldNotBeAllowed() { final Connection connection = new Connection.Builder().build(); final ResponseEntity<List<Violation>> got = post("/api/v1/connections/validation", connection, RESPONSE_TYPE, tokenRule.validToken(), HttpStatus.BAD_REQUEST); assertThat(got.getBody()).containsExactly( new Violation.Builder().property("name").error("NotNull").message("Value is required").build()); }
From source file:org.cloudfoundry.identity.uaa.codestore.CodeStoreEndpoints.java
@RequestMapping(value = { "/Codes" }, method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED)//from w w w . j a va 2s .c om @ResponseBody public ExpiringCode generateCode(@RequestBody ExpiringCode expiringCode) { try { return expiringCodeStore.generateCode(expiringCode.getData(), expiringCode.getExpiresAt()); } catch (NullPointerException e) { throw new CodeStoreException("data and expiresAt are required.", HttpStatus.BAD_REQUEST); } catch (IllegalArgumentException e) { throw new CodeStoreException("expiresAt must be in the future.", HttpStatus.BAD_REQUEST); } catch (DataIntegrityViolationException e) { throw new CodeStoreException("Duplicate code generated.", HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:com.haulmont.restapi.controllers.FileDownloadController.java
@GetMapping("/{fileDescriptorId}") public void downloadFile(@PathVariable String fileDescriptorId, @RequestParam(required = false) Boolean attachment, HttpServletResponse response) { UUID uuid;// w w w . j a v a2 s. co m try { uuid = UUID.fromString(fileDescriptorId); } catch (IllegalArgumentException e) { throw new RestAPIException("Invalid entity ID", String.format("Cannot convert %s into valid entity ID", fileDescriptorId), HttpStatus.BAD_REQUEST); } LoadContext<FileDescriptor> ctx = LoadContext.create(FileDescriptor.class).setId(uuid); FileDescriptor fd = dataService.load(ctx); if (fd == null) { throw new RestAPIException("File not found", "File not found. Id: " + fileDescriptorId, HttpStatus.NOT_FOUND); } try { response.setHeader("Cache-Control", "no-cache"); response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", 0); response.setHeader("Content-Type", getContentType(fd)); response.setHeader("Content-Disposition", (BooleanUtils.isTrue(attachment) ? "attachment" : "inline") + "; filename=\"" + fd.getName() + "\""); downloadFromMiddlewareAndWriteResponse(fd, response); } catch (Exception e) { log.error("Error on downloading the file {}", fileDescriptorId, e); throw new RestAPIException("Error on downloading the file", "", HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:com.marklogic.samplestack.web.security.ExceptionAdvice.java
/** * Unsupported method should return 400 and a JSON body. * /* w ww . java 2 s . c om*/ * @param ex * Exception that triggers a 400. * @return A JSON message body and 400 response code. */ @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(SamplestackIOException.class) public @ResponseBody JsonNode handleIOException(Exception ex) { return errors.makeJsonResponse(400, ex.getMessage()); }