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:org.mitre.oauth2.web.ScopeAPI.java

@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public String getScope(@PathVariable("id") Long id, ModelMap m) {

    SystemScope scope = scopeService.getById(id);

    if (scope != null) {

        m.put(JsonEntityView.ENTITY, scope);

        return JsonEntityView.VIEWNAME;
    } else {//w ww  . jav a2s  .  co m

        logger.error("getScope failed; scope not found: " + id);

        m.put(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
        m.put(JsonErrorView.ERROR_MESSAGE, "The requested scope with id " + id + " could not be found.");
        return JsonErrorView.VIEWNAME;
    }
}

From source file:cn.aozhi.songify.functional.rest.TaskRestFT.java

/**
 * //.//  w  w  w  .  j  a va 2 s  . com
 */
@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(new Long(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.cfitzarl.cfjwed.controller.ApiExceptionHandler.java

@ExceptionHandler(ResourceNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public void handleResourceNotFoundExceptions(ResourceNotFoundException e, HttpServletResponse response) {
    respond(e, "errors.not.found", response);
}

From source file:edu.eci.arsw.pacm.controllers.PacmRESTController.java

@RequestMapping(path = "/{salanum}/atacantes", method = RequestMethod.GET)
public ResponseEntity<?> getAtacantes(@PathVariable(name = "salanum") String salanum) {

    try {// ww w  .  jav  a  2s  .c  o m
        return new ResponseEntity<>(services.getAtacantes(Integer.parseInt(salanum)), HttpStatus.ACCEPTED);
    } catch (ServicesException ex) {
        Logger.getLogger(PacmRESTController.class.getName()).log(Level.SEVERE, null, ex);
        return new ResponseEntity<>(ex.getLocalizedMessage(), HttpStatus.NOT_FOUND);
    } catch (NumberFormatException ex) {
        Logger.getLogger(PacmRESTController.class.getName()).log(Level.SEVERE, null, ex);
        return new ResponseEntity<>("/{salanum}/ must be an integer value.", HttpStatus.BAD_REQUEST);
    }
}

From source file:de.codecentric.boot.admin.controller.RegistryController.java

/**
 * Get a single application out of the registry.
 * /*  w ww . j a  v a  2s  . c o m*/
 * @param id The application identifier.
 * @return The registered application.
 */
@RequestMapping(value = "/api/application/{id}", method = RequestMethod.GET)
public ResponseEntity<Application> get(@PathVariable String id) {
    LOGGER.debug("Deliver registered application with ID '{}'", id);
    Application application = registry.getApplication(id);
    if (application != null) {
        return new ResponseEntity<Application>(application, HttpStatus.OK);
    } else {
        return new ResponseEntity<Application>(application, HttpStatus.NOT_FOUND);
    }
}

From source file:io.github.microcks.web.ResourceController.java

@RequestMapping(value = "/resources/{name}", method = RequestMethod.GET)
public ResponseEntity<?> execute(@PathVariable("name") String name, HttpServletRequest request) {
    String extension = request.getRequestURI().substring(request.getRequestURI().lastIndexOf('.'));
    name = name + extension;//  ww  w. ja v a2s  .c o m

    log.info("Requesting resource named " + name);

    Resource resource = resourceRepository.findByName(name);
    if (resource != null) {
        return new ResponseEntity<Object>(resource.getContent(), HttpStatus.OK);
    }
    return new ResponseEntity<Object>(HttpStatus.NOT_FOUND);
}

From source file:springfox.documentation.swagger2.web.Swagger2Controller.java

@ApiIgnore
@RequestMapping(value = "${springfox.documentation.swagger.v2.path:" + DEFAULT_URL
        + "}", method = RequestMethod.GET, produces = { APPLICATION_JSON_VALUE, HAL_MEDIA_TYPE })
public @ResponseBody ResponseEntity<Json> getDocumentation(
        @RequestParam(value = "group", required = false) String swaggerGroup,
        HttpServletRequest servletRequest) {

    String groupName = Optional.fromNullable(swaggerGroup).or(Docket.DEFAULT_GROUP_NAME);
    Documentation documentation = documentationCache.documentationByGroup(groupName);
    if (documentation == null) {
        return new ResponseEntity<Json>(HttpStatus.NOT_FOUND);
    }// www  .j a v  a2  s.  c  o  m
    Swagger swagger = mapper.mapDocumentation(documentation);
    if (isNullOrEmpty(swagger.getHost())) {
        final UriComponents uriComponents = componentsFrom(servletRequest);
        swagger.basePath(Strings.isNullOrEmpty(uriComponents.getPath()) ? "/" : uriComponents.getPath());
        swagger.host(hostName(uriComponents));
    }
    return new ResponseEntity<Json>(jsonSerializer.toJson(swagger), HttpStatus.OK);
}

From source file:com.salmon.security.xacml.demo.springmvc.rest.controller.MarketPlaceQueryController.java

@ExceptionHandler(ObjectNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public void whenNotFound() {

}

From source file:com.ge.predix.acs.commons.web.ResponseEntityBuilder.java

/**
 * Creates a typed ResponseEntity with HTTP status code 200 with no response payload.
 *
 * @return The corresponding ResponseEntity
 *//* w  w  w  . ja  v a2s  .  c o  m*/
public static <T> ResponseEntity<T> notFound() {
    return new ResponseEntity<T>(HttpStatus.NOT_FOUND);
}

From source file:app.api.swagger.SwaggerConfig.java

private List<ResponseMessage> defaultGetResponses() {
    final List<ResponseMessage> results = new ArrayList<ResponseMessage>();
    results.add(response(HttpStatus.FORBIDDEN, null));
    results.add(response(HttpStatus.UNAUTHORIZED, null));
    results.add(response(HttpStatus.NOT_FOUND, null));
    return results;
}