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:edu.sjsu.cmpe275.lab2.controller.ManageFriendshipController.java

/** Add a friendship object
 (9) Add a friend//from   ww  w.j a v a  2s . c  om
 Path:friends/{id1}/{id2}
 Method: PUT
        
 This makes the two persons with the given IDs friends with each other.
 If either person does not exist, return 404.
 If the two persons are already friends, do nothing, just return 200. Otherwise,
 Record this friendship relation. If all is successful, return HTTP code 200 and any
 informative text message in the HTTP payload.
        
 * @param a         Description of a
 * @param b         Description of b
 * @return         Description of c
 */

@RequestMapping(value = "/{id1}/{id2}", method = RequestMethod.PUT)
@ResponseBody
public ResponseEntity createFriendship(@PathVariable("id1") long id1, @PathVariable("id2") long id2) {
    int result = friendshipDao.create(id1, id2);

    if (result == 0) {
        return new ResponseEntity(new String[] { "Create friendship successfuly" }, HttpStatus.OK);
    } else {
        return new ResponseEntity(new String[] { "Can not find persons" }, HttpStatus.NOT_FOUND);
    }
}

From source file:it.reply.orchestrator.exception.GlobalControllerExceptionHandler.java

/**
 * Not Found exception handler.//from  ww  w .  ja  v a 2 s  . co m
 * 
 * @param ex
 *          the exception
 * @return a {@code ResponseEntity} instance
 */
@ExceptionHandler
@ResponseStatus(HttpStatus.NOT_FOUND)
@ResponseBody
public Error handleException(NotFoundException ex) {

    return new Error().withCode(HttpStatus.NOT_FOUND.value()).withTitle(HttpStatus.NOT_FOUND.getReasonPhrase())
            .withMessage(ex.getMessage());
}

From source file:org.openlmis.fulfillment.service.referencedata.BaseReferenceDataService.java

/**
 * Return one object from Reference data service.
 *
 * @param id UUID of requesting object./*from w ww . jav a 2s.c o  m*/
 * @return Requesting reference data object.
 */
public T findOne(UUID id) {
    String url = getServiceUrl() + getUrl() + id;

    try {
        ResponseEntity<T> responseEntity = restTemplate.exchange(buildUri(url), HttpMethod.GET, createEntity(),
                getResultClass());
        return responseEntity.getBody();
    } catch (HttpStatusCodeException ex) {
        // rest template will handle 404 as an exception, instead of returning null
        if (ex.getStatusCode() == HttpStatus.NOT_FOUND) {
            logger.warn("{} with id {} does not exist. ", getResultClass().getSimpleName(), id);
            return null;
        } else {
            throw buildDataRetrievalException(ex);
        }
    }
}

From source file:demo.web.UserVehicleController.java

@ExceptionHandler
@ResponseStatus(HttpStatus.NOT_FOUND)
private void handleVinNotFound(VehicleIdentificationNumberNotFoundException ex) {
}

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

@Override
@RequestMapping(value = "/{applicationName}", method = RequestMethod.DELETE)
public ResponseEntity<Void> applicationsApplicationNameDelete(
        @ApiParam(value = "applicationName", required = true) @PathVariable("applicationName") String applicationUsername) {

    Application app = apprepository.findByName(applicationUsername);

    if (app != null) {
        apprepository.delete(app);//from ww  w.j  av  a 2 s  . c o m
        return new ResponseEntity(HttpStatus.OK);
    } else {
        return new ResponseEntity(HttpStatus.NOT_FOUND);
    }
}

From source file:com.todo.backend.web.rest.TodoApi.java

@RequestMapping(value = "/todo/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed//from   ww w.j ava2  s .  co  m
@Transactional(readOnly = true)
public ResponseEntity<ReadTodoResponse> readTodo(@PathVariable Long id) {
    log.debug("GET /todo/{}", id);
    final Optional<Todo> result = Optional.ofNullable(todoRepository.findOne(id));
    if (result.isPresent()) {
        return ResponseEntity.ok().body(convertToReadTodoResponse(result.get()));
    }
    return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}

From source file:com.crazyacking.learn.spring.actuator.NoManagementSampleActuatorApplicationTests.java

@Test
public void testMetricsNotAvailable() {
    testHome(); // makes sure some requests have been made
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/metrics",
            Map.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}

From source file:org.springsource.sinspctr.rest.SInspctrRootController.java

private ResponseEntity<String> getIndexHtml() {
    ResponseEntity<String> response;
    try {//from ww  w  .j ava  2 s . co m
        HttpHeaders headers = new HttpHeaders();
        headers.add("content-type", "text/html");
        response = new ResponseEntity<String>(
                FileCopyUtils.copyToString(
                        new FileReader(ResourceLocator.getClasspathRelativeFile("assets/index.html"))),
                headers, HttpStatus.OK);
        return response;
    } catch (Exception e) {
        return new ResponseEntity<String>(HttpStatus.NOT_FOUND);
    }
}

From source file:reconf.server.services.property.UpsertPropertyService.java

@RequestMapping(value = "/product/{prod}/component/{comp}/property/{prop}", method = RequestMethod.PUT)
@Transactional/*from   w ww . j  av  a  2  s .  c  o  m*/
public ResponseEntity<PropertyResult> global(@PathVariable("prod") String product,
        @PathVariable("comp") String component, @PathVariable("prop") String property,
        @RequestBody String value, @RequestParam(value = "desc", required = false) String description,
        HttpServletRequest request, Authentication auth) {

    PropertyKey key = new PropertyKey(product, component, property);
    Property reqProperty = new Property(key, value, description);

    List<String> errors = DomainValidator.checkForErrors(reqProperty);

    if (!errors.isEmpty()) {
        return new ResponseEntity<PropertyResult>(new PropertyResult(reqProperty, errors),
                HttpStatus.BAD_REQUEST);
    }
    if (!products.exists(key.getProduct())) {
        return new ResponseEntity<PropertyResult>(new PropertyResult(reqProperty, Product.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }
    if (!components.exists(new ComponentKey(key.getProduct(), key.getComponent()))) {
        return new ResponseEntity<PropertyResult>(new PropertyResult(reqProperty, Component.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }

    HttpStatus status = null;
    Property dbProperty = properties.findOne(key);
    if (dbProperty != null) {
        dbProperty.setValue(value);
        dbProperty.setDescription(description);
        status = HttpStatus.OK;

    } else {
        dbProperty = reqProperty;
        properties.save(dbProperty);
        status = HttpStatus.CREATED;
    }
    return new ResponseEntity<PropertyResult>(
            new PropertyResult(dbProperty, CrudServiceUtils.getBaseUrl(request)), status);
}

From source file:com.graphaware.module.algo.path.NumberOfShortestPathsFinderApi.java

@ExceptionHandler(NotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public void handleNotFound() {
}