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.mitre.openid.connect.web.WhitelistAPI.java
/** * Create a new whitelisted site/*from w w w . jav a 2 s. com*/ * @param jsonString * @param m * @param p * @return */ @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public String addNewWhitelistedSite(@RequestBody String jsonString, ModelMap m, Principal p) { JsonObject json; WhitelistedSite whitelist = null; try { json = parser.parse(jsonString).getAsJsonObject(); whitelist = gson.fromJson(json, WhitelistedSite.class); } catch (JsonParseException e) { logger.error("addNewWhitelistedSite failed due to JsonParseException", e); m.addAttribute(HttpCodeView.CODE, HttpStatus.BAD_REQUEST); m.addAttribute(JsonErrorView.ERROR_MESSAGE, "Could not save new whitelisted site. The server encountered a JSON syntax exception. Contact a system administrator for assistance."); return JsonErrorView.VIEWNAME; } catch (IllegalStateException e) { logger.error("addNewWhitelistedSite failed due to IllegalStateException", e); m.addAttribute(HttpCodeView.CODE, HttpStatus.BAD_REQUEST); m.addAttribute(JsonErrorView.ERROR_MESSAGE, "Could not save new whitelisted site. The server encountered an IllegalStateException. Refresh and try again - if the problem persists, contact a system administrator for assistance."); return JsonErrorView.VIEWNAME; } // save the id of the person who created this whitelist.setCreatorUserId(p.getName()); WhitelistedSite newWhitelist = whitelistService.saveNew(whitelist); m.put(JsonEntityView.ENTITY, newWhitelist); return JsonEntityView.VIEWNAME; }
From source file:reconf.server.services.product.UpsertProductService.java
private ResponseEntity<ProductResult> checkForErrors(Authentication auth, Product reqProduct, List<String> users) { List<String> errors = DomainValidator.checkForErrors(reqProduct); if (CollectionUtils.isNotEmpty(users)) { for (String user : users) { if (!appSecurity.userExists(user)) { errors.add("user " + user + " does not exist"); }//w w w .j a va 2s. c o m } } if (!errors.isEmpty()) { return new ResponseEntity<ProductResult>(new ProductResult(reqProduct, errors), HttpStatus.BAD_REQUEST); } return null; }
From source file:com.baby.web.DisconnectController.java
@RequestMapping(method = RequestMethod.POST) public ResponseEntity<String> disconnect(@RequestParam("signed_request") String signedRequest) { try {//from w w w . ja v a 2 s .c o m String userId = getUserId(signedRequest); logger.info( "Deauthorization request received for Facebook User ID: " + userId + "; Removing connections."); Set<String> providerUserIds = new HashSet<String>(); providerUserIds.add(userId); Set<String> localUserIds = usersConnectionRepository.findUserIdsConnectedTo("facebook", providerUserIds); for (String localUserId : localUserIds) { ConnectionRepository connectionRepository = usersConnectionRepository .createConnectionRepository(localUserId); logger.info(" Removing Facebook connection for local user '" + localUserId + "'"); connectionRepository.removeConnection(new ConnectionKey("facebook", userId)); } return new ResponseEntity<String>(HttpStatus.NO_CONTENT); } catch (SignedRequestException e) { return new ResponseEntity<String>(HttpStatus.BAD_REQUEST); } }
From source file:cn.org.once.cstack.config.RestHandlerException.java
@Override protected ResponseEntity<Object> handleHttpMessageNotReadable(HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { ex.printStackTrace();//from w ww. j ava2s . c o m headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return handleExceptionInternal(ex, new HttpErrorServer(ex.getLocalizedMessage()), headers, HttpStatus.BAD_REQUEST, request); }
From source file:net.ljcomputing.core.controler.GlobalExceptionController.java
/** * Handle all required value exceptions. * * @param req the req/*from www . jav a2s . c o m*/ * @param exception the exception * @return the error info */ @Order(Ordered.HIGHEST_PRECEDENCE) @ExceptionHandler(RequiredValueException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public @ResponseBody ErrorInfo handleAllRequiredValueExceptions(HttpServletRequest req, Exception exception) { logger.warn("A required value is missing : {}:", req.getRequestURL().toString()); return new ErrorInfo(getCurrentTimestamp(), HttpStatus.BAD_REQUEST, req.getRequestURL().toString(), exception); }
From source file:io.kahu.hawaii.rest.DefaultResponseManager.java
@Override public ResponseEntity<String> toResponse(Throwable throwable) { /**//from w ww .ja v a2s . c om * This method is activated as a final step method-execution * (exception-handling) before control is given back to the container * and can therefore not assert that the supplied exception is not null */ if (throwable == null) { return toResponse(new ServerException(ServerError.ILLEGAL_ARGUMENT)); } if (!(throwable instanceof HawaiiException)) { return toResponse(new ServerException(ServerError.UNEXPECTED_EXCEPTION, throwable)); } if (mustLog(throwable)) { logManager.debug(CoreLoggers.SERVER_EXCEPTION, throwable.getMessage(), throwable); } HawaiiException exception = (HawaiiException) throwable; /** * The alternative was to have the HawaiiException try-catch the * json-exceptions (and possible other runtime exceptions) and log the * error. That created the side-effect that the LogManager (no longer * static) needed to be inserted into every newly created instance of * the HawaiiException. There are ways to do that with Spring (at this * moment not known to me) but this solution feels better after all. */ JSONObject response = new JSONObject(); try { response.put(STATUS_KEY, exception.getStatus().value()); response.put(DATA_KEY, new JSONArray()); response.put(ERROR_KEY, exception.toJson()); } catch (Throwable very_unlikely) { logManager.error(new ServerException(ServerError.UNEXPECTED_EXCEPTION, very_unlikely)); } if (throwable instanceof ValidationException) { try { logManager.logIncomingCallEnd(HttpStatus.BAD_REQUEST.value(), response.toString(2)); } catch (Throwable very_unlikely) { logManager.error(new ServerException(ServerError.UNEXPECTED_EXCEPTION, very_unlikely)); } } else if (throwable instanceof AuthorisationException) { logManager.logIncomingCallEnd(HttpStatus.OK.value(), throwable.getMessage()); } else { logManager.logIncomingCallEnd(exception); } return myToResponse(response); }
From source file:com.logsniffer.web.controller.exception.RestErrorHandler.java
@ExceptionHandler(HttpMessageConversionException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseBody/* w ww .j av a 2 s . c o m*/ public ErrorResponse processHttpMessageConversionError(final HttpMessageConversionException ex, final HttpServletResponse response) throws IOException { return processExceptionResponse(ex, response, org.apache.http.HttpStatus.SC_BAD_REQUEST); }
From source file:io.syndesis.runtime.ConnectionsITCase.java
@Test public void shouldDetermineValidityForInvalidConnections() { final Connection connection = new Connection.Builder().name("Existing connection").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("UniqueProperty") .message("Value 'Existing connection' is not unique").build()); }
From source file:org.venice.piazza.servicecontroller.messaging.handlers.UpdateServiceHandler.java
/** * Handler for the RegisterServiceJob that was submitted. Stores the metadata in MongoDB * @see org.venice.piazza.servicecontroller.messaging.handlers.Handler#handle(model.job.PiazzaJobType) *//*from www .ja va 2s .c om*/ public ResponseEntity<String> handle(PiazzaJobType jobRequest) { LOGGER.debug("Updating a service"); UpdateServiceJob job = (UpdateServiceJob) jobRequest; if (job != null) { // Get the ResourceMetadata Service sMetadata = job.data; LOGGER.info("serviceMetadata received is " + sMetadata); coreLogger.log("serviceMetadata received is " + sMetadata, Severity.INFORMATIONAL); String result = handle(sMetadata); if (result.length() > 0) { String jobId = job.getJobId(); // TODO Use the result, send a message with the resource Id and jobId ArrayList<String> resultList = new ArrayList<>(); resultList.add(jobId); resultList.add(sMetadata.getServiceId()); return new ResponseEntity<String>(resultList.toString(), HttpStatus.OK); } else { coreLogger.log("No result response from the handler, something went wrong", Severity.ERROR); return new ResponseEntity<String>("UpdateServiceHandler handle didn't work", HttpStatus.UNPROCESSABLE_ENTITY); } } else { coreLogger.log("A null PiazzaJobRequest was passed in. Returning null", Severity.ERROR); return new ResponseEntity<String>("A Null PiazzaJobRequest was received", HttpStatus.BAD_REQUEST); } }
From source file:hr.foi.rsc.controllers.PersonController.java
/** * inserts new user to database/*w w w. ja va 2s. com*/ * @param person user to insert * @return person info and HTTP 200 on success or HTTP BAD REQUEST on fail */ @RequestMapping(value = "/signup", method = RequestMethod.POST) public ResponseEntity<Person> signup(@RequestBody Person person) { Logger.getLogger("PersonController.java").log(Level.INFO, "POST on /person/signup -- " + person.toString()); Person signed = this.personRepository.save(person); if (signed != null) { Logger.getLogger("PersonController.java").log(Level.INFO, "Registration success for " + signed.toString()); return new ResponseEntity(signed, HttpStatus.OK); } else { Logger.getLogger("PersonController.java").log(Level.WARN, "Registration failed for " + person.toString()); return new ResponseEntity(HttpStatus.BAD_REQUEST); } }