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.yoncabt.ebr.ws.ReportWS.java

@RequestMapping(value = {
        "/ws/1.0/status/{requestId}" }, method = RequestMethod.GET, produces = "application/json")
public ResponseEntity<ReportResponse> status(@PathVariable("requestId") String requestId) {
    Status status = reportService.status(requestId);
    if (status == null) {//balamam
        logManager.info("status query :YOK !!! " + requestId);
        return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
    }//from   w  ww .ja  v  a2 s . co  m
    logManager.info("status query :" + requestId);
    switch (status) {
    case WAIT:
        logManager.info("status query :" + requestId + " :balam");
        return ResponseEntity.status(HttpStatus.CREATED).body(null);

    case RUN:
        logManager.info("status query :" + requestId + " :devam ediyor");
        return ResponseEntity.status(HttpStatus.PROCESSING).body(null);

    case EXCEPTION:
        logManager.info("status query :" + requestId + " :hata");
        return ResponseEntity.status(420).body(null);// 420 Method Failure

    case FINISH:
        logManager.info("status query :" + requestId + " :bitmi");
        return ResponseEntity.status(HttpStatus.OK).body(null);

    case CANCEL:
        logManager.info("status query :" + requestId + " :iptal");
        return ResponseEntity.status(HttpStatus.OK).body(null);

    case SCHEDULED:
        logManager.info("status query :" + requestId + " :balam");
        return ResponseEntity.status(HttpStatus.CREATED).body(null);
    default:
        throw new IllegalArgumentException(status.name());
    }
}

From source file:eu.modaclouds.sla.service.rest.ModacloudsRest.java

@PUT
@Path("{id}/start")
@Consumes(MediaType.APPLICATION_JSON)//from   w  w  w.  j  a v a  2  s  .  c o m
public Response startMasterAgreement(@Context UriInfo uriInfo, @PathParam("id") String agreementId) {

    logger.debug("Starting Master Agreement {}", agreementId);

    IAgreement master = agreementDAO.getByAgreementId(agreementId);
    if (master == null) {
        return buildResponse(HttpStatus.NOT_FOUND, "Agreement " + agreementId + " not found");
    }
    List<IAgreement> agreements = agreementDAO.getByMasterId(agreementId);
    agreements.add(master);

    String slaUrl = getSlaUrl(this.slaUrl, uriInfo);
    /* TODO: read supplied Monitoring Platform url from body of request */
    String metricsUrl = getMetricsBaseUrl("", this.monitoringManagerUrl);
    ViolationSubscriber subscriber = getSubscriber(slaUrl, metricsUrl);
    for (IAgreement agreement : agreements) {
        subscriber.subscribeObserver(agreement);
        enforcementService.startEnforcement(agreement.getAgreementId());
    }

    return buildResponse(HttpStatus.ACCEPTED, "Agreement started");
}

From source file:org.mitre.oauth2.web.AccessTokenAPI.java

@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json")
public String getById(@PathVariable("id") Long id, ModelMap m, Principal p) {

    OAuth2AccessTokenEntity token = tokenService.getAccessTokenById(id);

    if (token == null) {
        logger.error("getToken failed; token not found: " + id);
        m.put("code", HttpStatus.NOT_FOUND);
        m.put("errorMessage", "The requested token with id " + id + " could not be found.");
        return "jsonErrorView";
    } else if (!token.getAuthenticationHolder().getAuthentication().getName().equals(p.getName())) {
        logger.error("getToken failed; token does not belong to principal " + p.getName());
        m.put("code", HttpStatus.FORBIDDEN);
        m.put("errorMessage", "You do not have permission to view this token");
        return "jsonErrorView";
    } else {/*from   w  w w.jav a 2s.c om*/
        m.put("entity", token);
        return "jsonEntityView";
    }
}

From source file:sample.SpringDataRestDeleteNotFoundApplicationTests.java

