Skip to content

Commit 774e06a

Browse files
authored
Merge pull request #98 from CyberSource/reporting-fix
Fix for closed I/O stream
2 parents 27de7df + 86400fe commit 774e06a

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
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: 7 additions & 0 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>

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)