Example usage for org.springframework.http ResponseEntity ok

List of usage examples for org.springframework.http ResponseEntity ok

Introduction

In this page you can find the example usage for org.springframework.http ResponseEntity ok.

Prototype

public static BodyBuilder ok() 

Source Link

Document

Create a builder with the status set to HttpStatus#OK OK .

Usage

From source file:com.viewer.controller.ViewerController.java

@RequestMapping(value = "/GetPdfWithPrintDialog")
@ResponseBody/*  w  w  w. j a  v a  2  s .c  om*/
public ResponseEntity<InputStreamResource> GetPdfWithPrintDialog(@RequestParam String path, Boolean getPdf,
        Boolean useHtmlBasedEngine, Boolean supportPageRotation, HttpServletResponse response)
        throws Exception {

    PdfFileOptions options = new PdfFileOptions();
    options.setGuid(path);
    options.setAddPrintAction(true);

    FileContainer result = _imageHandler.getPdfFile(options);

    return ResponseEntity.ok().contentType(MediaType.parseMediaType("application/pdf"))
            .body(new InputStreamResource(result.getStream()));
}

From source file:com.sastix.cms.server.services.content.impl.hazelcast.HazelcastResourceServiceImpl.java

@Override
@Transactional(readOnly = true)/*  ww w  .  j  av  a2  s . c  o m*/
public ResponseEntity<InputStreamResource> getResponseInputStream(String uuid)
        throws ResourceAccessError, IOException {
    // Find Resource
    final Resource resource = resourceRepository.findOneByUid(uuid);
    if (resource == null) {
        return null;
    }

    InputStream inputStream;
    int size;
    //check cache first
    QueryCacheDTO queryCacheDTO = new QueryCacheDTO(resource.getUri());
    CacheDTO cacheDTO = null;
    try {
        cacheDTO = cacheService.getCachedResource(queryCacheDTO);
    } catch (DataNotFound e) {
        LOG.warn("Resource '{}' is not cached.", resource.getUri());
    } catch (Exception e) {
        LOG.error("Exception: {}", e.getLocalizedMessage());
    }
    if (cacheDTO != null && cacheDTO.getCacheBlobBinary() != null) {
        LOG.info("Getting resource {} from cache", resource.getUri());
        inputStream = new ByteArrayInputStream(cacheDTO.getCacheBlobBinary());
        size = cacheDTO.getCacheBlobBinary().length;
    } else {
        try {
            final Path responseFile = hashedDirectoryService.getDataByURI(resource.getUri(),
                    resource.getResourceTenantId());
            inputStream = Files.newInputStream(responseFile);
            size = (int) Files.size(responseFile);

            // Adding resource to cache
            distributedCacheService.cacheIt(resource.getUri(), resource.getResourceTenantId());
        } catch (IOException ex) {
            LOG.info("Error writing file to output stream. Filename was '{}'", resource.getUri(), ex);
            throw new RuntimeException("IOError writing file to output stream");
        } catch (URISyntaxException e) {
            e.printStackTrace();
            throw new RuntimeException("IOError writing file to output stream");
        }
    }

    return ResponseEntity.ok().contentLength(size)
            .contentType(MediaType.parseMediaType(resource.getMediaType()))
            .body(new InputStreamResource(inputStream));
}

From source file:com.viewer.controller.ViewerController.java

@RequestMapping("/GetDocumentPageImage")
@ResponseBody/* w ww .  jav  a  2 s  .  c o  m*/
public final ResponseEntity<InputStreamResource> GetDocumentPageImage(@RequestParam String path, Boolean usePdf,
        Boolean useHtmlBasedEngine, Boolean rotate, int width, int pageindex, int quality) throws Exception {

    lock.lock();
    ViewerConfig imageConfig = new ViewerConfig();
    imageConfig.setStoragePath(_storagePath);
    imageConfig.setTempPath(_tempPath);
    imageConfig.setUseCache(true);
    _imageHandler = new ViewerImageHandler(imageConfig);
    String guid = path;
    int pageIndex = pageindex;
    int pageNumber = pageIndex + 1;
    PageImage pageImage = null;
    ImageOptions imageOptions = new ImageOptions();
    imageOptions.setConvertImageFileType(_convertImageFileType);
    imageOptions.setTransformations(rotate ? Transformation.Rotate : Transformation.None);

    if (rotate && width != 0) {
        DocumentInfoOptions documentInfoOptions = new DocumentInfoOptions(guid);
        DocumentInfoContainer documentInfoContainer = _imageHandler.getDocumentInfo(documentInfoOptions);

        int side = width;
        int pageAngle = 0;
        int count = 0;
        for (PageData page : documentInfoContainer.getPages()) {
            if (count == pageIndex) {
                pageAngle = page.getAngle();
            }
            count++;

        }
        if (pageAngle == 90 || pageAngle == 270) {
            imageOptions.setHeight(side);
        } else {
            imageOptions.setWidth(side);
        }
    }
    List<PageImage> pageImages = (List<PageImage>) _imageHandler.getPages(guid, imageOptions);

    for (PageImage image : pageImages) {

        if (image.getPageNumber() == pageNumber) {
            pageImage = image;

            lock.unlock();
            return ResponseEntity.ok().contentType(GetContentType(_convertImageFileType))
                    .body(new InputStreamResource(pageImage.getStream()));
        }
    }
    lock.unlock();
    return ResponseEntity.ok().contentType(GetContentType(_convertImageFileType))
            .body(new InputStreamResource(pageImage.getStream()));
}

