[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-libeufin] 15/25: Abstracting string conversion to "s
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-libeufin] 15/25: Abstracting string conversion to "stream". |
Date: |
Fri, 20 Sep 2019 19:32:53 +0200 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a commit to branch master
in repository libeufin.
commit 1c021799a1c1803fc17bbcc2d247099b0a7dae5b
Author: Marcello Stanisci <address@hidden>
AuthorDate: Mon Sep 16 01:05:38 2019 +0200
Abstracting string conversion to "stream".
---
src/main/java/tech/libeufin/XMLManagement.java | 14 ++++++++++++++
src/main/kotlin/Main.kt | 15 ++++++++++++---
src/test/java/XMLManagementTest.java | 2 ++
3 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/src/main/java/tech/libeufin/XMLManagement.java
b/src/main/java/tech/libeufin/XMLManagement.java
index 7e1bed9..3d9e389 100644
--- a/src/main/java/tech/libeufin/XMLManagement.java
+++ b/src/main/java/tech/libeufin/XMLManagement.java
@@ -7,6 +7,8 @@ import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.Source;
import javax.xml.validation.*; // has SchemaFactory
import java.io.File;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
/**
* This class takes care of importing XSDs and validate
@@ -58,4 +60,16 @@ public class XMLManagement {
}
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.
+ */
+ public boolean validate(String xmlString){
+ InputStream xmlInputStream = new
ByteArrayInputStream(xmlString.getBytes());
+ Source xmlSource = new StreamSource(xmlInputStream);
+ return this.validate(xmlSource);
+ }
+
};
\ No newline at end of file
diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt
index ad37c0d..ee6a700 100644
--- a/src/main/kotlin/Main.kt
+++ b/src/main/kotlin/Main.kt
@@ -27,10 +27,12 @@ import io.ktor.routing.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import tech.libeufin.XMLManagement;
+import java.io.ByteArrayInputStream
+import java.io.InputStream
-fun main(args: Array<String>) {
- var xmlprocess = XMLManagement();
+fun main(args: Array<String>) {
+ var xmlProcess = XMLManagement();
val server = embeddedServer(Netty, port = 5000) {
routing {
get("/") {
@@ -39,7 +41,14 @@ fun main(args: Array<String>) {
post("/") {
val body: String = call.receiveText()
println("Body: $body")
- call.respondText("Your request has been logged.",
ContentType.Text.Plain)
+ val isValid = xmlProcess.validate(body)
+ call.response.header("Content-Type", "application/xml")
+ if (isValid){
+ call.respond(HttpStatusCode.OK, xmlResponseObject)
+ }
+ else {
+ call.respond(HttpStatusCode.BadRequest, xmlResponseObject)
+ }
}
}
}
diff --git a/src/test/java/XMLManagementTest.java
b/src/test/java/XMLManagementTest.java
index 3e37c71..0837ca1 100644
--- a/src/test/java/XMLManagementTest.java
+++ b/src/test/java/XMLManagementTest.java
@@ -23,5 +23,7 @@ public class XMLManagementTest {
InputStream is = new ByteArrayInputStream("<InvalidXML>".getBytes());
Source ebics_from_string = new StreamSource(is);
assertFalse(xm.validate(ebics_from_string));
+
+ assertFalse(xm.validate("<moreInvalidXML>"));
}
}
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [GNUnet-SVN] [taler-libeufin] 07/25: Test stub., (continued)
- [GNUnet-SVN] [taler-libeufin] 07/25: Test stub., gnunet, 2019/09/20
- [GNUnet-SVN] [taler-libeufin] 06/25: readme, gnunet, 2019/09/20
- [GNUnet-SVN] [taler-libeufin] 05/25: Copyright header., gnunet, 2019/09/20
- [GNUnet-SVN] [taler-libeufin] 01/25: Import initial project structure., gnunet, 2019/09/20
- [GNUnet-SVN] [taler-libeufin] 10/25: fix resource loading, gnunet, 2019/09/20
- [GNUnet-SVN] [taler-libeufin] 03/25: AGPL license, gnunet, 2019/09/20
- [GNUnet-SVN] [taler-libeufin] 12/25: Local test of XML validation., gnunet, 2019/09/20
- [GNUnet-SVN] [taler-libeufin] 11/25: import sample hev, gnunet, 2019/09/20
- [GNUnet-SVN] [taler-libeufin] 14/25: Test with XML imported from string., gnunet, 2019/09/20
- [GNUnet-SVN] [taler-libeufin] 13/25: fix test, gnunet, 2019/09/20
- [GNUnet-SVN] [taler-libeufin] 15/25: Abstracting string conversion to "stream".,
gnunet <=
- [GNUnet-SVN] [taler-libeufin] 16/25: Introducing the converters:, gnunet, 2019/09/20
- [GNUnet-SVN] [taler-libeufin] 20/25: Server responds with ebicsHEVResponse., gnunet, 2019/09/20
- [GNUnet-SVN] [taler-libeufin] 18/25: method to get (XML) strings from JAXB objects., gnunet, 2019/09/20
- [GNUnet-SVN] [taler-libeufin] 23/25: Translating getLogger() into Kotlin., gnunet, 2019/09/20
- [GNUnet-SVN] [taler-libeufin] 19/25: Importing JAXB scaffolding to reflect ebics "hev" types., gnunet, 2019/09/20
- [GNUnet-SVN] [taler-libeufin] 21/25: Fix resource loading from JAR., gnunet, 2019/09/20
- [GNUnet-SVN] [taler-libeufin] 25/25: Finish translating Java into Kotlin., gnunet, 2019/09/20
- [GNUnet-SVN] [taler-libeufin] 17/25: Check if the message can be handled by the server., gnunet, 2019/09/20
- [GNUnet-SVN] [taler-libeufin] 24/25: Move XMLManagement.java to Kotlin., gnunet, 2019/09/20
- [GNUnet-SVN] [taler-libeufin] 22/25: Complete initial setup (#5888)., gnunet, 2019/09/20