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.sms.server.controller.UserController.java

@RequestMapping(value = "/{username}/stats", method = RequestMethod.GET)
public ResponseEntity<UserStats> getUserStats(@PathVariable("username") String username) {
    UserStats userStats = userDao.getUserStatsByUsername(username);

    if (userStats == null) {
        return new ResponseEntity<UserStats>(HttpStatus.NOT_FOUND);
    }/*  w  w w  .  j  a  v a2s  .c om*/

    return new ResponseEntity<UserStats>(userStats, HttpStatus.OK);
}

From source file:fi.helsinki.opintoni.exception.GlobalExceptionHandlers.java

@ExceptionHandler(value = CalendarFeedNotFoundException.class)
public ResponseEntity handleCalendarFeedNotFound() throws Exception {
    return new ResponseEntity(HttpStatus.NOT_FOUND);
}

From source file:com.bennavetta.appsite.processing.ProcessingController.java

public void handle(Request request, Response response, InputStream requestBody, OutputStream responseBody)
        throws Exception {
    for (RewriteRule rule : rewriteRules.get()) {
        if (rule.matches(request.getURI())) {
            URI rewritten = rule.rewrite(request.getURI());
            log.info("Rewriting {} to {}", request.getURI(), rewritten);
            handle(new RedirectedRequest(rewritten, request), response, requestBody, responseBody);
        }/* w  w w  . j  a v a  2s . c  o m*/
    }

    Resource resource = Resource.get(request.getURI());

    // index pages
    if (resource == null) {
        for (String indexPage : indexPages) {
            String indexUri = URI.create(request.getURI()).relativize(URI.create(indexPage)).toString();
            resource = Resource.get(indexUri);
            if (resource != null) {
                break;
            }
        }
    }

    if (resource == null) {
        resource = Resource.get(error.notFound()); //TODO: put requested page in attributes
        response.setStatus(HttpStatus.NOT_FOUND);
    }

    if (resource != null) {
        try {
            log.info("Serving resource {}", resource.getPath());
            sendResource(resource, request, response, requestBody, responseBody);
        } catch (Exception e) {
            log.error("Exception serving request", e);
            resource = Resource.get(error.exception()); //TODO: put exception in attributes
            response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR);
            sendResource(resource, request, response, requestBody, responseBody);
        }
    } else {
        log.warn("No content found: {}", request.getURI());
        // send something to avoid a blank response
        response.setStatus(HttpStatus.NOT_FOUND);
        response.setContentType(MediaType.HTML_UTF_8);
        PrintStream ps = new PrintStream(responseBody);
        ps.println("<html>");
        ps.println("\t<head>");
        ps.println("\t\t<title>Page not found</title>");
        ps.println("\t</head>");
        ps.println("\t<body>");
        ps.println("\t\t<h1>Page not found</h1>");
        ps.println("\t\t<p>Page " + request.getURI() + " not found</p>");
        ps.println("\t</body>");
        ps.println("</html>");
    }
}

From source file:com.orange.ngsi.client.SubscribeContextRequestTest.java

@Test(expected = HttpClientErrorException.class)
public void subscribeContextRequestWith404() throws Exception {

    this.mockServer.expect(requestTo(baseUrl + "/ngsi10/subscribeContext")).andExpect(method(HttpMethod.POST))
            .andRespond(withStatus(HttpStatus.NOT_FOUND));

    ngsiClient.subscribeContext(baseUrl, null, createSubscribeContextTemperature()).get();
}

From source file:io.github.proxyprint.kitchen.controllers.printshops.ReviewController.java

@ApiOperation(value = "Add a review to a printshop with the given ID", notes = "404 if the printshop doesn't exist.")
@Secured({ "ROLE_USER" })
@RequestMapping(value = "/printshops/{id}/reviews", method = RequestMethod.POST)
public ResponseEntity<String> addPrintShopReview(@PathVariable("id") long id, Principal principal,
        @RequestBody Map<String, String> params) {
    PrintShop pShop = this.printshops.findOne(id);
    if (pShop == null) {
        return new ResponseEntity(HttpStatus.NOT_FOUND);
    }/* ww w .  j a  v  a2  s.  c  om*/
    Consumer consumer = this.consumers.findByUsername(principal.getName());
    String reviewText = params.get("review");
    int rating = Integer.parseInt(params.get("rating"));
    Review review = reviews.save(new Review(reviewText, rating, consumer));
    pShop.addReview(review);
    pShop.updatePrintShopRating();
    this.printshops.save(pShop);
    return new ResponseEntity(this.GSON.toJson(review), HttpStatus.OK);
}

From source file:org.kuali.mobility.configparams.controllers.ConfigParamController.java

@RequestMapping(method = RequestMethod.PUT, headers = "Accept=application/json")
public ResponseEntity<String> put(@RequestBody String json) {
    ConfigParam cp = configParamService.fromJsonToEntity(json);
    if (configParamService.findConfigParamById(cp.getConfigParamId()) == null) {
        return new ResponseEntity<String>(HttpStatus.NOT_FOUND);
    } else {//from w  w  w.  j  a v a2 s . c om
        if (configParamService.saveConfigParam(cp) == null) {
            return new ResponseEntity<String>(HttpStatus.NOT_MODIFIED);
        }
    }
    return new ResponseEntity<String>(HttpStatus.OK);
}

