commit da30321ef33d65af3d7d3b3a6f875c4268a64bc0
parent 47275b97d04bd37050b68a032e9b5a926310fec6
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Thu, 7 Nov 2019 12:27:19 +0100
intercepting unmarshal-type exceptions
Diffstat:
2 files changed, 35 insertions(+), 3 deletions(-)
diff --git 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
@@ -2,6 +2,10 @@ 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
@@ -9,6 +13,19 @@ 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()
val hev = classLoader.getResourceAsStream("ebics_hev.xml")