gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated: intercepting unmarshal-type exceptions


From: gnunet
Subject: [libeufin] branch master updated: intercepting unmarshal-type exceptions
Date: Thu, 07 Nov 2019 12:27:26 +0100

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

marcello pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new da30321  intercepting unmarshal-type exceptions
da30321 is described below

commit da30321ef33d65af3d7d3b3a6f875c4268a64bc0
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Nov 7 12:27:19 2019 +0100

    intercepting unmarshal-type exceptions
---
 nexus/src/main/kotlin/Main.kt          | 21 ++++++++++++++++++---
 sandbox/src/test/kotlin/XmlUtilTest.kt | 17 +++++++++++++++++
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/nexus/src/main/kotlin/Main.kt b/nexus/src/main/kotlin/Main.kt
index 943096a..60e8c8b 100644
--- a/nexus/src/main/kotlin/Main.kt
+++ b/nexus/src/main/kotlin/Main.kt
@@ -52,6 +52,7 @@ import tech.libeufin.schema.ebics_s001.SignaturePubKeyInfoType
 import tech.libeufin.schema.ebics_s001.SignaturePubKeyOrderData
 import java.text.DateFormat
 import javax.sql.rowset.serial.SerialBlob
+import javax.xml.bind.JAXBElement
 
 fun testData() {
 
@@ -105,12 +106,26 @@ fun main() {
         install(StatusPages) {
             exception<Throwable> { cause ->
                 logger.error("Exception while handling '${call.request.uri}'", 
cause)
-                call.respondText("Internal server error.", 
ContentType.Text.Plain, HttpStatusCode.InternalServerError)
+                call.respondText("Internal server error.\n", 
ContentType.Text.Plain, HttpStatusCode.InternalServerError)
             }
 
             exception<NotAnIdError> { cause ->
                 logger.error("Exception while handling '${call.request.uri}'", 
cause)
-                call.respondText("Bad request", ContentType.Text.Plain, 
HttpStatusCode.BadRequest)
+                call.respondText("Bad request\n", ContentType.Text.Plain, 
HttpStatusCode.BadRequest)
+            }
+
+            exception<SubscriberNotFoundError> { cause ->
+                logger.error("Exception while handling '${call.request.uri}'", 
cause)
+                call.respondText("Subscriber not found\n", 
ContentType.Text.Plain, HttpStatusCode.NotFound)
+            }
+
+            exception<javax.xml.bind.UnmarshalException> { cause ->
+                logger.error("Exception while handling '${call.request.uri}'", 
cause)
+                call.respondText(
+                    "Could not convert string into JAXB (either from client or 
from bank)\n",
+                    ContentType.Text.Plain,
+                    HttpStatusCode.NotFound
+                )
             }
         }
 
@@ -231,7 +246,7 @@ fun main() {
 
                     call.respond(
                         HttpStatusCode.OK,
-                        NexusError("Did not get expected response from 
bank/sandbox")
+                        NexusError("Could not reach the bank.\n")
                     )
                     return@post
                 }
diff --git a/sandbox/src/test/kotlin/XmlUtilTest.kt 
b/sandbox/src/test/kotlin/XmlUtilTest.kt
index 37b2ab9..0bf182f 100644
--- a/sandbox/src/test/kotlin/XmlUtilTest.kt
+++ b/sandbox/src/test/kotlin/XmlUtilTest.kt
@@ -2,12 +2,29 @@ package tech.libeufin.sandbox
 
 import org.junit.Test
 import org.junit.Assert.*
+import org.junit.rules.ExpectedException
+import org.xml.sax.SAXParseException
+import tech.libeufin.schema.ebics_h004.EbicsKeyManagementResponse
+import java.rmi.UnmarshalException
 import java.security.KeyPairGenerator
 import java.util.*
 import javax.xml.transform.stream.StreamSource
 
 class XmlUtilTest {
 
+    @Test
+    fun exceptionOnConversion() {
+        try {
+            
XMLUtil.convertStringToJaxb<EbicsKeyManagementResponse>("<malformed xml>")
+        } catch (e: javax.xml.bind.UnmarshalException) {
+            // just ensuring this is the exception
+            logger.info("caught")
+            return
+        }
+
+        assertTrue(false)
+    }
+
     @Test
     fun hevValidation(){
         val classLoader = ClassLoader.getSystemClassLoader()

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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