From source file:org.mitre.openid.connect.web.UserInfoEndpoint.java

/**
 * Get information about the user as specified in the accessToken included in this request
 *//*from  ww  w  .  j  a  v  a  2s  . c  o m*/
@PreAuthorize("hasRole('ROLE_USER') and #oauth2.hasScope('" + SystemScopeService.OPENID_SCOPE + "')")
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }, produces = {
        MediaType.APPLICATION_JSON_VALUE, UserInfoJWTView.JOSE_MEDIA_TYPE_VALUE })
public String getInfo(@RequestParam(value = "claims", required = false) String claimsRequestJsonString,
        @RequestHeader(value = HttpHeaders.ACCEPT, required = false) String acceptHeader,
        OAuth2Authentication auth, Model model) {

    if (auth == null) {
        logger.error("getInfo failed; no principal. Requester is not authorized.");
        model.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN);
        return HttpCodeView.VIEWNAME;
    }

    String username = auth.getName();
    UserInfo userInfo = userInfoService.getByUsernameAndClientId(username,
            auth.getOAuth2Request().getClientId());

    if (userInfo == null) {
        logger.error("getInfo failed; user not found: " + username);
        model.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
        return HttpCodeView.VIEWNAME;
    }

    model.addAttribute(UserInfoView.SCOPE, auth.getOAuth2Request().getScope());

    model.addAttribute(UserInfoView.AUTHORIZED_CLAIMS, auth.getOAuth2Request().getExtensions().get("claims"));

    if (!Strings.isNullOrEmpty(claimsRequestJsonString)) {
        model.addAttribute(UserInfoView.REQUESTED_CLAIMS, claimsRequestJsonString);
    }

    model.addAttribute(UserInfoView.USER_INFO, userInfo);

    // content negotiation

    // start off by seeing if the client has registered for a signed/encrypted JWT from here
    ClientDetailsEntity client = clientService.loadClientByClientId(auth.getOAuth2Request().getClientId());
    model.addAttribute(UserInfoJWTView.CLIENT, client);

    List<MediaType> mediaTypes = MediaType.parseMediaTypes(acceptHeader);
    MediaType.sortBySpecificityAndQuality(mediaTypes);

    if (client.getUserInfoSignedResponseAlg() != null || client.getUserInfoEncryptedResponseAlg() != null
            || client.getUserInfoEncryptedResponseEnc() != null) {
        // client has a preference, see if they ask for plain JSON specifically on this request
        for (MediaType m : mediaTypes) {
            if (!m.isWildcardType() && m.isCompatibleWith(UserInfoJWTView.JOSE_MEDIA_TYPE)) {
                return UserInfoJWTView.VIEWNAME;
            } else if (!m.isWildcardType() && m.isCompatibleWith(MediaType.APPLICATION_JSON)) {
                return UserInfoView.VIEWNAME;
            }
        }

        // otherwise return JWT
        return UserInfoJWTView.VIEWNAME;
    } else {
        // client has no preference, see if they asked for JWT specifically on this request
        for (MediaType m : mediaTypes) {
            if (!m.isWildcardType() && m.isCompatibleWith(MediaType.APPLICATION_JSON)) {
                return UserInfoView.VIEWNAME;
            } else if (!m.isWildcardType() && m.isCompatibleWith(UserInfoJWTView.JOSE_MEDIA_TYPE)) {
                return UserInfoJWTView.VIEWNAME;
            }
        }

        // otherwise return JSON
        return UserInfoView.VIEWNAME;
    }

}

From source file:ca.qhrtech.controllers.ResultController.java

@ApiMethod(description = "Deletes the Game Result at the specified location")
@RequestMapping(value = "/result/{id}", method = RequestMethod.DELETE)
public ResponseEntity<Void> deleteResult(@PathVariable("id") long id) {
    if (resultService.findResultById(id) == null) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }/*from  www  .  j a v a  2 s.  c  om*/
    resultService.deleteResult(id);
    return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

From source file:com.orange.ngsi.client.RegisterContextRequestTest.java

@Test(expected = HttpClientErrorException.class)
public void subscribeContextRequestWith404() throws Exception {

    this.mockServer.expect(requestTo(baseUrl + "/ngsi9/registerContext")).andExpect(method(HttpMethod.POST))
            .andRespond(withStatus(HttpStatus.NOT_FOUND));

    ngsiClient.registerContext(baseUrl, null, createRegisterContextTemperature()).get();
}

From source file:org.eclipse.virgo.samples.rest.RestController.java

@RequestMapping(value = "/users/{userId}", method = RequestMethod.GET, produces = "application/json")
@ResponseBody/*from  w  ww  .j a  v  a 2  s.c  o  m*/
public ResponseEntity<String> getUser(@PathVariable("userId") String userId) {
    Info info = model.get(userId);
    if (info != null) {
        return createResponseEntity(info.toJson(), HttpStatus.OK);
    } else {
        return createResponseEntity("", HttpStatus.NOT_FOUND);
    }
}