Skip to content

Commit e87932d

Browse files
authored
Merge pull request #97 from CyberSource/log4j-fix
Upgrade to log4j2 v2.17.1 and fix for issue with downloads
2 parents 4a86d78 + 774e06a commit e87932d

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

generator/cybersource-java-template/libraries/okhttp-gson/ApiClient.mustache

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,9 +1206,12 @@ public class ApiClient {
12061206
if(returnType == new TypeToken< Model.AccessTokenResponse >(){}.getType()) {
12071207
logger.debug("Response :\n" + response.peekBody(Long.MAX_VALUE).string());
12081208
}
1209+
12091210
T data = handleResponse(response, returnType);
12101211

1211-
response.body().close();
1212+
if (returnType != null || call.request().method().equalsIgnoreCase("DELETE") || responseCode.equalsIgnoreCase("202")) {
1213+
response.body().close();
1214+
}
12121215

12131216
logger.info("HTTP Response Body :\n{}", data);
12141217

pom.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,13 @@
252252
<artifactId>log4j-1.2-api</artifactId>
253253
<version>${log4j.version}</version>
254254
</dependency>
255+
256+
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
257+
<dependency>
258+
<groupId>commons-io</groupId>
259+
<artifactId>commons-io</artifactId>
260+
<version>2.7</version>
261+
</dependency>
255262

256263
<!-- test dependencies -->
257264
<dependency>
@@ -265,7 +272,7 @@
265272
<dependency>
266273
<groupId>com.cybersource</groupId>
267274
<artifactId>AuthenticationSdk</artifactId>
268-
<version>0.0.20</version>
275+
<version>0.0.21</version>
269276
</dependency>
270277
</dependencies>
271278

@@ -281,6 +288,6 @@
281288
<maven-plugin-version>1.0.0</maven-plugin-version>
282289
<junit-version>4.13.2</junit-version>
283290
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
284-
<log4j.version>2.16.0</log4j.version>
291+
<log4j.version>2.17.1</log4j.version>
285292
</properties>
286293
</project>

src/main/java/Invokers/ApiClient.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,9 +1206,12 @@ public <T> ApiResponse<T> execute(Call call, Type returnType) throws ApiExceptio
12061206
if(returnType == new TypeToken< Model.AccessTokenResponse >(){}.getType()) {
12071207
logger.debug("Response :\n" + response.peekBody(Long.MAX_VALUE).string());
12081208
}
1209+
12091210
T data = handleResponse(response, returnType);
12101211

1211-
response.body().close();
1212+
if (returnType != null || call.request().method().equalsIgnoreCase("DELETE") || responseCode.equalsIgnoreCase("202")) {
1213+
response.body().close();
1214+
}
12121215

12131216
logger.info("HTTP Response Body :\n{}", data);
12141217

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package utilities.filehandling;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.io.InputStream;
6+
import org.apache.commons.io.FileUtils;
7+
8+
public class FileUtilities {
9+
public static void downloadFileFromInputStream(InputStream inputStream, File outputFile) throws IOException {
10+
if (inputStream == null) {
11+
throw new IllegalArgumentException("Input Stream is null or unavailable.");
12+
}
13+
14+
FileUtils.copyInputStreamToFile(inputStream, outputFile);
15+
16+
inputStream.close();
17+
}
18+
}

0 commit comments

Comments
 (0)