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:pitayaa.nail.msg.core.license.controller.LicenseController.java

@RequestMapping(value = "licenses/{ID}", method = RequestMethod.DELETE)
public @ResponseBody ResponseEntity<?> deleteLicense(@PathVariable("ID") UUID uid) throws Exception {

    // Find license
    Optional<License> optionalLicense = licenseService.findOne(uid);
    if (!optionalLicense.isPresent()) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }//from w w  w  .  ja v  a 2s.  c  o m
    // Delete license
    boolean isDelete = licenseService.deleteLicense(uid);

    // Get status
    HttpStatus status = (isDelete) ? HttpStatus.NO_CONTENT : HttpStatus.EXPECTATION_FAILED;

    // Return
    return new ResponseEntity<>(status);
}

From source file:reconf.server.services.component.UpsertComponentService.java

@RequestMapping(value = "/product/{prod}/component/{comp}", method = RequestMethod.PUT)
@Transactional/* w ww.j a v a  2 s . c om*/
public ResponseEntity<ComponentResult> doIt(@PathVariable("prod") String productId,
        @PathVariable("comp") String componentId,
        @RequestParam(value = "desc", required = false) String description, HttpServletRequest request,
        Authentication auth) {

    ComponentKey key = new ComponentKey(productId, componentId);
    Component reqComponent = new Component(key, description);

    List<String> errors = DomainValidator.checkForErrors(key);
    if (!errors.isEmpty()) {
        return new ResponseEntity<ComponentResult>(new ComponentResult(reqComponent, errors),
                HttpStatus.BAD_REQUEST);
    }

    Product product = products.findOne(key.getProduct());
    if (product == null) {
        return new ResponseEntity<ComponentResult>(new ComponentResult(reqComponent, Product.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }
    HttpStatus status = null;
    Component dbComponent = components.findOne(key);
    if (dbComponent == null) {
        dbComponent = new Component(key, description);
        components.save(dbComponent);
        status = HttpStatus.CREATED;

    } else {
        dbComponent.setDescription(description);
        status = HttpStatus.OK;
    }
    return new ResponseEntity<ComponentResult>(
            new ComponentResult(dbComponent, CrudServiceUtils.getBaseUrl(request)), status);
}

From source file:org.trustedanalytics.kafka.adminapi.api.ExceptionHandlerAdvice.java

@ExceptionHandler
@ResponseStatus(HttpStatus.NOT_FOUND)
@ResponseBody//from   w ww .ja v  a 2s.c  o m
public String handleUnknownTopic(UnknownTopicOrPartitionException ex) {
    LOG.error("Unknown topic", ex);
    return ex.getMessage();
}

From source file:za.ac.cput.project.universalhardwarestorev2.api.ItemApi.java

@RequestMapping(value = "/item/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Item> getItem(@PathVariable("id") long id) {
    System.out.println("Fetching Item with id " + id);
    Item Item = service.findById(id);/*w w  w  . ja v  a 2 s. co  m*/
    if (Item == null) {
        System.out.println("Item with id " + id + " not found");
        return new ResponseEntity<Item>(HttpStatus.NOT_FOUND);
    }
    return new ResponseEntity<Item>(Item, HttpStatus.OK);
}

From source file:com.hp.autonomy.frontend.find.idol.view.IdolViewController.java

@ExceptionHandler
@ResponseStatus(HttpStatus.NOT_FOUND)
public ModelAndView handleViewDocumentNotFoundException(final ViewDocumentNotFoundException e,
        final HttpServletRequest request, final ServletResponse response) {
    response.reset();/*from w  w  w .j ava 2  s  .com*/

    final String reference = e.getReference();

    log.info(Markers.AUDIT, "TRIED TO VIEW NON EXISTENT DOCUMENT WITH REFERENCE {}", reference);

    return controllerUtils.buildErrorModelAndView(new ErrorModelAndViewInfo.Builder().setRequest(request)
            .setMainMessageCode("error.documentNotFound").setSubMessageCode("error.referenceDoesNotExist")
            .setSubMessageArguments(new Object[] { reference }).setStatusCode(HttpStatus.NOT_FOUND.value())
            .setContactSupport(true).setException(e).build());
}

From source file:pitayaa.nail.msg.core.account.controller.AccountLicenseController.java

@RequestMapping(value = "/accountsLicense/{ID}", method = RequestMethod.PUT)
public @ResponseBody ResponseEntity<?> updateAccountLicenseModel(@RequestBody AccountLicense accLicenseBody,
        @PathVariable("ID") UUID uid) throws Exception {

    Optional<AccountLicense> accountLicense = accLicenseService.findOne(uid);

    if (!accountLicense.isPresent()) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }/* w  w w . jav a  2  s .c  om*/

    accLicenseBody = accLicenseService.update(accLicenseBody);

    return ResponseEntity.ok(accLicenseBody);
}

From source file:io.fourfinanceit.homework.controller.LoanControler.java

@RequestMapping(value = "/loan/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<LoanApplication> getLoanApplication(@PathVariable("id") Long id) {

    LoanApplication loanApplication = loanApplicationRepository.findOne(id);
    if (loanApplication == null) {
        return new ResponseEntity<LoanApplication>(HttpStatus.NOT_FOUND);
    }// ww  w  .j a v a2s. c o m

    return new ResponseEntity<LoanApplication>(loanApplication, HttpStatus.OK);
}

From source file:com.xyxy.platform.examples.showcase.webservice.rest.UserRestController.java

/**
 * ContentNegotiationManager,?URL????//from   w  ww  .  jav a 2s  .  c  o m
 * eg. /api/v1/user/1.xml xml
 * /api/v1/user/1.json json
 * /api/v1/user/1 xml(why?)
 */
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public UserDTO getUser(@PathVariable("id") Long id) {
    final TimerContext exectuionTimer = executionMetrics.start();
    try {
        User user = accountService.getUser(id);

        if (user == null) {
            String message = "?(id:" + id + ")";
            logger.warn(message);
            throw new RestException(HttpStatus.NOT_FOUND, message);
        }

        // Dozer?DTODozer?
        UserDTO dto = BeanMapper.map(user, UserDTO.class);
        dto.setTeamId(user.getTeam().getId());
        return dto;
    } finally {
        exectuionTimer.stop();
    }
}

From source file:com.tikal.tallerWeb.data.access.rest.AutoDAOImp.java

public void guardar(Auto dato) {
    // como no tengo idea si es nuevo o no primero se intenta como si ya existiera, si regresa 404 se crea.
    try {/*from  w w w .j av  a 2 s  .co  m*/
        Map<String, Object> map = new HashMap<>();
        map.put("numeroSerie", dato.getNumeroSerie());
        //            factory.getTemplate().postForLocation(factory.getRootUlr() + "/autos/{numeroSerie}", dato, map);
    } catch (HttpClientErrorException ex) {
        HttpStatus status = ex.getStatusCode();
        if (status != HttpStatus.NOT_FOUND) {
            throw ex;
        }
        //            URI resource = factory.getTemplate().postForLocation(factory.getRootUlr() + "/autos", dato);
        //            String[] uri = StringUtils.split(resource.toString(), '/');
        //            String id = uri[uri.length - 1];
        //            dato.setNumeroSerie(id);
    }
}

From source file:com.mycompany.springrest.controllers.UserController.java

@RequestMapping(value = "/user/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<User> getUser(@PathVariable("id") int id) {
    User user = userService.getUserById(id);
    logger.info("Fetching User with id " + id);
    if (user == null) {
        logger.info("User with id " + id + " not found");
        return new ResponseEntity<User>(HttpStatus.NOT_FOUND);
    }// w w w  .j av a 2s.  co m
    return new ResponseEntity<User>(user, HttpStatus.OK);
}