Skip to content
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

Support PDF document download #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Trulioo SDK for Java Changelog

## Version 1.0.4

Support application/pdf in documentDownload

## Version 1.0.3

Changed type of Model/AppendedField's Data from string to Object in order to allow WatchListDetails, returned as Map, parsable.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Trulioo SDK for Java #

## Version 1.0.3
## Version 1.0.4

### Introduction

Expand Down Expand Up @@ -51,7 +51,7 @@ Add this dependency to your project's POM:
<dependency>
<groupId>com.trulioo</groupId>
<artifactId>normalizedapi</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
<scope>compile</scope>
</dependency>
```
Expand All @@ -61,7 +61,7 @@ Add this dependency to your project's POM:
Add this dependency to your project's build file:

```groovy
compile "com.trulioo:normalizedapi:1.0.3"
compile "com.trulioo:normalizedapi:1.0.4"
```

### Others
Expand All @@ -74,7 +74,7 @@ mvn clean package

Then manually install the following JARs:

* `target/normalizedapi-1.0.3.jar`
* `target/normalizedapi-1.0.4.jar`
* `target/lib/*.jar`

## Getting Started
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'eclipse'
apply plugin: 'java'

group = 'com.trulioo'
version = 'v1.0.3.0'
version = 'v1.0.4.0'

buildscript {
repositories {
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ lazy val root = (project in file(".")).
settings(
organization := "com.trulioo",
name := "normalizedapi",
version := "1.0.3",
version := "1.0.4",
scalaVersion := "2.11.4",
scalacOptions ++= Seq("-feature"),
javacOptions in compile ++= Seq("-Xlint:deprecation"),
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<artifactId>normalizedapi</artifactId>
<packaging>jar</packaging>
<name>Trulioo Normalized API</name>
<version>1.0.3</version>
<version>1.0.4</version>
<url>https://api.globaldatacompany.com/docs</url>
<description>Trulioo provides a collection of API methods to help you build business processes powered by the
GlobalGateway Normalized API.
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/com/trulioo/normalizedapi/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,15 @@ public boolean isJsonMime(String mime) {
String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$";
return mime != null && (mime.matches(jsonMime) || mime.equalsIgnoreCase("application/json-patch+json"));
}

/**
* Check if the given MIME is application/pdf
* @param mime MIME (Multipurpose Internet Mail Extensions)
* @return True if the given MIME is application/pdf
*/
public boolean isPDF(String mime) {
return mime != null && (mime.matches("(?i)(^)application\\/pdf($)"));
}

/**
* Select the Accept header's value from the given accepts array:
Expand Down Expand Up @@ -822,6 +831,12 @@ public <T> T deserialize(Response response, Type returnType) throws ApiException
if (response == null || returnType == null) {
return null;
}

String contentType = response.headers().get("Content-Type");
if (contentType == null) {
// ensuring a default content type
contentType = "application/json";
}

if ("byte[]".equals(returnType.toString())) {
// Handle binary response (byte array).
Expand All @@ -830,7 +845,7 @@ public <T> T deserialize(Response response, Type returnType) throws ApiException
} catch (IOException e) {
throw new ApiException(e);
}
} else if (returnType.equals(File.class)) {
} else if (returnType.equals(File.class) || isPDF(contentType)) {
// Handle file downloading.
return (T) downloadFileFromResponse(response);
}
Expand All @@ -849,11 +864,6 @@ public <T> T deserialize(Response response, Type returnType) throws ApiException
return null;
}

String contentType = response.headers().get("Content-Type");
if (contentType == null) {
// ensuring a default content type
contentType = "application/json";
}
if (isJsonMime(contentType)) {
return json.deserialize(respBody, returnType);
} else if (returnType.equals(String.class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public okhttp3.Call documentDownloadCall(String transactionRecordId, String fiel
localVarHeaderParams.put("Content-Type", localVarContentType);

if(progressListener != null) {
apiClient.getHttpClient().networkInterceptors().add(new okhttp3.Interceptor() {
apiClient.getHttpClient().newBuilder().addNetworkInterceptor(new okhttp3.Interceptor() {
@Override
public okhttp3.Response intercept(okhttp3.Interceptor.Chain chain) throws IOException {
okhttp3.Response originalResponse = chain.proceed(chain.request());
Expand Down