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.openbaton.marketplace.api.exceptions.GlobalExceptionHandler.java

@ExceptionHandler({ InterruptedException.class, IOException.class })
@ResponseStatus(value = HttpStatus.NOT_FOUND)
protected ResponseEntity<Object> handleException(HttpServletRequest req, Exception e) {
    log.error("Exception with message " + e.getMessage() + " was thrown");
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    Map body = new HashMap<>();
    body.put("error", "Upload Error");
    body.put("exception", e.getClass().toString());
    body.put("message", e.getMessage());
    body.put("path", req.getRequestURI());
    body.put("status", HttpStatus.I_AM_A_TEAPOT.value());
    body.put("timestamp", new Date().getTime());
    ResponseEntity responseEntity = new ResponseEntity(body, headers, HttpStatus.I_AM_A_TEAPOT);
    return responseEntity;
}

From source file:com.chevres.rss.restapi.controller.UserController.java

@CrossOrigin
@RequestMapping(path = "/user/{username}", method = RequestMethod.GET)
@ResponseBody//from  ww w  .j a  v a2  s  . c o m
public ResponseEntity<String> getUser(@RequestHeader(value = "User-token") String userToken,
        @PathVariable String username) {

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
    UserDAO userDAO = context.getBean(UserDAO.class);
    UserAuthDAO userAuthDAO = context.getBean(UserAuthDAO.class);

    UserAuth userAuth = userAuthDAO.findByToken(userToken);
    if (userAuth == null) {
        context.close();
        return new ResponseEntity(new ErrorMessageResponse("invalid_token"), HttpStatus.BAD_REQUEST);
    }

    User user = userDAO.findByUsername(username);
    if (user == null) {
        context.close();
        return new ResponseEntity(HttpStatus.NOT_FOUND);
    }

    boolean isAdmin = userDAO.isAdmin(userAuth.getIdUser());
    if (!isAdmin && (userAuth.getIdUser() != user.getId())) {
        return new ResponseEntity(new ErrorMessageResponse("admin_required"), HttpStatus.FORBIDDEN);
    }

    context.close();

    return new ResponseEntity(new SuccessGetUserResponse(user.getUsername(), user.getType()), HttpStatus.OK);
}

From source file:com.sms.server.controller.MediaController.java