@Test
public void messagesCrud() {
    Message toCreate = createMessage();/*from   w  w  w .j a  v a2 s. co  m*/

    ResponseEntity<Message> created = rest.postForEntity("/messages/", toCreate, Message.class);

    assertThat(created).isNotNull();
    assertThat(created.getStatusCode()).isEqualTo(HttpStatus.CREATED);
    assertThat(created.getBody().getText()).isEqualTo(toCreate.getText());

    URI createdUri = created.getHeaders().getLocation();

    Message getForEntity = rest.getForEntity(createdUri, Message.class).getBody();
    assertThat(getForEntity.getText()).isEqualTo(toCreate.getText());

    // response is 405 when @GetMapping("/messages/{id}") is present
    rest.delete(createdUri);

    assertThat(rest.getForEntity(createdUri, Message.class).getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}

From source file:py.com.sodep.web.UserWatchListController.java

@ExceptionHandler
@ResponseStatus(HttpStatus.NOT_FOUND)
public RestResponse handleMovieNotFound(MovieNotFoundException ex) {
    return new RestResponse(false, ex.getMessage());
}

From source file:web.UsersRESTController.java

/**
 * Gets a specific user's info based on User ID through REST API
 * @param id/*from  www . j  a  v  a 2 s.com*/
 * @return
 */
@RequestMapping(value = "/api/users/userinfo/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Users> getUserInfo(@PathVariable("id") int id) {
    Users user = null;
    //returns a NOT_FOUND error if no User is tied to specific UserID        
    try {
        user = dao.getUserById(id);
    } catch (EmptyResultDataAccessException ex) {
        return new ResponseEntity<Users>(HttpStatus.NOT_FOUND);
    }
    //otherwise returns specific User's info
    return new ResponseEntity<Users>(user, HttpStatus.OK);
}

From source file:org.mitre.oauth2.web.RefreshTokenAPI.java

@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json")
public String getById(@PathVariable("id") Long id, ModelMap m, Principal p) {

    OAuth2RefreshTokenEntity token = tokenService.getRefreshTokenById(id);

    if (token == null) {
        logger.error("getToken failed; token not found: " + id);
        m.put("code", HttpStatus.NOT_FOUND);
        m.put("errorMessage", "The requested token with id " + id + " could not be found.");
        return "jsonErrorView";
    } else if (!token.getAuthenticationHolder().getAuthentication().getName().equals(p.getName())) {
        logger.error("getToken failed; token does not belong to principal " + p.getName());
        m.put("code", HttpStatus.FORBIDDEN);
        m.put("errorMessage", "You do not have permission to view this token");
        return "jsonErrorView";
    } else {//from   w  ww  .ja  va  2  s  .co m
        m.put("entity", token);
        return "jsonEntityView";
    }
}

From source file:ch.wisv.areafiftylan.exception.GlobalControllerExceptionHandler.java

@ExceptionHandler(TokenNotFoundException.class)
public ResponseEntity<?> handleTokenNotFoundException(TokenNotFoundException ex) {
    return createResponseEntity(HttpStatus.NOT_FOUND, ex.getMessage());
}

From source file:eu.dime.dnsregister.controllers.RecordsController.java

@RequestMapping(value = "/{id}", headers = "Accept=application/json")
@ResponseBody//  w  w  w . ja  va 2  s .c o  m
public ResponseEntity<String> showJson(@PathVariable("id") Integer id) {
    Records records = Records.findRecords(id);
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    if (records == null) {
        return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
    }
    return new ResponseEntity<String>(records.toJson(), headers, HttpStatus.OK);
}

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

/**
 * Build a preview for a previewable/*from w w  w  . ja  va2  s .co m*/
 */
public <T extends Previewable & Identifiable> ResponseEntity<String> render(String id, Repository<T> repository,
        HttpServletRequest httpServletRequest) {
    if (isBlank(id)) {
        throw new IllegalArgumentException("Need to specify the id of the page to preview.");
    }

    try {
        String html = generator.generateHtml(getResourceContext(httpServletRequest), repository.get(id));
        return new ResponseEntity<>(html, HttpStatus.OK);
    } catch (GenerationException e) {
        LOGGER.error("Error during page generation", e);
        return new ResponseEntity<>("Error during page generation", HttpStatus.INTERNAL_SERVER_ERROR);
    } catch (NotFoundException e) {
        return new ResponseEntity<>("Page <" + id + "> not found", HttpStatus.NOT_FOUND);
    }
}