gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated (d1e60b1 -> 3c85267)


From: gnunet
Subject: [libeufin] branch master updated (d1e60b1 -> 3c85267)
Date: Thu, 07 Nov 2019 16:51:49 +0100

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

marcello pushed a change to branch master
in repository libeufin.

    from d1e60b1  ebics transactions WIP
     new 845dae8  move HTTP client work to helper function (nexus)
     new 3c85267  Throwing exception on EBICS-specific error as well.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 nexus/src/main/kotlin/Main.kt | 75 ++++++++++++++++++++++++++-----------------
 1 file changed, 45 insertions(+), 30 deletions(-)

diff --git a/nexus/src/main/kotlin/Main.kt b/nexus/src/main/kotlin/Main.kt
index 1a4c076..c4cfba4 100644
--- a/nexus/src/main/kotlin/Main.kt
+++ b/nexus/src/main/kotlin/Main.kt
@@ -83,8 +83,33 @@ fun expectId(param: String?) : Int {
     }
 }
 
+/**
+ * @return null when the bank could not be reached, otherwise returns the
+ * response already converted in JAXB.
+ */
+suspend inline fun <reified S, reified T>HttpClient.postToBank(url: String, 
body: T) : JAXBElement<S>? {
+
+    val response = try {
+        this.post<String>(
+            urlString = url,
+            block = {
+                this.body = XMLUtil.convertJaxbToString(body)
+            }
+        )
+    } catch (e: Exception) {
+        e.printStackTrace()
+        return null
+    }
+
+    // note: not checking status code, as EBICS mandates to return "200 OK" 
for ANY outcome.
+    return XMLUtil.convertStringToJaxb(response)
+}
+
 data class NotAnIdError(val statusCode: HttpStatusCode) : Exception("String ID 
not convertible in number")
 data class SubscriberNotFoundError(val statusCode: HttpStatusCode) : 
Exception("Subscriber not found in database")
+data class UnreachableBankError(val statusCode: HttpStatusCode) : 
Exception("Could not reach the bank")
+data class EbicsError(val codeError: String) : Exception("Bank did not 
accepted EBICS request, error is: " +
+        "${codeError}")
 
 
 fun main() {
@@ -114,11 +139,21 @@ fun main() {
                 call.respondText("Bad request\n", ContentType.Text.Plain, 
HttpStatusCode.BadRequest)
             }
 
+            exception<UnreachableBankError> { cause ->
+                logger.error("Exception while handling '${call.request.uri}'", 
cause)
+                call.respondText("Could not reach the bank\n", 
ContentType.Text.Plain, HttpStatusCode.InternalServerError)
+            }
+
             exception<SubscriberNotFoundError> { cause ->
                 logger.error("Exception while handling '${call.request.uri}'", 
cause)
                 call.respondText("Subscriber not found\n", 
ContentType.Text.Plain, HttpStatusCode.NotFound)
             }
 
+            exception<EbicsError> { cause ->
+                logger.error("Exception while handling '${call.request.uri}'", 
cause)
+                call.respondText("Bank gave EBICS-error response\n", 
ContentType.Text.Plain, HttpStatusCode.NotAcceptable)
+            }
+
             exception<javax.xml.bind.UnmarshalException> { cause ->
                 logger.error("Exception while handling '${call.request.uri}'", 
cause)
                 call.respondText(
@@ -234,39 +269,19 @@ fun main() {
                     subscriber.ebicsURL
                 }
 
-                val response = try {
-                    client.post<String>(
-                        urlString = url,
-                        block = {
-                            body = XMLUtil.convertJaxbToString(iniRequest)
-                        }
-                    )
-                } catch (e: Exception) {
-                    e.printStackTrace()
-
-                    call.respond(
-                        HttpStatusCode.OK,
-                        NexusError("Could not reach the bank.\n")
-                    )
-                    return@post
-                }
+                val responseJaxb = 
client.postToBank<EbicsKeyManagementResponse, EbicsUnsecuredRequest>(
+                    url,
+                    iniRequest
+                ) ?: throw 
UnreachableBankError(HttpStatusCode.InternalServerError)
 
-                val responseJaxb = 
XMLUtil.convertStringToJaxb<EbicsKeyManagementResponse>(response)  // caught 
above
                 val returnCode = responseJaxb.value.body.returnCode.value
-                if (returnCode == "000000") {
-                    call.respond(
-                        HttpStatusCode.OK,
-                        NexusError("Sandbox accepted the key.")
-                    )
-                    return@post
-                } else {
+                if (returnCode != "000000") throw EbicsError(returnCode)
 
-                    call.respond(
-                        HttpStatusCode.OK,
-                        NexusError("Sandbox did not accept the key.  Error 
code: ${returnCode}")
-                    )
-                    return@post
-                }
+                call.respond(
+                    HttpStatusCode.OK,
+                    NexusError("Sandbox accepted the key!")
+                )
+                return@post
             }
         }
     }

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



reply via email to

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