commit 2b0915e3b03474b4ed9315338ae8749815900207
parent a15c48d5225473caa72a11442facf896dfd6f211
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Thu, 5 Mar 2020 15:42:47 +0100
implement compressed C53 responses
Diffstat:
3 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -38,11 +38,8 @@ import io.ktor.routing.post
import io.ktor.routing.routing
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
-import javafx.util.Pair
-import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
import org.apache.commons.compress.archivers.zip.ZipFile
import org.apache.commons.compress.utils.SeekableInMemoryByteChannel
-import org.jetbrains.exposed.dao.EntityID
import org.jetbrains.exposed.exceptions.ExposedSQLException
import org.jetbrains.exposed.sql.StdOutSqlLogger
import org.jetbrains.exposed.sql.addLogger
@@ -466,7 +463,6 @@ fun main() {
}
get("/ebics/subscribers/{id}/accounts") {
- // FIXME(marcello): return bank accounts associated with the subscriber,
// this information is only avaiable *after* HTD or HKD has been called
val id = expectId(call.parameters["id"])
val ret = EbicsAccountsInfoResponse()
diff --git a/sandbox/build.gradle b/sandbox/build.gradle
@@ -40,6 +40,7 @@ dependencies {
implementation 'org.apache.santuario:xmlsec:2.1.4'
implementation group: 'org.bouncycastle', name: 'bcprov-jdk16', version: '1.45'
implementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.28.0'
+ implementation group: 'org.apache.commons', name: 'commons-compress', version: '1.20'
testImplementation group: 'junit', name: 'junit', version: '4.12'
testImplementation 'org.jetbrains.kotlin:kotlin-test-junit:1.3.50'
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -40,6 +40,7 @@ import tech.libeufin.util.EbicsOrderUtil
import tech.libeufin.util.XMLUtil
import tech.libeufin.util.*
import tech.libeufin.util.XMLUtil.Companion.signEbicsResponse
+import java.io.ByteArrayOutputStream
import java.math.BigDecimal
import java.security.interfaces.RSAPrivateCrtKey
import java.security.interfaces.RSAPublicKey
@@ -48,6 +49,11 @@ import java.util.zip.DeflaterInputStream
import java.util.zip.InflaterInputStream
import javax.sql.rowset.serial.SerialBlob
import javax.xml.datatype.DatatypeFactory
+import org.apache.commons.compress.archivers.ArchiveStreamFactory
+import org.apache.commons.compress.archivers.zip.ZipArchiveEntry
+import org.apache.commons.compress.utils.IOUtils
+import java.io.BufferedInputStream
+import java.io.ByteArrayInputStream
open class EbicsRequestError(errorText: String, errorCode: String) :
@@ -273,7 +279,7 @@ private fun constructCamtResponse(type: Int, customerId: Int, header: EbicsReque
}
}
}
- return camt
+ return camt
}
@@ -288,7 +294,20 @@ private fun handleEbicsPTK(requestContext: RequestContext): ByteArray {
private fun handleEbicsC52(requestContext: RequestContext): ByteArray {
val subscriber = requestContext.subscriber
- return constructCamtResponse(52, subscriber.bankCustomer.id.value, requestContext.requestObject.header).toByteArray()
+ val camt = constructCamtResponse(52, subscriber.bankCustomer.id.value, requestContext.requestObject.header)
+
+ val baos = ByteArrayOutputStream()
+ val asf = ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, baos)
+ val zae = ZipArchiveEntry("Singleton C53 Entry")
+ asf.putArchiveEntry(zae)
+
+ val bais = ByteArrayInputStream(camt.toByteArray())
+ IOUtils.copy(bais, asf)
+ bais.close()
+ asf.closeArchiveEntry()
+ asf.finish()
+ baos.close()
+ return baos.toByteArray()
}
private suspend fun ApplicationCall.handleEbicsHia(header: EbicsUnsecuredRequest.Header, orderData: ByteArray) {