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.chevres.rss.restapi.controller.UserController.java
@CrossOrigin @RequestMapping(path = "/user/{username}", method = RequestMethod.PUT) @ResponseBody/*from ww w.ja v a 2 s.c o m*/ public ResponseEntity<String> updateUser(@RequestHeader(value = "User-token") String userToken, @PathVariable String username, @RequestBody User userRequest, BindingResult bindingResult) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); UserDAO userDAO = context.getBean(UserDAO.class); UserAuthDAO userAuthDAO = context.getBean(UserAuthDAO.class); userUpdateValidator.validate(userRequest, bindingResult); if (bindingResult.hasErrors()) { context.close(); return new ResponseEntity(new ErrorMessageResponse("bad_params"), HttpStatus.BAD_REQUEST); } 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())) || (userRequest.getType() != null && !isAdmin)) { context.close(); return new ResponseEntity(new ErrorMessageResponse("admin_required"), HttpStatus.FORBIDDEN); } if (userDAO.doesExist(userRequest.getUsername()) && !user.getUsername().equalsIgnoreCase(userRequest.getUsername())) { context.close(); return new ResponseEntity(new ErrorMessageResponse("already_exist"), HttpStatus.BAD_REQUEST); } userDAO.updateUser(user, userRequest, isAdmin); context.close(); return new ResponseEntity(new SuccessMessageResponse("success"), HttpStatus.OK); }
From source file:org.mitre.uma.web.ResourceSetRegistrationEndpoint.java
@RequestMapping(method = RequestMethod.POST, produces = MimeTypeUtils.APPLICATION_JSON_VALUE, consumes = MimeTypeUtils.APPLICATION_JSON_VALUE) public String createResourceSet(@RequestBody String jsonString, Model m, Authentication auth) { ensureOAuthScope(auth, SystemScopeService.UMA_PROTECTION_SCOPE); ResourceSet rs = parseResourceSet(jsonString); if (rs == null) { // there was no resource set in the body logger.warn("Resource set registration missing body."); m.addAttribute("code", HttpStatus.BAD_REQUEST); m.addAttribute("error_description", "Resource request was missing body."); return JsonErrorView.VIEWNAME; }//from ww w . j a v a 2 s.co m if (auth instanceof OAuth2Authentication) { // if it's an OAuth mediated call, it's on behalf of a client, so store that OAuth2Authentication o2a = (OAuth2Authentication) auth; rs.setClientId(o2a.getOAuth2Request().getClientId()); rs.setOwner(auth.getName()); // the username is going to be in the auth object } else { // this one shouldn't be called if it's not OAuth m.addAttribute(HttpCodeView.CODE, HttpStatus.BAD_REQUEST); m.addAttribute(JsonErrorView.ERROR_MESSAGE, "This call must be made with an OAuth token"); return JsonErrorView.VIEWNAME; } rs = validateScopes(rs); if (Strings.isNullOrEmpty(rs.getName()) // there was no name (required) || rs.getScopes() == null // there were no scopes (required) ) { logger.warn("Resource set registration missing one or more required fields."); m.addAttribute(HttpCodeView.CODE, HttpStatus.BAD_REQUEST); m.addAttribute(JsonErrorView.ERROR_MESSAGE, "Resource request was missing one or more required fields."); return JsonErrorView.VIEWNAME; } ResourceSet saved = resourceSetService.saveNew(rs); m.addAttribute(HttpCodeView.CODE, HttpStatus.CREATED); m.addAttribute(JsonEntityView.ENTITY, saved); m.addAttribute(ResourceSetEntityAbbreviatedView.LOCATION, config.getIssuer() + URL + "/" + saved.getId()); return ResourceSetEntityAbbreviatedView.VIEWNAME; }
From source file:com.github.lynxdb.server.api.http.handlers.EpVhost.java
@RequestMapping(value = "/{vhostUUID}/user", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity listUser(Authentication _authentication, @PathVariable("vhostUUID") UUID vhostId) { Vhost vhost = vhosts.byId(vhostId);//from w w w . j a v a 2s.com if (vhost == null) { return new ErrorResponse(mapper, HttpStatus.BAD_REQUEST, "Vhost does not exist.", null).response(); } List<User> userList = users.byVhost(vhost); return ResponseEntity.ok(userList); }
From source file:com.mum.controller.CardRestController.java
@ExceptionHandler(IllegalArgumentException.class) @ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "Illegal request, please verify your payload") public void handleClientErrors(Exception ex) { }
From source file:org.esbtools.gateway.resubmit.controller.ResubmitGateway.java
@ExceptionHandler(IncompleteRequestException.class) private ResponseEntity<ResubmitResponse> incompleteRequestExceptionHandler(IncompleteRequestException e) { ResubmitResponse resubmitResponse = new ResubmitResponse(GatewayResponse.Status.Error, e.getMessage()); return new ResponseEntity<>(resubmitResponse, HttpStatus.BAD_REQUEST); }
From source file:com.ar.dev.tierra.api.controller.TransferenciaController.java
@RequestMapping(value = "/update", method = RequestMethod.POST) public ResponseEntity<?> update(@RequestBody Transferencia transferencia, OAuth2Authentication authentication) { Usuarios user = facadeService.getUsuariosDAO().findUsuarioByUsername(authentication.getName()); transferencia.setFechaModificacion(new Date()); transferencia.setEstadoPedido(true); transferencia.setUsuarioModificacion(user.getIdUsuario()); transferencia.setSucursalRespuesta(user.getUsuarioSucursal().getIdSucursal()); if (transferencia.getSucursalPedido() != user.getUsuarioSucursal().getIdSucursal()) { facadeService.getTransferenciaDAO().add(transferencia); return new ResponseEntity<>(HttpStatus.OK); } else {/*from w ww. j a v a 2 s .c o m*/ JsonResponse response = new JsonResponse("Error", "No puedes confirmar tu propia transferencia."); return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); } }
From source file:resources.RedSocialColaborativaRESTFUL.java
/** * * @param _usuario/*from w w w .j av a2s.co m*/ * @return */ @RequestMapping(value = "/perfil/acceso", method = RequestMethod.POST, consumes = "application/json") public ResponseEntity<String> solicitudAcceso(@RequestBody NuevoUsuarioDTO _usuario) { if (!_usuario.getMail().equals(_usuario.getConfMail())) { return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } else if (!_usuario.getPassword().equals(_usuario.getConfPassword())) { return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } try { red.solicitarAcceso(_usuario.getUsername(), _usuario.getMail(), _usuario.getPassword()); } catch (RuntimeException e) { //codigo 409 return new ResponseEntity<>(HttpStatus.CONFLICT); } return new ResponseEntity<>(HttpStatus.OK); }
From source file:br.com.modoagil.asr.rest.support.RESTErrorHandler.java
/** * Manipula exceo de validao de objetos nos servios * * @param ex/*w ww . j a va 2s . c o m*/ * {@link MethodArgumentNotValidException} * @return resposta ao cliente */ @ResponseBody @ExceptionHandler(MethodArgumentNotValidException.class) public Response<E> processMethodArgumentNotValidException(final MethodArgumentNotValidException ex) { this.logger.info("handleMethodArgumentNotValidException - Catching: " + ex.getClass().getSimpleName(), ex); final BindingResult result = ex.getBindingResult(); final FieldError fieldError = result.getFieldError(); final String message = this.messageSource.getMessage(fieldError.getDefaultMessage(), null, null); return new ResponseBuilder<E>().success(false).status(HttpStatus.BAD_REQUEST).message(message).build(); }
From source file:org.akaademiwolof.ConfigurationTests.java
@SuppressWarnings("static-access") //@Test// ww w.j a va 2 s.c om public void shouldUpdateWordWhenSendingRequestToController() throws Exception { HttpHeaders headers = new HttpHeaders(); JSONObject requestJson = new JSONObject(); requestJson.wrap(json); System.out.print(requestJson.toString()); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> entity = new HttpEntity<String>(json, headers); ResponseEntity<String> loginResponse = restTemplate.exchange(localhostUrl, HttpMethod.POST, entity, String.class); if (loginResponse.getStatusCode() == HttpStatus.OK) { JSONObject wordJson = new JSONObject(loginResponse.getBody()); System.out.print(loginResponse.getStatusCode()); assertThat(wordJson != null); } else if (loginResponse.getStatusCode() == HttpStatus.BAD_REQUEST) { System.out.print(loginResponse.getStatusCode()); } }
From source file:ru.portal.controllers.RestController.java
@ExceptionHandler(Exception.class) ResponseEntity<String> handelExceptions(Exception e) { String result = e.getMessage(); return new ResponseEntity<>(result, HttpStatus.BAD_REQUEST); }