Example usage for org.springframework.http HttpStatus NOT_FOUND

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

Introduction

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

Prototype

HttpStatus NOT_FOUND

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

Click Source Link

Document

404 Not Found .

Usage

From source file:cn.dsgrp.field.stock.functional.rest.TaskRestFT.java

/**
 * //.//ww  w  . j  a  v a2 s  .  c  o m
 */
@Test
@Category(Smoke.class)
public void createUpdateAndDeleteTask() {

    // create
    Task task = TaskData.randomTask();

    URI createdTaskUri = restTemplate.postForLocation(resourceUrl, task);
    System.out.println(createdTaskUri.toString());
    Task createdTask = restTemplate.getForObject(createdTaskUri, Task.class);
    assertThat(createdTask.getTitle()).isEqualTo(task.getTitle());

    // update
    String id = StringUtils.substringAfterLast(createdTaskUri.toString(), "/");
    task.setId(BigInteger.valueOf(Long.parseLong(id)));
    task.setTitle(TaskData.randomTitle());

    restTemplate.put(createdTaskUri, task);

    Task updatedTask = restTemplate.getForObject(createdTaskUri, Task.class);
    assertThat(updatedTask.getTitle()).isEqualTo(task.getTitle());

    // delete
    restTemplate.delete(createdTaskUri);

    try {
        restTemplate.getForObject(createdTaskUri, Task.class);
        fail("Get should fail while feth a deleted task");
    } catch (HttpStatusCodeException e) {
        assertThat(e.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
    }
}

From source file:com.iscas.rent.rest.UserRestController.java

@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaTypes.JSON_UTF_8)
public Account getnaem(@PathVariable("id") Long id) {
    Account user = userService.getUser(id);
    if (user == null) {
        String message = "?(id:" + id + ")";
        logger.warn(message);//from   w  w  w .  j a  va 2  s. c o m
        throw new RestException(HttpStatus.NOT_FOUND, message);
    }
    return user;
}

From source file:com.auditbucket.fortress.endpoint.FortressEP.java

@RequestMapping(value = "/{fortressName}", method = RequestMethod.GET)
@ResponseBody//from w  w w.j a v a 2 s  .c o m
public ResponseEntity<Fortress> getFortress(@PathVariable("fortressName") String fortressName) {
    // curl -u mike:123 -X GET  http://localhost:8080/ab/fortress/ABC
    Fortress fortress = fortressService.findByName(fortressName);
    if (fortress == null)
        return new ResponseEntity<>(fortress, HttpStatus.NOT_FOUND);
    else
        return new ResponseEntity<>(fortress, HttpStatus.OK);
}

From source file:ca.qhrtech.controllers.GameController.java

@ApiMethod(description = "Updates the Game at the specified location. Passed Game should contain the updated fields")
@RequestMapping(value = "/game/{id}", method = RequestMethod.PUT)
public ResponseEntity<Game> updateGame(@PathVariable("id") long id, @RequestBody Game game) {
    Game currentGame = gameService.findGameById(id);
    if (game == null) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }//from ww w  . j a va2  s.c om
    currentGame.setBggId(game.getBggId());
    currentGame.setCategories(game.getCategories());
    currentGame.setImagePath(game.getImagePath());
    currentGame.setMaxPlayTimeMins(game.getMaxPlayTimeMins());
    currentGame.setMaxPlayers(game.getMaxPlayers());
    currentGame.setMinPlayTimeMins(game.getMinPlayTimeMins());
    currentGame.setMinPlayers(game.getMinPlayers());
    currentGame.setName(game.getName());
    gameService.updateGame(currentGame);
    return new ResponseEntity<>(currentGame, HttpStatus.OK);

}

From source file:com.asiainfo.tfsPlatform.web.functional.rest.TaskRestFT.java

/**
 * //.//  w w  w  .  j a  v a  2  s  . c  om
 */
