Skip to content

Update dependencies to handle vulnerability - CVE-2020-8908 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
target
bin
bin
.idea
.settings
27 changes: 2 additions & 25 deletions api2pdf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ This client library is a wrapper for the Api2Pdf.com REST API. See full REST api
<artifactId>
jackson-databind
</artifactId>
<version>2.12.4</version>
<version>2.13.4</version>
</dependency>
<dependency>
<groupId>
Expand All @@ -118,7 +118,7 @@ This client library is a wrapper for the Api2Pdf.com REST API. See full REST api
<artifactId>
maven-filtering
</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>
</dependency>
</dependencies>
<build>
Expand Down Expand Up @@ -173,29 +173,6 @@ This client library is a wrapper for the Api2Pdf.com REST API. See full REST api
2.8.2
</version>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-javadoc-plugin
</artifactId>
<version>
2.9.1
</version>
<executions>
<execution>
<id>
attach-javadocs
</id>
<goals>
<goal>
jar
</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
Expand Down
45 changes: 12 additions & 33 deletions api2pdf/src/main/java/com/api2pdf/client/Api2PdfClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

public class Api2PdfClient {
private static final String API2PDF_BASE_URL = "https://v2.api2pdf.com";
private String _baseUrl;
private String _apiKey;
private final String _baseUrl;
private final String _apiKey;

public Api2PdfClient(String apiKey) {
this._apiKey = apiKey;
Expand Down Expand Up @@ -65,7 +65,7 @@ private Api2PdfResponse makeRequest(String payload, HttpURLConnection con)

BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
StringBuilder response = new StringBuilder();

while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
Expand All @@ -78,13 +78,16 @@ private Api2PdfResponse makeRequest(String payload, HttpURLConnection con)
System.out.println(jsonResponse);

ObjectMapper objectMapper = new ObjectMapper();
Api2PdfResponse api2pdfResponse = objectMapper.readValue(jsonResponse, Api2PdfResponse.class);
return api2pdfResponse;
return objectMapper.readValue(jsonResponse, Api2PdfResponse.class);
}

public Api2PdfResponse libreofficeAnyToPdf(String url, boolean inline, String fileName)
throws IOException {
HttpURLConnection con = getConnection(this._baseUrl + "/libreoffice/any-to-pdf");
return getApi2PdfResponse(url, inline, fileName, con);
}

private Api2PdfResponse getApi2PdfResponse(String url, boolean inline, String fileName, HttpURLConnection con) throws IOException {
Api2PdfFromUrlRequestModel model = new Api2PdfFromUrlRequestModel();
model.setUrl(url);
model.setInline(inline);
Expand All @@ -97,49 +100,25 @@ public Api2PdfResponse libreofficeAnyToPdf(String url, boolean inline, String fi
public Api2PdfResponse libreofficeHtmlToDocx(String url, boolean inline, String fileName)
throws IOException {
HttpURLConnection con = getConnection(this._baseUrl + "/libreoffice/html-to-docx");
Api2PdfFromUrlRequestModel model = new Api2PdfFromUrlRequestModel();
model.setUrl(url);
model.setInline(inline);
model.setFileName(fileName);
ObjectMapper objectMapper = new ObjectMapper();
String payload = objectMapper.writeValueAsString(model);
return makeRequest(payload, con);
return getApi2PdfResponse(url, inline, fileName, con);
}

public Api2PdfResponse libreofficeHtmlToXlsx(String url, boolean inline, String fileName)
throws IOException {
HttpURLConnection con = getConnection(this._baseUrl + "/libreoffice/html-to-xlsx");
Api2PdfFromUrlRequestModel model = new Api2PdfFromUrlRequestModel();
model.setUrl(url);
model.setInline(inline);
model.setFileName(fileName);
ObjectMapper objectMapper = new ObjectMapper();
String payload = objectMapper.writeValueAsString(model);
return makeRequest(payload, con);
return getApi2PdfResponse(url, inline, fileName, con);
}

public Api2PdfResponse libreofficeThumbnail(String url, boolean inline, String fileName)
throws IOException {
HttpURLConnection con = getConnection(this._baseUrl + "/libreoffice/thumbnail");
Api2PdfFromUrlRequestModel model = new Api2PdfFromUrlRequestModel();
model.setUrl(url);
model.setInline(inline);
model.setFileName(fileName);
ObjectMapper objectMapper = new ObjectMapper();
String payload = objectMapper.writeValueAsString(model);
return makeRequest(payload, con);
return getApi2PdfResponse(url, inline, fileName, con);
}

public Api2PdfResponse libreofficePdfToHtml(String url, boolean inline, String fileName)
throws IOException {
HttpURLConnection con = getConnection(this._baseUrl + "/libreoffice/pdf-to-html");
Api2PdfFromUrlRequestModel model = new Api2PdfFromUrlRequestModel();
model.setUrl(url);
model.setInline(inline);
model.setFileName(fileName);
ObjectMapper objectMapper = new ObjectMapper();
String payload = objectMapper.writeValueAsString(model);
return makeRequest(payload, con);
return getApi2PdfResponse(url, inline, fileName, con);
}

public Api2PdfResponse pdfsharpMerge(String[] pdfUrls, boolean inline, String fileName) throws IOException {
Expand Down
26 changes: 13 additions & 13 deletions api2pdf/src/test/java/api2pdf/Api2PdfClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public void testLibreofficeAnyToPdf() throws IOException {

@Test
public void testLibreofficeHtmlToDocx() throws IOException {
Api2PdfResponse response = a2pClient.libreofficeHtmlToDocx("http://www.api2pdf.com/wp-content/uploads/2021/01/sampleHtml.html", true,
Api2PdfResponse response = a2pClient.libreofficeHtmlToDocx("https://www.api2pdf.com/wp-content/uploads/2021/01/sampleHtml.html", true,
"test.docx");
Assert.assertEquals(response.getSuccess(), true);
}

@Test
public void testLibreofficeHtmlToXlsx() throws IOException {
Api2PdfResponse response = a2pClient.libreofficeHtmlToXlsx("http://www.api2pdf.com/wp-content/uploads/2021/01/sampleTables.html", true,
Api2PdfResponse response = a2pClient.libreofficeHtmlToXlsx("https://www.api2pdf.com/wp-content/uploads/2021/01/sampleTables.html", true,
"test.xlsx");
Assert.assertEquals(response.getSuccess(), true);
}
Expand All @@ -50,30 +50,30 @@ public void testLibreofficeThumbnail() throws IOException {

@Test
public void testLibreofficePdfToHtml() throws IOException {
Api2PdfResponse response = a2pClient.libreofficePdfToHtml("http://www.api2pdf.com/wp-content/uploads/2021/01/1a082b03-2bd6-4703-989d-0443a88e3b0f-4.pdf", true,
Api2PdfResponse response = a2pClient.libreofficePdfToHtml("https://www.api2pdf.com/wp-content/uploads/2021/01/1a082b03-2bd6-4703-989d-0443a88e3b0f-4.pdf", true,
"test.html");
Assert.assertEquals(response.getSuccess(), true);
}

@Test
public void testPdfSharpMerge() throws IOException {
String[] urls = { "http://www.api2pdf.com/wp-content/uploads/2021/01/1a082b03-2bd6-4703-989d-0443a88e3b0f-4.pdf",
"http://www.api2pdf.com/wp-content/uploads/2021/01/1a082b03-2bd6-4703-989d-0443a88e3b0f-4.pdf" };
String[] urls = {"https://www.api2pdf.com/wp-content/uploads/2021/01/1a082b03-2bd6-4703-989d-0443a88e3b0f-4.pdf",
"https://www.api2pdf.com/wp-content/uploads/2021/01/1a082b03-2bd6-4703-989d-0443a88e3b0f-4.pdf"};
Api2PdfResponse response = a2pClient.pdfsharpMerge(urls, true, "test.pdf");
Assert.assertEquals(response.getSuccess(), true);
}

@Test
public void testPdfSharpAddBookmark() throws IOException {
String url = "http://www.api2pdf.com/wp-content/uploads/2021/01/1a082b03-2bd6-4703-989d-0443a88e3b0f-4.pdf";
String url = "https://www.api2pdf.com/wp-content/uploads/2021/01/1a082b03-2bd6-4703-989d-0443a88e3b0f-4.pdf";
Api2PdfBookmarkItemModel[] bookmarks = new Api2PdfBookmarkItemModel[] { new Api2PdfBookmarkItemModel(0, "Title page") };
Api2PdfResponse response = a2pClient.pdfsharpAddBookmarks(url, bookmarks, true, "test.pdf");
Assert.assertEquals(response.getSuccess(), true);
}

@Test
public void testPdfSharpAddPassword() throws IOException {
String url = "http://www.api2pdf.com/wp-content/uploads/2021/01/1a082b03-2bd6-4703-989d-0443a88e3b0f-4.pdf";
String url = "https://www.api2pdf.com/wp-content/uploads/2021/01/1a082b03-2bd6-4703-989d-0443a88e3b0f-4.pdf";
String password = "hello";
Api2PdfResponse response = a2pClient.pdfsharpAddPassword(url, password, true, "test.pdf");
Assert.assertEquals(response.getSuccess(), true);
Expand All @@ -88,7 +88,7 @@ public void testWkhtmlHtmlToPdf() throws IOException {

@Test
public void testWkhtmlHtmlToPdfWithOptions() throws IOException {
HashMap<String, String> options = new HashMap<String, String>();
HashMap<String, String> options = new HashMap<>();
options.put("orientation", "landscape");
options.put("pageSize", "A4");
Api2PdfResponse response = a2pClient.wkhtmlHtmlToPdf("<p>test</p>",
Expand All @@ -105,7 +105,7 @@ public void testWkhtmlUrlToPdf() throws IOException {

@Test
public void testWkhtmlUrlToPdfWithOptions() throws IOException {
HashMap<String, String> options = new HashMap<String, String>();
HashMap<String, String> options = new HashMap<>();
options.put("orientation", "landscape");
options.put("pageSize", "A4");
Api2PdfResponse response = a2pClient.wkhtmlUrlToPdf("https://www.api2pdf.com",
Expand All @@ -122,7 +122,7 @@ public void testChromeHtmlToPdf() throws IOException {

@Test
public void testChromeHtmlToPdfWithOptions() throws IOException {
HashMap<String, String> options = new HashMap<String, String>();
HashMap<String, String> options = new HashMap<>();
options.put("landscape", "true");
Api2PdfResponse response = a2pClient.chromeHtmlToPdf("<p>test</p>",
true, "test.pdf", options);
Expand All @@ -138,7 +138,7 @@ public void testChromeUrlToPdf() throws IOException {

@Test
public void testChromeUrlToPdfWithOptions() throws IOException {
HashMap<String, String> options = new HashMap<String, String>();
HashMap<String, String> options = new HashMap<>();
options.put("orientation", "landscape");
Api2PdfResponse response = a2pClient.chromeUrlToPdf("https://www.api2pdf.com",
true, "test.pdf", options);
Expand All @@ -154,7 +154,7 @@ public void testChromeHtmlToImage() throws IOException {

@Test
public void testChromeHtmlToImageWithOptions() throws IOException {
HashMap<String, String> options = new HashMap<String, String>();
HashMap<String, String> options = new HashMap<>();
options.put("fullPage", "false");
Api2PdfResponse response = a2pClient.chromeHtmlToPdf("<p>test</p>",
true, "test.png", options);
Expand All @@ -170,7 +170,7 @@ public void testChromeUrlToImage() throws IOException {

@Test
public void testChromeUrlToImageWithOptions() throws IOException {
HashMap<String, String> options = new HashMap<String, String>();
HashMap<String, String> options = new HashMap<>();
options.put("fullPage", "false");
Api2PdfResponse response = a2pClient.chromeUrlToImage("https://www.api2pdf.com",
true, "test.png", options);
Expand Down