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:com.br.helpdesk.controller.UserGroupController.java

/**
 * Exceptions Handler//  w ww  .j  av a  2  s  .  co m
 */

@ExceptionHandler(EntityNotFoundException.class)
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "Entidade no encontrada")
public void handleEntityNotFoundException(Exception ex) {
}

From source file:org.bonitasoft.web.designer.controller.preview.PreviewerTest.java

@Test
public void should_return_error_response_when_page_is_not_found() throws Exception {
    when(pageRepository.get("unexisting-page")).thenThrow(new NotFoundException("page not found"));

    ResponseEntity<String> response = previewer.render("unexisting-page", pageRepository, request);

    assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
    assertThat(response.getBody()).isEqualTo("Page <unexisting-page> not found");
}

From source file:edu.sjsu.cmpe275.lab2.controller.ManageFriendshipController.java

/** Remove a friendship object
 (10) Remove a friend//from ww w.ja  v a 2 s.  c  o  m
 Path:friends/{id1}/{id2}
 Method: DELETE
        
 This request removes the friendship relation between the two persons.
 If either person does not exist, return 404.
 If the two persons are not friends, return 404. Otherwise,
 Remove this friendship relation. Return HTTP code 200 and a meaningful text message if all is successful.
        
 * @param a         Description of a
 * @param b         Description of b
 * @return         Description of c
 */

@RequestMapping(value = "/{id1}/{id2}", method = RequestMethod.DELETE)
@ResponseBody
public ResponseEntity deleteFriendship(@PathVariable("id1") long id1, @PathVariable("id2") long id2) {
    int result = friendshipDao.delete(id1, id2);
    if (result == 0) {
        return new ResponseEntity(new String[] { "Delete friendship successfuly" }, HttpStatus.OK);
    } else {
        return new ResponseEntity(new String[] { "Can not find persons" }, HttpStatus.NOT_FOUND);
    }
}

From source file:springfox.documentation.swagger1.web.Swagger1Controller.java

private ResponseEntity<Json> getSwaggerApiListing(String swaggerGroup, String apiDeclaration) {
    String groupName = Optional.fromNullable(swaggerGroup).or("default");
    Documentation documentation = documentationCache.documentationByGroup(groupName);
    if (documentation == null) {
        return new ResponseEntity<Json>(HttpStatus.NOT_FOUND);
    }//  w ww. ja  va2 s  . c  om
    Multimap<String, springfox.documentation.service.ApiListing> apiListingMap = documentation.getApiListings();
    Map<String, Collection<ApiListing>> dtoApiListings = transformEntries(apiListingMap,
            toApiListingDto(mapper)).asMap();

    Collection<ApiListing> apiListings = dtoApiListings.get(apiDeclaration);
    return mergedApiListing(apiListings).transform(toJson()).transform(toResponseEntity(Json.class))
            .or(new ResponseEntity<Json>(HttpStatus.NOT_FOUND));
}

From source file:web.ClientsRESTController.java

/**
 * Gets a list of events tied to a client's Client ID
 * @param id//from ww  w  .ja va 2s . co  m
 * @return
 */
@RequestMapping(value = "/api/clients/clientevents/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<EventLog>> getClientEvents(@PathVariable("id") int id) {
    List<EventLog> clientEL = null;
    //returns a NOT_FOUND error if no Event Log history for Client exists
    try {
        clientEL = adao.getEventsByClientID(id);
    } catch (EmptyResultDataAccessException ex) {
        return new ResponseEntity<List<EventLog>>(HttpStatus.NOT_FOUND);
    }
    //otherwise returns Event Log history for that Client
    return new ResponseEntity<List<EventLog>>(clientEL, HttpStatus.OK);
}

From source file:ru.org.linux.comment.ShowCommentsController.java