@Test
@Category(Smoke.class)
public void createUpdateAndDeleteTask() {

    // create
    TaskDto task = TaskData.randomTask();

    URI createdTaskUri = restTemplate.postForLocation(resourceUrl, task);
    System.out.println(createdTaskUri.toString());
    TaskDto createdTask = restTemplate.getForObject(createdTaskUri, TaskDto.class);
    assertThat(createdTask.getTitle()).isEqualTo(task.getTitle());

    // update
    String id = StringUtils.substringAfterLast(createdTaskUri.toString(), "/");
    task.setId(new Long(id));
    task.setTitle(TaskData.randomTitle());

    restTemplate.put(createdTaskUri, task);

    TaskDto updatedTask = restTemplate.getForObject(createdTaskUri, TaskDto.class);
    assertThat(updatedTask.getTitle()).isEqualTo(task.getTitle());

    // delete
    restTemplate.delete(createdTaskUri);

    try {
        restTemplate.getForObject(createdTaskUri, TaskDto.class);
        fail("Get should fail while feth a deleted task");
    } catch (HttpStatusCodeException e) {
        assertThat(e.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
    }
}

From source file:cn.edu.zjnu.acm.judge.problem.ProblemStatusController.java

@GetMapping("/problemstatus")
@SuppressWarnings("AssignmentToMethodParameter")
public String status(HttpServletRequest request, @RequestParam("problem_id") long id,
        @PageableDefault(size = 20, sort = { "time", "memory", "code_length" }) Pageable pageable,
        Authentication authentication) {
    log.debug("{}", pageable);
    if (pageable.getPageSize() > 500) {
        pageable = new PageRequest(pageable.getPageNumber(), 500, pageable.getSort());
    }/*from  w ww  .ja v  a 2  s  .  com*/
    Problem problem = problemMapper.findOneNoI18n(id);
    if (problem == null) {
        throw new MessageException("No such problem", HttpStatus.NOT_FOUND);
    }
    final Long contestId = problem.getContest();
    request.setAttribute("contestId", contestId);
    List<ScoreCount> list = problemMapper.groupByScore(id);
    ArrayList<String> scores = new ArrayList<>(list.size());
    ArrayList<Long> counts = new ArrayList<>(list.size());
    ArrayList<String> urls = new ArrayList<>(list.size());
    for (ScoreCount scoreCount : list) {
        int score = scoreCount.getScore();
        scores.add(ResultType.getShowsourceString(score));
        counts.add(scoreCount.getCount());
        urls.add(request.getContextPath() + "/status?problem_id=" + id + "&score=" + score);
    }
    List<Submission> bestSubmissions = submissionMapper.bestSubmission(id, pageable);
    long total = pageable.getOffset() + bestSubmissions.size()
            + (pageable.getPageSize() == bestSubmissions.size() ? 1 : 0);
    PageImpl<Submission> page = new PageImpl<>(bestSubmissions, pageable, total);
    boolean isAdmin = UserDetailService.isAdminLoginned(request);
    boolean isSourceBrowser = UserDetailService.isSourceBrowser(request);
    boolean canView = isAdmin || isSourceBrowser;

    request.setAttribute("page", page);
    request.setAttribute("sa", Arrays.asList(counts, scores, urls));
    request.setAttribute("problem", problem);
    request.setAttribute("url", URLBuilder.fromRequest(request).replaceQueryParam("page").toString());
    request.setAttribute("contestId", contestId);
    request.setAttribute("canView", canView);
    request.setAttribute("authentication", authentication);

    return "problems/status";
}

From source file:org.apigw.authserver.web.admin.DefaultAdminExceptionHandler.java

@ExceptionHandler(ResourceNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public @ResponseBody Map<String, Object> handleResourceNotFound(ResourceNotFoundException e) {
    Map<String, Object> map = Maps.newHashMap();
    map.put("error", "Entity Not Found");
    map.put("cause", e.getMessage());
    log.info("Handle ResourceNotFound. Returning {}", map);
    return map;/*from   w  ww .ja  v  a  2 s .  c o  m*/

}

From source file:com.citibanamex.api.locator.atm.exceptions.GlobalExceptionHandler.java

/**
 * This method is to handle NotFoundException category
 * /*from w  w w  . j  av  a 2 s.  c  o m*/
 * @param NotFoundException
 * @return Response
 */
@ExceptionHandler
@ResponseStatus(value = HttpStatus.NOT_FOUND)
@ResponseBody
public ResponseEntity<?> handleResourceNotFoundException(final NoHandlerFoundException ex) {
    Response eR = new Response();
    eR.setTimeStamp(new Date().getTime());
    eR.setStatus("FAILURE");
    eR.setErrorCode(HttpStatus.NOT_FOUND.value());
    eR.setMessage("Resource Not Found");
    eR.setDescription("Resource you are trying to reach is not found");
    logger.info("Http response -" + eR.getErrorCode() + "-" + eR.getDescription() + "-" + eR.getMessage());
    return new ResponseEntity<Response>(eR, HttpStatus.NOT_FOUND);
}

From source file:org.cloudfoundry.test.ServiceController.java

@RequestMapping(value = "/mysql/char-set", method = RequestMethod.GET)
public ResponseEntity<String> getMySQLDataSourceCharSet() {
    if (serviceHolder.getMySqlDataSource() == null) {
        return new ResponseEntity<String>(HttpStatus.NOT_FOUND);
    }//from   w w w.  j a v a  2 s. c  om
    JdbcTemplate jt = new JdbcTemplate(serviceHolder.getMySqlDataSource());
    String characterEncoding = jt.queryForObject("SELECT charset('Dligt vder oroar semestersvensken')",
            String.class);
    return new ResponseEntity<String>(characterEncoding, HttpStatus.OK);
}

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

@Override
@RequestMapping(value = "/{badgeId}", method = RequestMethod.DELETE)
public ResponseEntity<Void> badgesBadgeIdDelete(
        @ApiParam(value = "badgeId", required = true) @RequestHeader(value = "X-Gamification-Token", required = true) String xGamificationToken,
        @ApiParam(value = "badgeId", required = true) @PathVariable("badgeId") Long badgeId) {

    AuthenKey apiKey = authenKeyRepository.findByAppKey(xGamificationToken);
    if (apiKey == null) {
        return new ResponseEntity("apikey not exist", HttpStatus.UNAUTHORIZED);
    }//from w  w w  .  j ava2s  . co m

    Application app = apiKey.getApp();
    Badge badge = badgeRepository.findByIdAndApp(badgeId, app);

    if (badge != null && app != null) {
        badgeRepository.delete(badge);
        return new ResponseEntity(HttpStatus.OK);
    } else {
        return new ResponseEntity("no content is valid", HttpStatus.NOT_FOUND);
    }
}