Example usage for org.springframework.http HttpStatus BAD_REQUEST

List of usage examples for org.springframework.http HttpStatus BAD_REQUEST

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus BAD_REQUEST.

Prototype

HttpStatus BAD_REQUEST

To view the source code for org.springframework.http HttpStatus BAD_REQUEST.

Click Source Link

Document

400 Bad Request .

Usage

From source file:io.spring.initializr.web.project.AbstractInitializrController.java

@ExceptionHandler
public void invalidProjectRequest(HttpServletResponse response, InvalidProjectRequestException ex)
        throws IOException {
    response.sendError(HttpStatus.BAD_REQUEST.value(), ex.getMessage());
}

From source file:hr.foi.sis.controllers.TestDataController.java

@RequestMapping(value = "/add", method = RequestMethod.POST)
@PreAuthorize("isAuthenticated()")
public ResponseEntity addData(@RequestBody TestData data) {

    Logger.getLogger("TestDataController.java").log(Level.INFO, "POST on /testdata/ ");

    Person creator = (Person) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

    Logger.getLogger("TestDataController.java").log(Level.INFO,
            "POST on /testdata/ for user" + creator.getName());

    data.setPerson(creator);/*  w w  w  .  ja  v a 2  s  .  c  om*/

    TestData saved = this.testDataRepository.save(data);

    if (saved != null)
        return new ResponseEntity(HttpStatus.OK);
    else
        return new ResponseEntity(HttpStatus.BAD_REQUEST);

}

From source file:com.envision.envservice.rest.PictureUploadResource.java

@POST
@Consumes(MediaType.APPLICATION_JSON)/*from www. j a  va  2s. c  om*/
@Produces(MediaType.APPLICATION_JSON)
public Response addNew(ClgPictureBo clgPicture) throws Exception {
    HttpStatus status = HttpStatus.CREATED;
    String response = StringUtils.EMPTY;
    if (!checkParam(clgPicture)) {
        status = HttpStatus.BAD_REQUEST;
        response = FailResult.toJson(Code.PARAM_ERROR, "?");
    } else {
        List<ClgPicture> list = ClgPictureService.addClgPicture(clgPicture);
        List<Map> maplist = new ArrayList<Map>();
        for (int i = 0; i < list.size(); i++) {
            Map map = new HashMap();
            map.put("id", list.get(i).getId().toString());
            maplist.add(map);
        }
        response = JSONObject.toJSONString(maplist, JSONFilter.UNDERLINEFILTER);
        return Response.status(status.value()).entity(response).build();
    }

    return null;
}

From source file:ch.heigvd.gamification.api.LeaderboardEndpoint.java

@Override
public ResponseEntity<LeaderboardDTO> leaderboardGet(
        @ApiParam(value = "token that identifies the app sending the request", required = true) @RequestHeader(value = "X-Gamification-Token", required = true) String xGamificationToken) {
    AuthenKey apiKey = authenKeyRepository.findByAppKey(xGamificationToken);

    if (apiKey == null) {
        return new ResponseEntity("apikey not exist", HttpStatus.BAD_REQUEST);
    }/*from ww  w. jav  a 2 s  . c  om*/
    Application app = apiKey.getApp();

    if (app != null) {

        List<LeaderboardDTO> results = new ArrayList<>();
        List<Object[]> endUsers = new ArrayList<>();

        endUsers = endUserRepository.getBestUsers(app);

        if (endUsers.isEmpty()) {
            endUsers = endUserRepository.getBestBadgeUsers(app);
            for (int i = 0; i < endUsers.size(); ++i) {
                LeaderboardDTO tmp = new LeaderboardDTO();
                EndUser enduser = (EndUser) endUsers.get(i)[0];

                tmp.setName(enduser.getName());
                tmp.setEndUserId(enduser.getId());
                List<String> names = new ArrayList<>();
                for (BadgeAward badge : enduser.getBadgeAwards()) {
                    names.add(badge.getBadge().getName());
                }
                tmp.setBadges(names);

                if (!results.contains(tmp)) {
                    results.add(tmp);
                }
            }

            return new ResponseEntity(results, HttpStatus.OK);
        }

        System.out.println("la taille de l'objet" + endUsers.size());
        PointScale pointscale = new PointScale();

        for (int i = 0; i < endUsers.size(); ++i) {

            Long somme = 0l;
            LeaderboardDTO tmp = new LeaderboardDTO();
            EndUser enduser = (EndUser) endUsers.get(i)[0];
            tmp.setName(enduser.getName());
            tmp.setEndUserId(enduser.getId());
            somme = (Long) endUsers.get(i)[2];
            tmp.setPoints(somme.intValue());
            pointscale = (PointScale) endUsers.get(i)[1];
            tmp.setNamePointscale(pointscale.getName());
            List<String> names = new ArrayList<>();
            System.err.println("version badge");
            for (BadgeAward badge : enduser.getBadgeAwards()) {
                names.add(badge.getBadge().getName());
            }

            tmp.setBadges(names);

            if (!results.contains(tmp)) {
                results.add(tmp);
            }
        }

        return new ResponseEntity(results, HttpStatus.OK);
    }

    return new ResponseEntity("content no available", HttpStatus.BAD_REQUEST);
}

