[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [libeufin] branch master updated: avoid double parsing
From: |
gnunet |
Subject: |
[GNUnet-SVN] [libeufin] branch master updated: avoid double parsing |
Date: |
Mon, 30 Sep 2019 15:10:38 +0200 |
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 832dd59 avoid double parsing
832dd59 is described below
commit 832dd5979a83dc75a272efbccec0af085084fa1e
Author: Marcello Stanisci <address@hidden>
AuthorDate: Mon Sep 30 15:10:21 2019 +0200
avoid double parsing
---
src/main/kotlin/tech/libeufin/Main.kt | 22 ++++++++++------------
src/main/kotlin/tech/libeufin/XMLTransform.kt | 17 ++++++++++++++++-
2 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/src/main/kotlin/tech/libeufin/Main.kt
b/src/main/kotlin/tech/libeufin/Main.kt
index db06035..71482e2 100644
--- a/src/main/kotlin/tech/libeufin/Main.kt
+++ b/src/main/kotlin/tech/libeufin/Main.kt
@@ -141,28 +141,26 @@ fun main() {
post("/ebicsweb") {
val body: String = call.receiveText()
logger.debug("Body: $body")
+ val bodyDocument: Document? =
xmlProcess.parseStringIntoDom(body)
- val isValid = xmlProcess.validateFromString(body)
-
- if (!isValid) {
- logger.error("Invalid request received")
+ if (bodyDocument == null) {
call.respondText(
contentType = ContentType.Application.Xml,
status = HttpStatusCode.BadRequest
- ) { "Bad request" }
+ ) { "Bad request / Could not parse the body" }
return@post
+
}
- val bodyDocument: Document? =
xmlProcess.parseStringIntoDom(body)
- if (null == bodyDocument) {
- /* Should never happen. */
- logger.error("A valid document failed to parse into DOM!")
+ if (!xmlProcess.validateFromDom(bodyDocument)) {
+ logger.error("Invalid request received")
call.respondText(
contentType = ContentType.Application.Xml,
- status = HttpStatusCode.InternalServerError
- ) { "Internal server error" }
+ status = HttpStatusCode.BadRequest
+ ) { "Bad request / invalid document" }
return@post
}
+
logger.info(bodyDocument.documentElement.localName)
when (bodyDocument.documentElement.localName) {
@@ -178,7 +176,7 @@ fun main() {
val jaxbHEV: JAXBElement<HEVResponseDataType> =
hevResponse.makeHEVResponse()
val responseText: String? =
xmlProcess.getStringFromJaxb(jaxbHEV)
- // FIXME: check if String is actually non-NULL!
+
call.respondText(
contentType = ContentType.Application.Xml,
status = HttpStatusCode.OK
diff --git a/src/main/kotlin/tech/libeufin/XMLTransform.kt
b/src/main/kotlin/tech/libeufin/XMLTransform.kt
index ee0c43e..e64f82b 100644
--- a/src/main/kotlin/tech/libeufin/XMLTransform.kt
+++ b/src/main/kotlin/tech/libeufin/XMLTransform.kt
@@ -116,6 +116,21 @@ class XMLTransform {
}
/**
+ * Validates the DOM against the Schema(s) of this object.
+ * @param domDocument DOM to validate
+ * @return true/false if the document is valid/invalid
+ */
+ fun validateFromDom(domDocument: Document): Boolean {
+ try {
+ validator?.validate(DOMSource(domDocument))
+ } catch (e: SAXException) {
+ e.printStackTrace()
+ return false
+ }
+ return true
+ }
+
+ /**
* Craft object to be passed to the XML validator.
* @param xmlString XML body, as read from the POST body.
* @return InputStream object, as wanted by the validator.
@@ -205,7 +220,7 @@ class XMLTransform {
} catch (e: JAXBException) {
e.printStackTrace()
- return null
+ return "Bank fatal error."
}
return sw.toString()
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [libeufin] branch master updated: avoid double parsing,
gnunet <=