com.dynamicpdf.api.PdfInfo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dynamicpdf-api Show documentation
Show all versions of dynamicpdf-api Show documentation
A Java Client API that uses the DynamicPDF API to create, merge, split, form fill, stamp, secure/encrypt PDF documents.
package com.dynamicpdf.api;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
/**
* Represents the pdf info endpoint.
*/
public class PdfInfo extends Endpoint
{
private PdfResource resource;
/**
* Initializes a new instance of the PdfInfo
class.
* @param resource The resource of type PdfResource
.
*/
public PdfInfo(PdfResource resource)
{
this.resource = resource;
}
String getEndpointName() { return "pdf-info";}
/**
* Process the pdf resource to get pdf's information.
* @return collection of PdfInfoResponse
as multithreading tasks Task
.
*/
public PdfInfoResponse process()
{
CompletableFuture cf = processAsync();
try {
return cf.get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
return null;
}
/**
* Process the pdf resource to get pdf's information.
*
* @return collection of PdfInfoResponse
as multithreading tasks CompletableFuture
.
*/
public CompletableFuture processAsync()
{
return CompletableFuture.supplyAsync(() -> {
PdfInfoResponse pdfInfoResponse = null;
RequestSpecification requestSpec = super.createRequestSpecification();
Response response = RestAssured
.given()
.header("Accept", "application/pdf")
.header("content-type", "application/pdf")
.spec(requestSpec)
.body(resource.getData())
.post(getDefaultBaseUrl() + "/"+ getEndpointVersion() + "/" + getEndpointName());
if (response.getStatusCode() == 200)
{
pdfInfoResponse = new PdfInfoResponse(response.asString());
pdfInfoResponse.setIsSuccessful(true);
pdfInfoResponse.setStatusCode(response.getStatusCode());
}
else
{
pdfInfoResponse = new PdfInfoResponse();
pdfInfoResponse.setErrorJson(response.asString());
pdfInfoResponse.setIsSuccessful(false);
pdfInfoResponse.setStatusCode(response.getStatusCode());
}
return pdfInfoResponse;
});
}
}