@ExceptionHandler(UserNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public ModelAndView handleUserNotFound() {
    ModelAndView mav = new ModelAndView("errors/good-penguin");
    mav.addObject("msgTitle", ": ?  ??");
    mav.addObject("msgHeader", "?  ??");
    mav.addObject("msgMessage", "");
    return mav;/*from   ww w  . j a v  a 2s .  c o m*/
}

From source file:com.gazbert.bxbot.rest.api.StrategyConfigController.java

/**
 * Returns the Strategy configuration for a given id.
 *
 * @param user the authenticated user.//from   w w  w .  ja v a  2s  .c o  m
 * @param strategyId the id of the Strategy to fetch.
 * @return the Strategy configuration.
 */
@RequestMapping(value = "/strategy/{strategyId}", method = RequestMethod.GET)
public ResponseEntity<?> getStrategy(@AuthenticationPrincipal User user, @PathVariable String strategyId) {

    final StrategyConfig strategyConfig = strategyConfigService.findById(strategyId);
    return strategyConfig.getId() != null ? new ResponseEntity<>(strategyConfig, null, HttpStatus.OK)
            : new ResponseEntity<>(HttpStatus.NOT_FOUND);
}

From source file:com.javiermoreno.springboot.mvc.users.UserCtrl.java

/**
 * Retrieves an user given his/her username or id.
 * @param emailOrId email or id (diferenciated by looking for an @).
 * @return 200 if ok, 404 if not found.//w  ww.j a  v  a 2 s.c o m
 */
@RequestMapping(value = "/{emailOrId}", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "GET /users/{emailOrId}", notes = "404 if user not found")
public HttpEntity<DailyUserResource> showUser(@PathVariable String emailOrId) {
    DailyUser user;
    if (emailOrId.contains("@") == true) {
        user = userRepository.findByEmail(emailOrId);
    } else {
        int id = Integer.parseInt(emailOrId);
        user = userRepository.findOne(id);
    }
    if (user != null) {
        DailyUserResource resource = new DailyUserResource();
        resource.user = user;
        resource.add(linkTo(methodOn(UserCtrl.class).showUser(emailOrId)).withSelfRel());
        return new ResponseEntity<>(resource, HttpStatus.OK);
    } else {
        return new ResponseEntity<>(null, HttpStatus.NOT_FOUND);
    }
}

From source file:com.sms.server.controller.UserController.java

@RequestMapping(value = "/{username}/role", method = RequestMethod.GET)
public ResponseEntity<List<UserRole>> getUserRoles(@PathVariable("username") String username) {
    List<UserRole> userRoles = userDao.getUserRolesByUsername(username);

    if (userRoles == null) {
        return new ResponseEntity<List<UserRole>>(HttpStatus.NOT_FOUND);
    }//  w  w w.jav a2  s.c o  m

    return new ResponseEntity<List<UserRole>>(userRoles, HttpStatus.OK);
}

From source file:de.escalon.hypermedia.sample.event.ReviewController.java

@Action("ReviewAction")
@RequestMapping(value = "/events/{eventId}", method = RequestMethod.POST)
public @ResponseBody ResponseEntity<Void> addReview(@PathVariable int eventId, @RequestBody Review review) {
    Assert.notNull(review);//  w  w  w .ja v  a  2s. co  m
    Assert.notNull(review.getReviewRating());
    Assert.notNull(review.getReviewRating().getRatingValue());
    ResponseEntity<Void> responseEntity;
    try {
        eventBackend.addReview(eventId, review.getReviewBody(), review.getReviewRating());
        final HttpHeaders headers = new HttpHeaders();
        headers.setLocation(AffordanceBuilder
                .linkTo(AffordanceBuilder.methodOn(this.getClass()).getReviews(eventId)).toUri());
        responseEntity = new ResponseEntity<Void>(headers, HttpStatus.CREATED);
    } catch (NoSuchElementException ex) {
        responseEntity = new ResponseEntity<Void>(HttpStatus.NOT_FOUND);
    }
    return responseEntity;
}