@RequestMapping(value = "/folder/{id}/contents", method = RequestMethod.GET)
public ResponseEntity<List<MediaElement>> getMediaElementsByMediaFolderID(@PathVariable("id") Long id) {
    MediaFolder mediaFolder = settingsDao.getMediaFolderByID(id);

    if (mediaFolder == null) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }/* w ww  .j ava2 s .  c  o m*/

    List<MediaElement> mediaElements = mediaDao.getAlphabeticalMediaElementsByParentPath(mediaFolder.getPath());

    if (mediaElements == null) {
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

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

From source file:org.kurento.repository.RepositoryController.java

@RequestMapping(method = RequestMethod.GET, value = "/{itemId}")
public RepositoryItemPlayer getReadEndpoint(@PathVariable("itemId") String itemId,
        HttpServletResponse response) {//  w w  w . ja  v  a  2  s  .  c  o  m
    try {
        return repoService.getReadEndpoint(itemId);
    } catch (ItemNotFoundException e) {
        try {
            response.sendError(HttpStatus.NOT_FOUND.value(), e.getMessage());
        } catch (IOException ioe) {
            ioe.printStackTrace();
            throw new KurentoException(ioe);
        }
        return null;
    }
}

From source file:hr.foi.rsc.controllers.PersonController.java

/**
 * looks up a user and verifies password
 * @param credentials username and password
 * @return person info and HTTP 200 on success or HTTP 404 on fail
 *///w ww.  ja v  a  2 s  .  c  o m
@RequestMapping(value = "/login", method = RequestMethod.POST)
public ResponseEntity<Person> login(@RequestBody Credentials credentials) {
    Logger.getLogger("PersonController.java").log(Level.INFO,
            "POST on /person/login -- " + credentials.toString());
    String username = credentials.getUsername();
    String password = credentials.getPassword();

    Person found = this.personRepository.findByCredentialsUsername(username);
    if (found != null && found.getCredentials().getPassword().equals(password)) {
        Logger.getLogger("PersonController.java").log(Level.INFO,
                "Successfully verified, returning " + found.toString());
        return new ResponseEntity(found, HttpStatus.OK);
    } else {
        Logger.getLogger("PersonController.java").log(Level.WARN,
                "Verification failed for " + credentials.toString());
        return new ResponseEntity(HttpStatus.NOT_FOUND);
    }

}

From source file:nu.yona.server.rest.HibernateStatisticsController.java

@RequestMapping(value = "/clearCaches/", method = RequestMethod.POST)
@ResponseBody/*from  w w  w. j av  a2s .c  o m*/
public ResponseEntity<Void> clearCaches() {
    if (!hibernateStatisticsService.isStatisticsEnabled()) {
        return createResponse(HttpStatus.NOT_FOUND);
    }

    hibernateStatisticsService.clearAllUserDataCaches();

    return createOkResponse();
}

From source file:fr.mby.opa.pics.web.controller.ImageController.java

@RequestMapping(value = "{id}", method = RequestMethod.GET)
public ResponseEntity<byte[]> getImage(@PathVariable final Long id, final HttpServletRequest request,
        final HttpServletResponse response) throws Exception {

    ResponseEntity<byte[]> responseEntity = null;

    if (id != null) {

        final BinaryImage image = this.pictureDao.findImageById(id);
        if (image != null) {
            final byte[] thumbnailData = image.getData();

            final HttpHeaders responseHeaders = new HttpHeaders();
            responseHeaders.setContentType(MediaType.parseMediaType("image/" + image.getFormat()));
            responseHeaders.setContentLength(thumbnailData.length);
            responseHeaders.set("Content-Disposition", "filename=\"" + image.getFilename() + '\"');

            responseEntity = new ResponseEntity<byte[]>(thumbnailData, responseHeaders, HttpStatus.OK);
        }/*w w  w .  jav  a  2 s.c om*/
    }

    if (responseEntity == null) {
        responseEntity = new ResponseEntity<byte[]>(null, null, HttpStatus.NOT_FOUND);
    }

    return responseEntity;
}

From source file:com._8x8.presentation.restfulController.ZPayRestfulController.java

@RequestMapping(value = "/getVendorInfoByQRCode/{qrCode}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<User> listVendorUsers(@PathVariable("qrCode") String qrCode) {

    try {/*w w  w.  j av  a  2 s  . c om*/
        String code = _encryptorService.decryptCode(qrCode);
        int id = Integer.parseInt(code);
        User user = _userService.GetUserById(id);
        if (user == null) {
            System.out.println("User with id " + id + " not found");
            return new ResponseEntity<User>(HttpStatus.NOT_FOUND);
        }
        return new ResponseEntity<User>(user, HttpStatus.OK);

    } catch (Exception ex) {
        Logger.getLogger(ZPayRestfulController.class.getName()).log(Level.SEVERE, null, ex);
        return new ResponseEntity<User>(HttpStatus.NOT_FOUND);
    }

}

From source file:com.srinathavan.mwbng.rest.mvc.BlogEntryController.java

/**
 * //from   ww w.j a v  a 2  s .  com
 * @param blogEntryId
 * @return
 */
@RequestMapping(value = "/{blogEntryId}", method = RequestMethod.DELETE)
public ResponseEntity<Object> deleteBlogEntry(@PathVariable Long blogEntryId) {
    BlogEntry blogEntry = blogEntryService.deleteBlogEntry(blogEntryId);
    if (null != blogEntry) {
        return new ResponseEntity<Object>(blogEntry, HttpStatus.OK);
    } else {
        return new ResponseEntity<Object>(HttpStatus.NOT_FOUND);
    }
}

From source file:com.sms.server.controller.ImageController.java

@RequestMapping(value = "/{id}/fanart/{scale}", method = RequestMethod.GET, produces = "image/jpeg")
@ResponseBody/*from w w w  .  j a  va 2s .  c o  m*/
public ResponseEntity getFanArt(@PathVariable("id") Long id, @PathVariable("scale") Integer scale) {
    MediaElement mediaElement;
    BufferedImage image;

    // Get corresponding media element
    mediaElement = mediaDao.getMediaElementByID(id);

    if (mediaElement == null) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

    // Get scaled fan art
    image = imageService.getFanArt(mediaElement, scale);

    // Check if we were able to retrieve fan art
    if (image == null) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

    // Convert image to bytes to send
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(image, "jpg", baos);
        byte[] imageBytes = baos.toByteArray();

        // Return cover art if found
        return new ResponseEntity(imageBytes, HttpStatus.OK);

    } catch (IOException ex) {
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }
}