Example usage for java.util.concurrent Future get

List of usage examples for java.util.concurrent Future get

Introduction

In this page you can find the example usage for java.util.concurrent Future get.

Prototype

V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException;

Source Link

Document

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

Usage

From source file:de.taimos.dvalin.test.jaxrs.APITest.java

/**
 * creates a web socket connection to the given path using the supplied client socket adapter
 *
 * @param path   the path of the websocket target
 * @param socket the client socket to use
 * @return the created {@link WebSocketClient}
 * @throws RuntimeException if connection fails
 *//* w  w w . j  av a2  s  .co m*/
protected WebSocketClient openWebsocket(String path, ClientSocketAdapter socket) {
    try {
        WebSocketClient cl = new WebSocketClient();
        cl.start();
        ClientUpgradeRequest request = new ClientUpgradeRequest();
        socket.modifyRequest(request);
        Future<Session> socketSession = cl.connect(socket, URI.create(this.getWebSocketURL() + path), request);
        socketSession.get(5, TimeUnit.SECONDS);
        return cl;
    } catch (Exception e) {
        throw new RuntimeException("WebSocket failed", e);
    }
}

From source file:apiserver.services.images.controllers.filters.BoxBlurController.java

/**
 * A filter which performs a box blur on an uploaded image. The horizontal and vertical blurs can be specified separately and a number of iterations can be given which allows an approximation to Gaussian blur.
 *
 * @param file/*from w  ww  . j  a  v a2s.co  m*/
 * @param hRadius
 * @param vRadius
 * @param iterations
 * @param preMultiplyAlpha
 * @param format
 * @return
 * @throws java.util.concurrent.TimeoutException
 * @throws java.util.concurrent.ExecutionException
 * @throws InterruptedException
 * @throws java.io.IOException
 */
