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:csns.web.controller.ProgramControllerS.java
@RequestMapping("/department/{dept}/program/addCourse") @ResponseBody/*from w ww .ja v a2 s .c o m*/ public ResponseEntity<String> addCourse(@ModelAttribute("program") Program program, @RequestParam Long courseId, @RequestParam String courseType) { Course course = courseDao.getCourse(courseId); if (program.contains(course)) return new ResponseEntity<String>(HttpStatus.BAD_REQUEST); if (courseType.equalsIgnoreCase("required")) program.getRequiredCourses().add(course); else program.getElectiveCourses().add(course); logger.info(SecurityUtils.getUser().getUsername() + " added " + courseType + " course " + courseId + " to program " + program.getId()); return new ResponseEntity<String>(HttpStatus.OK); }
From source file:com.alexshabanov.springrestapi.support.ProfileController.java
@ExceptionHandler(IllegalArgumentException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseBody// w ww. j av a2 s . c om public ErrorDesc handleIllegalArgumentException() { return new ErrorDesc(); }
From source file:alfio.controller.api.admin.AdditionalServiceApiController.java
@ExceptionHandler({ IllegalArgumentException.class }) public ResponseEntity<String> handleBadRequest(Exception e) { log.warn("bad input detected", e); return new ResponseEntity<>("bad input parameters", HttpStatus.BAD_REQUEST); }
From source file:fi.helsinki.opintoni.exception.GlobalExceptionHandlers.java
@ExceptionHandler(value = BadRequestException.class) public ResponseEntity<CommonError> handleBadRequest() throws Exception { return new ResponseEntity<>(new CommonError("Bad request"), HttpStatus.BAD_REQUEST); }
From source file:com.pw.ism.controllers.CommunicationController.java
@RequestMapping(value = "/addheartbeat", method = RequestMethod.POST, headers = { "Content-type=application/json" }) public ResponseEntity<String> addHeartbeat(@Valid @RequestBody Heartbeat hb, BindingResult bindingResult) { if (bindingResult.hasErrors()) { LOGGER.info("Bad request!"); return new ResponseEntity<>("NOK!", HttpStatus.BAD_REQUEST); } else {/*ww w . j a va 2 s. c om*/ heartbeatRepository.addHeartbeat(hb, Instant.now()); return new ResponseEntity<>("OK", HttpStatus.OK); } }
From source file:com.wisemapping.rest.BaseController.java
@ExceptionHandler(ValidationException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public RestErrors handleValidationErrors(@NotNull ValidationException ex) { return new RestErrors(ex.getErrors(), messageSource); }
From source file:br.com.s2it.snakes.controllers.CarController.java
@CrossOrigin("*") @RequestMapping(value = "/checklist/{licensePlate}", method = RequestMethod.PUT) public ResponseEntity<Car> doChecklist(final @RequestBody CarCheckList checklist, final @PathVariable(value = "licensePlate") String licensePlate) { if (licensePlate == null || licensePlate.isEmpty() || checklist == null) return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null); try {/*from www .j av a 2 s.c om*/ Car car = service.findByLicensePlate(licensePlate); if (car.getChecklist() == null) car.setChecklist(new ArrayList<>()); car.getChecklist().add(checklist); return ResponseEntity.status(HttpStatus.OK).body(service.save(car)); } catch (Exception e) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null); } }
From source file:com.stormpath.spring.boot.examples.filter.ReCaptchaFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { if (!(req instanceof HttpServletRequest) || !("POST".equalsIgnoreCase(((HttpServletRequest) req).getMethod()))) { chain.doFilter(req, res);// www . j av a 2s .com return; } PostMethod method = new PostMethod(RECAPTCHA_URL); method.addParameter("secret", RECAPTCHA_SECRET); method.addParameter("response", req.getParameter(RECAPTCHA_RESPONSE_PARAM)); method.addParameter("remoteip", req.getRemoteAddr()); HttpClient client = new HttpClient(); client.executeMethod(method); BufferedReader br = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); String readLine; StringBuffer response = new StringBuffer(); while (((readLine = br.readLine()) != null)) { response.append(readLine); } JSONObject jsonObject = new JSONObject(response.toString()); boolean success = jsonObject.getBoolean("success"); if (success) { chain.doFilter(req, res); } else { ((HttpServletResponse) res).sendError(HttpStatus.BAD_REQUEST.value(), "Bad ReCaptcha"); } }
From source file:net.maritimecloud.identityregistry.controllers.BaseControllerWithCertificate.java
protected PemCertificate issueCertificate(CertificateModel certOwner, Organization org, String type, HttpServletRequest request) throws McBasicRestException { // Generate keypair for user KeyPair userKeyPair = CertificateUtil.generateKeyPair(); // Find special MC attributes to put in the certificate HashMap<String, String> attrs = getAttr(certOwner); String o = org.getMrn();/*ww w. ja va 2 s . c o m*/ String name = getName(certOwner); String email = getEmail(certOwner); String uid = getUid(certOwner); if (uid == null || uid.trim().isEmpty()) { throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.ENTITY_ORG_ID_MISSING, request.getServletPath()); } BigInteger serialNumber = certUtil.generateSerialNumber(); X509Certificate userCert = certUtil.generateCertForEntity(serialNumber, org.getCountry(), o, type, name, email, uid, userKeyPair.getPublic(), attrs); String pemCertificate; try { pemCertificate = CertificateUtil.getPemFromEncoded("CERTIFICATE", userCert.getEncoded()).replace("\n", "\\n"); } catch (CertificateEncodingException e) { throw new RuntimeException(e.getMessage(), e); } String pemPublicKey = CertificateUtil.getPemFromEncoded("PUBLIC KEY", userKeyPair.getPublic().getEncoded()) .replace("\n", "\\n"); String pemPrivateKey = CertificateUtil .getPemFromEncoded("PRIVATE KEY", userKeyPair.getPrivate().getEncoded()).replace("\n", "\\n"); PemCertificate ret = new PemCertificate(pemPrivateKey, pemPublicKey, pemCertificate); // Create the certificate Certificate newMCCert = new Certificate(); certOwner.assignToCert(newMCCert); newMCCert.setCertificate(pemCertificate); newMCCert.setSerialNumber(serialNumber); // The dates we extract from the cert is in localtime, so they are converted to UTC before saving into the DB Calendar cal = Calendar.getInstance(); long offset = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET); newMCCert.setStart(new Date(userCert.getNotBefore().getTime() - offset)); newMCCert.setEnd(new Date(userCert.getNotAfter().getTime() - offset)); this.certificateService.saveCertificate(newMCCert); return ret; }
From source file:de.sainth.recipe.backend.rest.controller.BasicUnitController.java
@Secured("ROLE_ADMIN") @RequestMapping(value = "{shortname}", method = RequestMethod.PUT) HttpEntity<BasicUnit> update(@PathVariable("shortname") String shortname, @Valid @RequestBody BasicUnit basicUnit) { if (shortname.equals(basicUnit.getShortname())) { if (repository.findOne(basicUnit.getShortname()) != null) { repository.save(basicUnit);//from www. ja v a2 s . com return new ResponseEntity<>(basicUnit, HttpStatus.OK); } } return new ResponseEntity<>(HttpStatus.BAD_REQUEST); }