From source file:org.osiam.resources.exception.OsiamExceptionHandler.java

@ExceptionHandler({ IllegalArgumentException.class, InvalidConstraintException.class })
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody/*w  w w. j a va  2  s  .com*/
public ErrorResponse handleInvalidConstraintException(Exception e) {
    return produceErrorResponse(e.getMessage(), HttpStatus.BAD_REQUEST);
}

From source file:org.openbaton.autoscaling.api.exceptions.GlobalExceptionHandler.java

@ExceptionHandler({ BadFormatException.class, NetworkServiceIntegrityException.class,
        WrongStatusException.class })
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
protected ResponseEntity<Object> handleInvalidRequest(Exception e, WebRequest request) {
    log.error("Exception with message " + e.getMessage() + " was thrown");
    ExceptionResource exc = new ExceptionResource("Bad Request", e.getMessage());
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);

    return handleExceptionInternal(e, exc, headers, HttpStatus.UNPROCESSABLE_ENTITY, request);
}

From source file:com.envision.envservice.rest.UserCasePriseResource.java

@POST
@Consumes(MediaType.APPLICATION_JSON)//from ww  w.ja  v a2  s  . co  m
@Produces(MediaType.APPLICATION_JSON)
public Response prise(UserCasePriseBo userCasePrise) throws Exception {
    HttpStatus status = HttpStatus.CREATED;
    String response = StringUtils.EMPTY;

    if (!checkParam(userCasePrise)) {
        status = HttpStatus.BAD_REQUEST;
        response = FailResult.toJson(Code.PARAM_ERROR, "?");
    } else {
        userCasePriseService.prise(userCasePrise);
    }

    return Response.status(status.value()).entity(response).build();
}

From source file:$.RestExceptionHandler.java

@ExceptionHandler(value = { ConstraintViolationException.class })
    public final ResponseEntity<?> handleException(ConstraintViolationException ex, WebRequest request) {
        Map<String, String> errors = BeanValidators.extractPropertyAndMessage(ex.getConstraintViolations());
        String body = jsonMapper.toJson(errors);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.parseMediaType(MediaTypes.TEXT_PLAIN_UTF_8));
        return handleExceptionInternal(ex, body, headers, HttpStatus.BAD_REQUEST, request);
    }/*from  www  . j  a  v  a  2 s . co m*/

From source file:edu.sjsu.cmpe275.project.controller.RoomController.java

/** Create a room
 * @param roomNo         Room No//from   ww w  . j ava 2  s. c om
 * @param roomType         Room Type
 * @param smoking         smoking, non-smoking
 * @param basePrice         Base Price
 * @return         void
 */

@RequestMapping(value = "", method = RequestMethod.POST)
public ResponseEntity<?> createRoom(@RequestParam(value = "room_no", required = true) String roomNo,
        @RequestParam(value = "room_type", required = true) Integer roomType,
        @RequestParam(value = "smoking", required = true) Boolean smoking,
        @RequestParam(value = "base_price", required = false) Integer basePrice) {

    Room room = new Room(roomNo, roomType, smoking, basePrice);
    room.setStatus(ROOM_STATUS.VACANT);
    room = roomDao.addRoom(room);
    if (room == null) {
        return new ResponseEntity<Object>(HttpStatus.BAD_REQUEST);
    } else {
        return new ResponseEntity<Object>(room, HttpStatus.OK);
    }
}

From source file:org.openbaton.vnfm.api.exceptions.GlobalExceptionHandler.java

@ExceptionHandler({ BadFormatException.class, NetworkServiceIntegrityException.class,
        WrongStatusException.class })
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
protected ResponseEntity<Object> handleInvalidRequest(Exception e, WebRequest request) {
    log.error("Exception with message " + e.getMessage() + " was thrown");
    ExceptionResource exc = new ExceptionResource("Bad Request", e.getMessage());
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);

    return handleExceptionInternal(e, exc, headers, HttpStatus.BAD_REQUEST, request);
}