From source file:com.mocktpo.api.LicenseApiController.java

@RequestMapping(value = "/api/licenses/require", method = RequestMethod.POST)
public ResponseEntity<Void> require(@RequestBody RequireActivationVo vo) {
    logger.debug("{}.{}() accessed.", this.getClass().getSimpleName(),
            Thread.currentThread().getStackTrace()[1].getMethodName());
    String email = vo.getEmail();
    String hardware = vo.getHardware();
    List<License> lz = service.findByEmail(email);
    if (null != lz && lz.size() > 0) { // email exists, filled in by agents previously.
        License lic = lz.get(0);//from ww w  .  j  a va2  s .  c  o m
        String licensedHardware = lic.getHardware();
        if (StringUtils.isEmpty(licensedHardware)) { // hardware remains blank
            lic.setHardware(hardware);
            Date date = new Date();
            lic.setDateUpdated(date);
            service.update(lic);
            EmailUtils.sendActivationCode(lic);
            return ResponseEntity.ok().build();
        } else {
            if (licensedHardware.equals(hardware)) { // same hardware registered
                EmailUtils.sendActivationCode(lic);
                return ResponseEntity.ok().build();
            } else {
                return ResponseEntity.status(HttpStatus.CONFLICT).build(); // different hardware registered
            }
        }
    } else {
        return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); // email never exists
    }
}

From source file:com.spartasystems.holdmail.rest.MessageController.java

@RequestMapping(value = "/{messageId}", method = RequestMethod.DELETE)
public ResponseEntity deleteMessage(@PathVariable("messageId") long messageId) {
    messageService.deleteMessage(messageId);
    return ResponseEntity.ok().build();
}

From source file:com.spartasystems.holdmail.rest.MessageController.java

@RequestMapping(value = "/{messageId}")
public ResponseEntity getMessageContent(@PathVariable("messageId") long messageId) {

    MessageSummary summary = loadMessageSummary(messageId);
    return ResponseEntity.ok().body(summary);
}

From source file:com.spartasystems.holdmail.rest.MessageController.java

@RequestMapping(value = "/{messageId}/content/{contentId}")
public ResponseEntity getMessageContentByPartId(@PathVariable("messageId") long messageId,
        @PathVariable("contentId") String contentId) {

    Message message = messageService.getMessage(messageId);

    MessageContentPart content = message.getContent().findByContentId(contentId);

    return ResponseEntity.ok().header("Content-Type", content.getContentType())
            .body(new InputStreamResource(content.getContentStream()));
}

From source file:com.spartasystems.holdmail.rest.MessageController.java

@RequestMapping(value = "/{messageId}/att/{attId}")
public ResponseEntity getMessageContentByAttachmentId(@PathVariable("messageId") long messageId,
        @PathVariable("attId") int attId) {

    Message message = messageService.getMessage(messageId);

    MessageContentPart content = message.getContent().findBySequenceId(attId);

    String disposition = "attachment;";

    if (StringUtils.isNotBlank(content.getAttachmentFilename())) {
        disposition += " filename=\"" + content.getAttachmentFilename() + "\";";
    }/*from w w  w . j a va 2  s .com*/

    return ResponseEntity.ok().header("Content-Type", content.getContentType())
            .header("Content-Disposition", disposition)
            .body(new InputStreamResource(content.getContentStream()));
}

From source file:com.spartasystems.holdmail.rest.MessageController.java

protected ResponseEntity serveContent(Object data, MediaType mediaType) {

    if (data == null) {
        return ResponseEntity.notFound().build();
    }//from w w  w  . j a v a  2 s.  c o m
    return ResponseEntity.ok().contentType(mediaType).body(data);
}

From source file:com.tyro.oss.pact.spring4.pact.consumer.ReturnExpect.java

/**
 * Record this expectation and expect no return value. This implies a 200 OK response with an empty response body.
 *///w w  w  . j a va 2s .  co m
public void andReturn() {
    createRequestExpectation(ResponseEntity.ok().build(), null);
}