commit 855350fdc3ee3156a1110182fb004c63657ef1c1
parent e2ee4a14ba2fb136cc0c9533efa6b39e304ca1cb
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Tue, 17 Mar 2020 18:31:14 +0100
Nexus: unzip the C52 response.
Diffstat:
2 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
@@ -1,6 +1,8 @@
package tech.libeufin.nexus
import io.ktor.http.HttpStatusCode
+import org.apache.commons.compress.archivers.zip.ZipFile
+import org.apache.commons.compress.utils.SeekableInMemoryByteChannel
/**
* Inserts spaces every 2 characters, and a newline after 8 pairs.
@@ -27,3 +29,15 @@ fun chunkString(input: String): String {
fun expectId(param: String?): String {
return param ?: throw NexusError(HttpStatusCode.BadRequest, "Bad ID given")
}
+
+fun unzipOrderData(od: ByteArray): String {
+ val mem = SeekableInMemoryByteChannel(od)
+ val zipFile = ZipFile(mem)
+ val s = java.lang.StringBuilder()
+ zipFile.getEntriesInPhysicalOrder().iterator().forEach { entry ->
+ s.append("<=== File ${entry.name} ===>\n")
+ s.append(zipFile.getInputStream(entry).readAllBytes().toString(Charsets.UTF_8))
+ s.append("\n")
+ }
+ return s.toString()
+}
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -604,7 +604,7 @@ fun main() {
when (response) {
is EbicsDownloadSuccessResult -> {
call.respondText(
- response.orderData.toString(Charsets.UTF_8),
+ unzipOrderData(response.orderData),
ContentType.Text.Plain,
HttpStatusCode.OK
)
@@ -626,18 +626,8 @@ fun main() {
val response = doEbicsDownloadTransaction(client, subscriberData, "C53", orderParams)
when (response) {
is EbicsDownloadSuccessResult -> {
- val mem = SeekableInMemoryByteChannel(response.orderData)
- val zipFile = ZipFile(mem)
-
- val s = StringBuilder()
-
- zipFile.getEntriesInPhysicalOrder().iterator().forEach { entry ->
- s.append("<=== File ${entry.name} ===>\n")
- s.append(zipFile.getInputStream(entry).readAllBytes().toString(Charsets.UTF_8))
- s.append("\n")
- }
call.respondText(
- s.toString(),
+ unzipOrderData(response.orderData),
ContentType.Text.Plain,
HttpStatusCode.OK
)