Skip to content

Commit 3febb5f

Browse files
authored
Merge pull request #7 from ammwinchande/master
Update dependencies to handle vulnerability - CVE-2020-8908
2 parents a47cacd + c050650 commit 3febb5f

4 files changed

Lines changed: 30 additions & 72 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
target
2-
bin
2+
bin
3+
.idea
4+
.settings

api2pdf/pom.xml

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ This client library is a wrapper for the Api2Pdf.com REST API. See full REST api
109109
<artifactId>
110110
jackson-databind
111111
</artifactId>
112-
<version>2.12.4</version>
112+
<version>2.13.4</version>
113113
</dependency>
114114
<dependency>
115115
<groupId>
@@ -118,7 +118,7 @@ This client library is a wrapper for the Api2Pdf.com REST API. See full REST api
118118
<artifactId>
119119
maven-filtering
120120
</artifactId>
121-
<version>3.2.0</version>
121+
<version>3.3.0</version>
122122
</dependency>
123123
</dependencies>
124124
<build>
@@ -173,29 +173,6 @@ This client library is a wrapper for the Api2Pdf.com REST API. See full REST api
173173
2.8.2
174174
</version>
175175
</plugin>
176-
<plugin>
177-
<groupId>
178-
org.apache.maven.plugins
179-
</groupId>
180-
<artifactId>
181-
maven-javadoc-plugin
182-
</artifactId>
183-
<version>
184-
2.9.1
185-
</version>
186-
<executions>
187-
<execution>
188-
<id>
189-
attach-javadocs
190-
</id>
191-
<goals>
192-
<goal>
193-
jar
194-
</goal>
195-
</goals>
196-
</execution>
197-
</executions>
198-
</plugin>
199176
<plugin>
200177
<groupId>
201178
org.apache.maven.plugins

api2pdf/src/main/java/com/api2pdf/client/Api2PdfClient.java

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
public class Api2PdfClient {
2424
private static final String API2PDF_BASE_URL = "https://v2.api2pdf.com";
25-
private String _baseUrl;
26-
private String _apiKey;
25+
private final String _baseUrl;
26+
private final String _apiKey;
2727

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

6666
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
6767
String inputLine;
68-
StringBuffer response = new StringBuffer();
68+
StringBuilder response = new StringBuilder();
6969

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

8080
ObjectMapper objectMapper = new ObjectMapper();
81-
Api2PdfResponse api2pdfResponse = objectMapper.readValue(jsonResponse, Api2PdfResponse.class);
82-
return api2pdfResponse;
81+
return objectMapper.readValue(jsonResponse, Api2PdfResponse.class);
8382
}
8483

8584
public Api2PdfResponse libreofficeAnyToPdf(String url, boolean inline, String fileName)
8685
throws IOException {
8786
HttpURLConnection con = getConnection(this._baseUrl + "/libreoffice/any-to-pdf");
87+
return getApi2PdfResponse(url, inline, fileName, con);
88+
}
89+
90+
private Api2PdfResponse getApi2PdfResponse(String url, boolean inline, String fileName, HttpURLConnection con) throws IOException {
8891
Api2PdfFromUrlRequestModel model = new Api2PdfFromUrlRequestModel();
8992
model.setUrl(url);
9093
model.setInline(inline);
@@ -97,49 +100,25 @@ public Api2PdfResponse libreofficeAnyToPdf(String url, boolean inline, String fi
97100
public Api2PdfResponse libreofficeHtmlToDocx(String url, boolean inline, String fileName)
98101
throws IOException {
99102
HttpURLConnection con = getConnection(this._baseUrl + "/libreoffice/html-to-docx");
100-
Api2PdfFromUrlRequestModel model = new Api2PdfFromUrlRequestModel();
101-
model.setUrl(url);
102-
model.setInline(inline);
103-
model.setFileName(fileName);
104-
ObjectMapper objectMapper = new ObjectMapper();
105-
String payload = objectMapper.writeValueAsString(model);
106-
return makeRequest(payload, con);
103+
return getApi2PdfResponse(url, inline, fileName, con);
107104
}
108105

109106
public Api2PdfResponse libreofficeHtmlToXlsx(String url, boolean inline, String fileName)
110107
throws IOException {
111108
HttpURLConnection con = getConnection(this._baseUrl + "/libreoffice/html-to-xlsx");
112-
Api2PdfFromUrlRequestModel model = new Api2PdfFromUrlRequestModel();
113-
model.setUrl(url);
114-
model.setInline(inline);
115-
model.setFileName(fileName);
116-
ObjectMapper objectMapper = new ObjectMapper();
117-
String payload = objectMapper.writeValueAsString(model);
118-
return makeRequest(payload, con);
109+
return getApi2PdfResponse(url, inline, fileName, con);
119110
}
120111

121112
public Api2PdfResponse libreofficeThumbnail(String url, boolean inline, String fileName)
122113
throws IOException {
123114
HttpURLConnection con = getConnection(this._baseUrl + "/libreoffice/thumbnail");
124-
Api2PdfFromUrlRequestModel model = new Api2PdfFromUrlRequestModel();
125-
model.setUrl(url);
126-
model.setInline(inline);
127-
model.setFileName(fileName);
128-
ObjectMapper objectMapper = new ObjectMapper();
129-
String payload = objectMapper.writeValueAsString(model);
130-
return makeRequest(payload, con);
115+
return getApi2PdfResponse(url, inline, fileName, con);
131116
}
132117

133118
public Api2PdfResponse libreofficePdfToHtml(String url, boolean inline, String fileName)
134119
throws IOException {
135120
HttpURLConnection con = getConnection(this._baseUrl + "/libreoffice/pdf-to-html");
136-
Api2PdfFromUrlRequestModel model = new Api2PdfFromUrlRequestModel();
137-
model.setUrl(url);
138-
model.setInline(inline);
139-
model.setFileName(fileName);
140-
ObjectMapper objectMapper = new ObjectMapper();
141-
String payload = objectMapper.writeValueAsString(model);
142-
return makeRequest(payload, con);
121+
return getApi2PdfResponse(url, inline, fileName, con);
143122
}
144123

145124
public Api2PdfResponse pdfsharpMerge(String[] pdfUrls, boolean inline, String fileName) throws IOException {

api2pdf/src/test/java/api2pdf/Api2PdfClientTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ public void testLibreofficeAnyToPdf() throws IOException {
2929

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

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

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

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

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

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

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

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

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

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

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

171171
@Test
172172
public void testChromeUrlToImageWithOptions() throws IOException {
173-
HashMap<String, String> options = new HashMap<String, String>();
173+
HashMap<String, String> options = new HashMap<>();
174174
options.put("fullPage", "false");
175175
Api2PdfResponse response = a2pClient.chromeUrlToImage("https://www.api2pdf.com",
176176
true, "test.png", options);

0 commit comments

Comments
 (0)