@ApiOperation(value = "A filter which performs a box blur on an image. The horizontal and vertical blurs can be specified separately and a number of iterations can be given which allows an approximation to Gaussian blur.")
@RequestMapping(value = "/filter/boxblur", method = { RequestMethod.POST })
@ResponseBody
public ResponseEntity<byte[]> imageBoxBlurByFile(HttpServletRequest request, HttpServletResponse response,
        @ApiParam(name = "file", required = false) @RequestParam(value = "file", required = false) MultipartFile file,
        @ApiParam(name = "format", required = false) @RequestParam(value = "format", required = false) String format,
        @ApiParam(name = "hRadius", required = false, defaultValue = "2", value = "the horizontal radius of blur") @RequestParam(value = "hRadius", required = false, defaultValue = "2") int hRadius,
        @ApiParam(name = "vRadius", required = false, defaultValue = "2", value = "the vertical radius of blur") @RequestParam(value = "vRadius", required = false, defaultValue = "2") int vRadius,
        @ApiParam(name = "iterations", required = false, defaultValue = "1", value = "the number of time to iterate the blur") @RequestParam(value = "iterations", defaultValue = "1") int iterations,
        @ApiParam(name = "preMultiplyAlpha", required = false, defaultValue = "true", allowableValues = "true,false", value = "pre multiply the alpha channel") @RequestParam(value = "preMultiplyAlpha", required = false, defaultValue = "true") boolean preMultiplyAlpha

) throws TimeoutException, ExecutionException, InterruptedException, IOException {
    Document _file = null;
    MimeType _outputMimeType = null;
    String _outputContentType = null;

    MultipartFile _mFile = fileUploadHelper.getFileFromRequest(file, request);
    _file = new Document(_mFile);
    _outputMimeType = fileUploadHelper.getOutputFileFormat(format, _file.getContentType());
    _outputContentType = _outputMimeType.contentType;
    if (!_file.getContentType().isSupportedImage() || !_outputMimeType.isSupportedImage()) {
        return new ResponseEntity<>(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
    }

    BoxBlurJob job = new BoxBlurJob();
    job.setDocumentId(null);
    job.setDocument(_file);

    job.setHRadius(hRadius);
    job.setVRadius(vRadius);
    job.setIterations(iterations);
    job.setPreMultiplyAlpha(preMultiplyAlpha);

    Future<Map> imageFuture = imageFilterBoxBlurGateway.imageBoxBlurFilter(job);
    ImageDocumentJob payload = (ImageDocumentJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS);

    ResponseEntity<byte[]> result = ResponseEntityHelper.processImage(payload.getBufferedImage(),
            _outputContentType, false);
    return result;
}

From source file:apiserver.services.images.controllers.filters.BumpController.java

/**
 * This filter does a simple convolution which emphasises edges in an uploaded image.
 *
 * @param documentId//from w  w w  . ja va2  s. c  o  m
 * @param format
 * @param edgeAction
 * @param useAlpha
 * @param matrix
 * @return
 * @throws java.util.concurrent.TimeoutException
 * @throws java.util.concurrent.ExecutionException
 * @throws InterruptedException
 * @throws java.io.IOException
 */
@ApiOperation(value = "This filter does a simple convolution which emphasises edges in an image.")
@RequestMapping(value = "/filter/{documentId}/bump.{format}", method = { RequestMethod.GET })
public ResponseEntity<byte[]> imageBumpByFile(
        @ApiParam(name = "documentId", required = true, defaultValue = "8D981024-A297-4169-8603-E503CC38EEDA") @PathVariable(value = "documentId") String documentId,
        @ApiParam(name = "format", required = true, defaultValue = "jpg") @PathVariable(value = "format") String format

        ,
        @ApiParam(name = "edgeAction", required = false, defaultValue = "1") @RequestParam(value = "edgeAction", required = false, defaultValue = "1") int edgeAction,
        @ApiParam(name = "useAlpha", required = false, defaultValue = "true", allowableValues = "true,false") @RequestParam(value = "useAlpha", required = false, defaultValue = "true") boolean useAlpha,
        @ApiParam(name = "matrix", required = false, defaultValue = "-1.0,-1.0,0.0,-1.0,1.0,1.0,0.0,1.0,1.0") @RequestParam(value = "matrix", required = false, defaultValue = "-1.0,-1.0,0.0,-1.0,1.0,1.0,0.0,1.0,1.0") String matrix

) throws TimeoutException, ExecutionException, InterruptedException, IOException {
    String _contentType = MimeType.getMimeType(format).contentType;
    if (!MimeType.getMimeType(format).isSupportedImage()) {
        return new ResponseEntity<byte[]>(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
    }

    // convert string array into float array
    String[] matrixStrings = matrix.split(",");
    float[] matrixValues = new float[matrixStrings.length];
    for (int i = 0; i < matrixStrings.length; i++) {
        String s = matrixStrings[i];
        matrixValues[i] = Float.parseFloat(s);
    }

    BumpJob args = new BumpJob();
    args.setDocumentId(documentId);
    args.setEdgeAction(edgeAction);
    args.setUseAlpha(useAlpha);
    args.setMatrix(matrixValues);

    Future<Map> imageFuture = imageFilterBumpGateway.imageBumpFilter(args);
    ImageDocumentJob payload = (ImageDocumentJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS);

    ResponseEntity<byte[]> result = ResponseEntityHelper.processImage(payload.getBufferedImage(), _contentType,
            false);
    return result;
}

From source file:apiserver.services.images.controllers.manipulations.TextController.java

/**
 * Overlay text onto an image/*from w  w  w  . ja v  a 2 s .c  om*/
 *
 * @param file
 * @param text
 * @param color
 * @param fontSize
 * @param fontStyle
 * @param angle
 * @param x
 * @param y
 * @return
 * @throws InterruptedException
 * @throws java.util.concurrent.ExecutionException
 * @throws java.util.concurrent.TimeoutException
 * @throws java.io.IOException
 */
@RequestMapping(value = "/modify/text", method = { RequestMethod.POST })
public ResponseEntity<byte[]> drawTextByImage(HttpServletRequest request, HttpServletResponse response,
        @ApiParam(name = "file", required = false) @RequestParam(value = "file", required = false) MultipartFile file,
        @ApiParam(name = "text", required = true) @RequestParam(required = true) String text,
        @ApiParam(name = "color", required = true) @RequestParam(required = true) String color,
        @ApiParam(name = "fontSize", required = true) @RequestParam(required = true) String fontSize,
        @ApiParam(name = "fontStyle", required = true) @RequestParam(required = true) String fontStyle,
        @ApiParam(name = "x", required = true) @RequestParam(required = true) Integer x,
        @ApiParam(name = "y", required = true) @RequestParam(required = true) Integer y,
        @ApiParam(name = "format", required = false) @RequestParam(value = "format", required = false) String format

) throws InterruptedException, ExecutionException, TimeoutException, IOException {
    Document _file = null;
    MimeType _outputMimeType = null;
    String _outputContentType = null;

    MultipartFile _mFile = fileUploadHelper.getFileFromRequest(file, request);
    _file = new Document(_mFile);
    _outputMimeType = fileUploadHelper.getOutputFileFormat(format, _file.getContentType());
    _outputContentType = _outputMimeType.contentType;
    if (!_file.getContentType().isSupportedImage() || !_outputMimeType.isSupportedImage()) {
        return new ResponseEntity<>(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
    }

    FileTextJob job = new FileTextJob();
    job.setDocumentId(null);
    job.setDocument(_file);
    //job.getDocument().setContentType(MimeType.getMimeType(file.getContentType()));
    //job.getDocument().setFileName(file.getOriginalFilename());
    job.setText(text);
    job.setColor(color);
    job.setFontSize(fontSize);
    job.setFontStyle(fontStyle);
    job.setX(x);
    job.setY(y);
    job.setFormat(format);

    Future<Map> imageFuture = imageDrawTextGateway.imageDrawTextFilter(job);
    FileTextJob payload = (FileTextJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS);

    //pass CF Response back to the client
    return payload.getHttpResponse();

}

From source file:it.anyplace.sync.discovery.utils.AddressRanker.java

private void testAndRankAndWait() throws InterruptedException {
    logger.trace("testing and ranking peer addresses");
    List<Future<DeviceAddress>> futures = Lists.newArrayList();
    for (final DeviceAddress deviceAddress : preprocessDeviceAddresses(sourceAddresses)) {
        futures.add(executorService.submit(new Callable<DeviceAddress>() {

            @Override/*w  ww. ja  v a  2  s  .c  o m*/
            public DeviceAddress call() {
                return testAndRank(deviceAddress);
            }
        }));
    }
    for (Future<DeviceAddress> future : futures) {
        try {
            DeviceAddress deviceAddress = future.get(TCP_CONNECTION_TIMEOUT * 2, TimeUnit.MILLISECONDS);
            if (deviceAddress != null) {
                targetAddresses.add(deviceAddress);
            }
        } catch (ExecutionException ex) {
            throw new RuntimeException(ex);
        } catch (TimeoutException ex) {
            logger.warn("test address timeout : {}", ex.toString());
        }
    }
    Collections.sort(targetAddresses, Ordering.natural().onResultOf(new Function<DeviceAddress, Comparable>() {
        @Override
        public Comparable apply(DeviceAddress a) {
            return a.getScore();
        }
    }));
}

From source file:org.openbaton.autoscaling.core.management.ElasticityManagement.java

@Async
public Future<Boolean> deactivate(String nsr_id, String vnfr_id) {
    log.info("Deactivating Elasticity for NSR with id: " + nsr_id);
    Set<Future<Boolean>> pendingTasks = new HashSet<>();
    if (autoScalingProperties.getPool().isActivate()) {
        try {//from w w  w .j  a  v a  2s . c  om
            pendingTasks.add(poolManagement.deactivate(nsr_id, vnfr_id));
        } catch (NotFoundException e) {
            log.warn(e.getMessage());
            if (log.isDebugEnabled()) {
                log.error(e.getMessage(), e);
            }
        } catch (VimException e) {
            log.warn(e.getMessage());
            if (log.isDebugEnabled()) {
                log.error(e.getMessage(), e);
            }
        }
    }
    try {
        pendingTasks.add(detectionManagment.stop(nsr_id, vnfr_id));
    } catch (NotFoundException e) {
        log.error(e.getMessage(), e);
    }
    pendingTasks.add(decisionManagement.stop(nsr_id, vnfr_id));
    pendingTasks.add(executionManagement.stop(nsr_id, vnfr_id));
    for (Future<Boolean> pendingTask : pendingTasks) {
        try {
            pendingTask.get(60, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            if (log.isDebugEnabled()) {
                log.error(e.getMessage(), e);
            }
        } catch (ExecutionException e) {
            if (log.isDebugEnabled()) {
                log.error(e.getMessage(), e);
            }
        } catch (TimeoutException e) {
            if (log.isDebugEnabled()) {
                log.error(e.getMessage(), e);
            }
        }
    }
    log.info("Deactivated Elasticity for NSR with id: " + nsr_id);
    return new AsyncResult<>(true);
}

From source file:apiserver.services.images.controllers.filters.BumpController.java

/**
 * This filter does a simple convolution which emphasises edges in an uploaded image.
 *
 * @param file//ww w .  java2  s.  c om
 * @param format
 * @param edgeAction
 * @param useAlpha
 * @param matrix
 * @return
 * @throws java.util.concurrent.TimeoutException
 * @throws java.util.concurrent.ExecutionException
 * @throws InterruptedException
 * @throws java.io.IOException
 */
@ApiOperation(value = "This filter does a simple convolution which emphasises edges in an image.")
@RequestMapping(value = "/filter/bump", method = { RequestMethod.POST })
public ResponseEntity<byte[]> imageBumpByFile(HttpServletRequest request, HttpServletResponse response,
        @ApiParam(name = "file", required = false) @RequestParam(value = "file", required = false) MultipartFile file,
        @ApiParam(name = "format", required = false) @RequestParam(value = "format", required = false) String format,
        @ApiParam(name = "edgeAction", required = false, defaultValue = "1") @RequestParam(value = "edgeAction", required = false, defaultValue = "1") int edgeAction,
        @ApiParam(name = "useAlpha", required = false, defaultValue = "true", allowableValues = "true,false") @RequestParam(value = "useAlpha", required = false, defaultValue = "true") boolean useAlpha,
        @ApiParam(name = "matrix", required = false, defaultValue = "-1.0,-1.0,0.0,-1.0,1.0,1.0,0.0,1.0,1.0") @RequestParam(value = "matrix", required = false, defaultValue = "-1.0,-1.0,0.0,-1.0,1.0,1.0,0.0,1.0,1.0") String matrix

) throws TimeoutException, ExecutionException, InterruptedException, IOException {
    Document _file = null;
    MimeType _outputMimeType = null;
    String _outputContentType = null;

    MultipartFile _mFile = fileUploadHelper.getFileFromRequest(file, request);
    _file = new Document(_mFile);
    _outputMimeType = fileUploadHelper.getOutputFileFormat(format, _file.getContentType());
    _outputContentType = _outputMimeType.contentType;
    if (!_file.getContentType().isSupportedImage() || !_outputMimeType.isSupportedImage()) {
        return new ResponseEntity<>(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
    }

    // convert string array into float array
    String[] matrixStrings = matrix.split(",");
    float[] matrixValues = new float[matrixStrings.length];
    for (int i = 0; i < matrixStrings.length; i++) {
        String s = matrixStrings[i];
        matrixValues[i] = Float.parseFloat(s);
    }

    BumpJob job = new BumpJob();
    job.setDocumentId(null);
    job.setDocument(_file);

    job.setEdgeAction(edgeAction);
    job.setUseAlpha(useAlpha);
    job.setMatrix(matrixValues);

    Future<Map> imageFuture = imageFilterBumpGateway.imageBumpFilter(job);
    ImageDocumentJob payload = (ImageDocumentJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS);

    ResponseEntity<byte[]> result = ResponseEntityHelper.processImage(payload.getBufferedImage(),
            _outputContentType, false);
    return result;
}

From source file:apiserver.services.pdf.controllers.ConvertUrlController.java

/**
 * Convert the html returned from a url to pdf
 * @param path/*from   w ww.  ja  v a2s .  co  m*/
 * @return
 * @throws InterruptedException
 * @throws java.util.concurrent.ExecutionException
 * @throws java.util.concurrent.TimeoutException
 * @throws java.io.IOException
 */
@ApiOperation(value = "Convert a URL into a PDF document.")
@RequestMapping(value = "/convert/url", method = { RequestMethod.GET })
public ResponseEntity<byte[]> url2pdf(
        @ApiParam(name = "path", required = true) @RequestParam(value = "path") String path,
        // Optional arguments
        @ApiParam(name = "backgroundVisible", required = false, defaultValue = "true") @RequestParam(value = "backgroundVisible") Boolean backgroundVisible,
        @ApiParam(name = "encryption", required = false, defaultValue = "none", allowableValues = "128-bit,40-bit,none") @RequestParam(value = "encryption") CFDocumentJob.Encryption encryption,
        @ApiParam(name = "fontEmbed", required = false, defaultValue = "true", allowableValues = "true,false") @RequestParam(value = "fontEmbed") Boolean fontEmbed,
        @ApiParam(name = "marginBottom", required = false, defaultValue = "0") @RequestParam(value = "marginBottom", defaultValue = "0") Integer marginBottom,
        @ApiParam(name = "marginTop", required = false, defaultValue = "0") @RequestParam(value = "marginTop", defaultValue = "0") Integer marginTop,
        @ApiParam(name = "marginLeft", required = false, defaultValue = "0") @RequestParam(value = "marginLeft", defaultValue = "0") Integer marginLeft,
        @ApiParam(name = "marginRight", required = false, defaultValue = "0") @RequestParam(value = "marginRight", defaultValue = "0") Integer marginRight,
        @ApiParam(name = "orientation", required = false, defaultValue = "portrait", allowableValues = "portrait,landscape") @RequestParam(value = "orientation", defaultValue = "0") CFDocumentJob.Orientation orientation,
        @ApiParam(name = "ownerPassword", required = false) @RequestParam(value = "ownerPassword") String ownerPassword,
        @ApiParam(name = "pageHeight", required = false) @RequestParam(value = "pageHeight") Integer pageHeight,
        @ApiParam(name = "pageWidth", required = false) @RequestParam(value = "pageWidth") Integer pageWidth,
        @ApiParam(name = "pageType", required = false, defaultValue = "letter", allowableValues = "legal,letter,a4,a5,b4,b5,b4-jis,b5-jis,custom") @RequestParam(value = "pageType", defaultValue = "letter") CFDocumentJob.PageType pageType,
        @ApiParam(name = "scale", required = false) @RequestParam(value = "scale") Integer scale,
        @ApiParam(name = "unit", required = false) @RequestParam(value = "unit") CFDocumentJob.Unit unit,
        @ApiParam(name = "userPassword", required = false) @RequestParam(value = "userPassword") String userPassword,
        // Permisions[] items
        @ApiParam(name = "allowPrinting", required = false, defaultValue = "false") @RequestParam(value = "allowPrinting", defaultValue = "false") Boolean allowPrinting,
        @ApiParam(name = "allowModifyContents", required = false, defaultValue = "false") @RequestParam(value = "allowModifyContents", defaultValue = "false") Boolean allowModifyContents,
        @ApiParam(name = "allowCopy", required = false, defaultValue = "false") @RequestParam(value = "allowCopy", defaultValue = "false") Boolean allowCopy,
        @ApiParam(name = "allowModifyAnnotations", required = false, defaultValue = "false") @RequestParam(value = "allowModifyAnnotations", defaultValue = "false") Boolean allowModifyAnnotations,
        @ApiParam(name = "allowFillIn", required = false, defaultValue = "false") @RequestParam(value = "allowFillIn", defaultValue = "false") Boolean allowFillIn,
        @ApiParam(name = "allowScreenReaders", required = false, defaultValue = "false") @RequestParam(value = "allowScreenReaders", defaultValue = "false") Boolean allowScreenReaders,
        @ApiParam(name = "allowAssembly", required = false, defaultValue = "false") @RequestParam(value = "allowAssembly", defaultValue = "false") Boolean allowAssembly,
        @ApiParam(name = "allowDegradedPrinting", required = false, defaultValue = "false") @RequestParam(value = "allowDegradedPrinting", defaultValue = "false") Boolean allowDegradedPrinting)
        throws InterruptedException, ExecutionException, TimeoutException, IOException {
    Url2PdfJob args = new Url2PdfJob();
    args.setPath(path);

    if (backgroundVisible != null)
        args.setBackgroundVisible(backgroundVisible);
    if (encryption != null)
        args.setEncryption(encryption);
    if (fontEmbed != null)
        args.setFontEmbed(fontEmbed);
    if (marginBottom != null)
        args.setMarginBottom(marginBottom);
    if (marginTop != null)
        args.setMarginTop(marginTop);
    if (marginLeft != null)
        args.setMarginLeft(marginLeft);
    if (marginRight != null)
        args.setMarginRight(marginRight);
    if (orientation != null)
        args.setOrientation(orientation);
    if (ownerPassword != null)
        args.setOwnerPassword(ownerPassword);
    if (pageHeight != null)
        args.setPageHeight(pageHeight);
    if (pageWidth != null)
        args.setPageWidth(pageWidth);
    if (pageType != null)
        args.setPageType(pageType);
    if (scale != null)
        args.setScale(scale);
    if (unit != null)
        args.setUnit(unit);
    if (userPassword != null)
        args.setUserPassword(userPassword);

    List<CFDocumentJob.Permission> permissionsArray = new ArrayList();
    if (allowAssembly)
        permissionsArray.add(CFDocumentJob.Permission.AllowAssembly);
    if (allowCopy)
        permissionsArray.add(CFDocumentJob.Permission.AllowCopy);
    if (allowDegradedPrinting)
        permissionsArray.add(CFDocumentJob.Permission.AllowDegradedPrinting);
    if (allowFillIn)
        permissionsArray.add(CFDocumentJob.Permission.AllowFillIn);
    if (allowModifyAnnotations)
        permissionsArray.add(CFDocumentJob.Permission.AllowModifyAnnotations);
    if (allowModifyContents)
        permissionsArray.add(CFDocumentJob.Permission.AllowModifyContents);
    if (allowScreenReaders)
        permissionsArray.add(CFDocumentJob.Permission.AllowScreenReaders);
    if (allowPrinting)
        permissionsArray.add(CFDocumentJob.Permission.AllowPrinting);
    args.setPermissions((CFDocumentJob.Permission[]) permissionsArray.toArray());

    Future<Map> future = gateway.convertUrlToPdf(args);
    BinaryJob payload = (BinaryJob) future.get(defaultTimeout, TimeUnit.MILLISECONDS);

    byte[] fileBytes = payload.getPdfBytes();
    String contentType = "application/pdf";
    ResponseEntity<byte[]> result = ResponseEntityHelper.processFile(fileBytes, contentType, false);
    return result;
}

From source file:se.omegapoint.facepalm.infrastructure.FilePolicyRepository.java

@Override
public Optional<Policy> retrievePolicyWith(final String filename) {
    notBlank(filename);/*  w  w w . j a  va 2s  .  com*/

    final ExecutorService executorService = Executors.newSingleThreadExecutor();
    final Command command = commandBasedOnOperatingSystem(filename);
    final Future<String> future = executorService.submit(command);

    try {
        eventService.publish(new GenericEvent(format("About to execute command[%s]", command.command)));
        return Optional.of(new Policy(future.get(TIMEOUT, TimeUnit.SECONDS)));
    } catch (Exception e) {
        return Optional.empty();
    }
}

From source file:apiserver.services.pdf.controllers.ProtectController.java

/**
 * Secure a cached pdf with a password/*from  w w  w  . j  a v a2  s  .  c o m*/
 * @param documentId
 * @return
 * @throws InterruptedException
 * @throws java.util.concurrent.ExecutionException
 * @throws java.util.concurrent.TimeoutException
 * @throws java.io.IOException
 * @throws Exception
 */
@ApiOperation(value = "Secure a cached pdf with a password")
@RequestMapping(value = "/{documentId}/protect", method = RequestMethod.GET, produces = "application/pdf")
public ResponseEntity<byte[]> protectPdf(
        @ApiParam(name = "documentId", required = true) @RequestPart("documentId") String documentId,
        @ApiParam(name = "password", required = false, value = "Owner or user password of the source PDF document, if the document is password-protected.") @RequestPart("password") String password,
        @ApiParam(name = "newUserPassword", required = true, value = "Password used to open PDF document.") @RequestPart("newUserPassword") String newUserPassword,
        @ApiParam(name = "newOwnerPassword", required = true, value = "Password used to set permissions on a PDF document.") @RequestPart("newOwnerPassword") String newOwnerPassword,
        @ApiParam(name = "encrypt", required = false, allowableValues = "RC4_40,RC4_128,RC4_128M,AES_128,none", value = "Encryption type for the PDF output file:") @RequestPart("encrypt") String encrypt,
        @ApiParam(name = "allowAssembly", required = false, value = "permissions on the PDF document") @RequestPart("allowAssembly") Boolean allowAssembly,
        @ApiParam(name = "allowCopy", required = false, value = "permissions on the PDF document") @RequestPart("allowCopy") Boolean allowCopy,
        @ApiParam(name = "allowDegradedPrinting", required = false, value = "permissions on the PDF document") @RequestPart("allowDegradedPrinting") Boolean allowDegradedPrinting,
        @ApiParam(name = "allowFillIn", required = false, value = "permissions on the PDF document") @RequestPart("allowFillIn") Boolean allowFillIn,
        @ApiParam(name = "allowModifyAnnotations", required = false, value = "permissions on the PDF document") @RequestPart("allowModifyAnnotations") Boolean allowModifyAnnotations,
        @ApiParam(name = "allowPrinting", required = false, value = "permissions on the PDF document") @RequestPart("allowPrinting") Boolean allowPrinting,
        @ApiParam(name = "allowScreenReaders", required = false, value = "permissions on the PDF document") @RequestPart("allowScreenReaders") Boolean allowScreenReaders,
        @ApiParam(name = "allowSecure", required = false, value = "permissions on the PDF document") @RequestPart("allowSecure") Boolean allowSecure)
        throws InterruptedException, ExecutionException, TimeoutException, IOException, Exception {
    SecurePdfResult job = new SecurePdfResult();
    //file
    job.setDocumentId(documentId);
    if (password != null)
        job.setPassword(password);
    if (newUserPassword != null)
        job.setNewUserPassword(newUserPassword);
    if (newOwnerPassword != null)
        job.setNewOwnerPassword(newOwnerPassword);
    if (encrypt != null)
        job.setEncrypt(encrypt);
    // permission
    if (allowAssembly != null)
        job.setAllowAssembly(allowAssembly);
    if (allowCopy != null)
        job.setAllowCopy(allowCopy);
    if (allowDegradedPrinting != null)
        job.setAllowDegradedPrinting(allowDegradedPrinting);
    if (allowFillIn != null)
        job.setAllowFillIn(allowFillIn);
    if (allowModifyAnnotations != null)
        job.setAllowModifyAnnotations(allowModifyAnnotations);
    if (allowPrinting != null)
        job.setAllowPrinting(allowPrinting);
    if (allowScreenReaders != null)
        job.setAllowScreenReaders(allowScreenReaders);
    if (allowSecure != null)
        job.setAllowSecure(allowSecure);

    Future<Map> future = gateway.protectPdf(job);
    BinaryResult payload = (BinaryResult) future.get(defaultTimeout, TimeUnit.MILLISECONDS);

    byte[] fileBytes = payload.getResult();
    String contentType = "application/pdf";
    ResponseEntity<byte[]> result = ResponseEntityHelper.processFile(fileBytes, contentType, false);
    return result;
}