gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] 01/02: Setting JSON request parser as the default.


From: gnunet
Subject: [libeufin] 01/02: Setting JSON request parser as the default.
Date: Mon, 14 Feb 2022 10:16:07 +0100

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository libeufin.

commit 3e204b0b4d7d3aa54ecfd6f796ddda456f4a0d4f
Author: ms <ms@taler.net>
AuthorDate: Sat Feb 12 10:24:54 2022 +0100

    Setting JSON request parser as the default.
---
 .../tech/libeufin/sandbox/XMLEbicsConverter.kt     | 40 ++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/XMLEbicsConverter.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/XMLEbicsConverter.kt
new file mode 100644
index 00000000..5dc23af6
--- /dev/null
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/XMLEbicsConverter.kt
@@ -0,0 +1,40 @@
+package tech.libeufin.sandbox
+
+import io.ktor.application.*
+import io.ktor.features.*
+import io.ktor.http.*
+import io.ktor.http.content.*
+import io.ktor.request.*
+import io.ktor.response.*
+import io.ktor.util.pipeline.*
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.withContext
+import tech.libeufin.util.XMLUtil
+import java.io.OutputStream
+
+public class EbicsConverter : ContentConverter {
+    override suspend fun convertForReceive(context: 
PipelineContext<ApplicationReceiveRequest, ApplicationCall>): Any {
+        return context.context.receiveEbicsXml()
+    }
+
+    override suspend fun convertForSend(
+        context: PipelineContext<Any, ApplicationCall>,
+        contentType: ContentType,
+        value: Any
+    ): Any? {
+        val conv = try {
+            XMLUtil.convertJaxbToString(value)
+        } catch (e: Exception) {
+            logger.warn("Could not convert XML to string with custom 
converter.")
+            return null
+        }
+        return OutputStreamContent({
+            suspend fun writeAsync(out: OutputStream) {
+                withContext(Dispatchers.IO) {
+                    out.write(conv.toByteArray())
+                }
+            }
+            writeAsync(this)
+        })
+    }
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]