Skip to content

Commit

Permalink
Run mvn spotless:apply on RequestStatus.java
Browse files Browse the repository at this point in the history
  • Loading branch information
datalogics-cgreen committed Jun 6, 2024
1 parent 6804bb7 commit 99571b4
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions Java/Endpoint Examples/Multipart Payload/RequestStatus.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import io.github.cdimascio.dotenv.Dotenv;

import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import okhttp3.*;
import org.json.JSONObject;

Expand Down Expand Up @@ -57,24 +55,24 @@ public static void main(String[] args) {
private static String getPdfaResponse(File inputFile, String apiKey) {

final RequestBody inputFileRequestBody =
RequestBody.create(inputFile, MediaType.parse("application/pdf"));
RequestBody.create(inputFile, MediaType.parse("application/pdf"));
RequestBody requestBody =
new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", inputFile.getName(), inputFileRequestBody)
.addFormDataPart("output_type", "PDF/A-2u")
.addFormDataPart("output", "pdfrest_pdfa")
.build();
new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", inputFile.getName(), inputFileRequestBody)
.addFormDataPart("output_type", "PDF/A-2u")
.addFormDataPart("output", "pdfrest_pdfa")
.build();
Request request =
new Request.Builder()
.header("Api-Key", apiKey)
.header("response-type", "requestId")
.url("https://api.pdfrest.com/pdfa")
.post(requestBody)
.build();
new Request.Builder()
.header("Api-Key", apiKey)
.header("response-type", "requestId")
.url("https://api.pdfrest.com/pdfa")
.post(requestBody)
.build();
try {
OkHttpClient client =
new OkHttpClient().newBuilder().readTimeout(60, TimeUnit.SECONDS).build();
new OkHttpClient().newBuilder().readTimeout(60, TimeUnit.SECONDS).build();

Response response = client.newCall(request).execute();
System.out.println("Result code " + response.code());
Expand All @@ -88,15 +86,10 @@ private static String getPdfaResponse(File inputFile, String apiKey) {

private static String getRequestStatusResponse(String requestId, String apiKey) {
String urlString = String.format("https://api.pdfrest.com/request-status/%s", requestId);
Request request =
new Request.Builder()
.header("Api-Key", apiKey)
.url(urlString)
.get()
.build();
Request request = new Request.Builder().header("Api-Key", apiKey).url(urlString).get().build();
try {
OkHttpClient client =
new OkHttpClient().newBuilder().readTimeout(60, TimeUnit.SECONDS).build();
new OkHttpClient().newBuilder().readTimeout(60, TimeUnit.SECONDS).build();
Response response = client.newCall(request).execute();
System.out.println("Result code " + response.code());
String responseBody = response.body().string();
Expand All @@ -107,7 +100,6 @@ private static String getRequestStatusResponse(String requestId, String apiKey)
}
}


private static String prettyJson(String json) {
// https://stackoverflow.com/a/9583835/11996393
return new JSONObject(json).toString(4);
Expand Down

0 comments on commit 99571b4

Please sign in to comment.