[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: Use 'moshi' to enforce JSON fields.
From: |
gnunet |
Subject: |
[libeufin] branch master updated: Use 'moshi' to enforce JSON fields. |
Date: |
Fri, 08 Nov 2019 16:50:53 +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 0e157a5 Use 'moshi' to enforce JSON fields.
0e157a5 is described below
commit 0e157a5c06d5080c7b7b527f76483cbb784cd77d
Author: Marcello Stanisci <address@hidden>
AuthorDate: Fri Nov 8 16:50:30 2019 +0100
Use 'moshi' to enforce JSON fields.
---
nexus/build.gradle | 4 ++++
nexus/src/main/kotlin/JSON.kt | 4 ++++
nexus/src/main/kotlin/Main.kt | 24 ++++++++++++------------
3 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/nexus/build.gradle b/nexus/build.gradle
index 04c7f1c..df5e941 100644
--- a/nexus/build.gradle
+++ b/nexus/build.gradle
@@ -4,6 +4,8 @@ plugins {
id 'application'
}
+apply plugin: 'kotlin-kapt'
+
sourceCompatibility = '11'
targetCompatibility = '11'
version = '0.0.1'
@@ -33,6 +35,8 @@ dependencies {
implementation "javax.activation:activation:1.1"
implementation "org.glassfish.jaxb:jaxb-runtime:2.3.1"
implementation 'org.apache.santuario:xmlsec:2.1.4'
+ kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.8.0'
+ compile 'com.ryanharter.ktor:ktor-moshi:1.0.1'
testImplementation group: 'junit', name: 'junit', version: '4.12'
}
diff --git a/nexus/src/main/kotlin/JSON.kt b/nexus/src/main/kotlin/JSON.kt
index 090838e..8a571fc 100644
--- a/nexus/src/main/kotlin/JSON.kt
+++ b/nexus/src/main/kotlin/JSON.kt
@@ -1,9 +1,13 @@
package tech.libeufin.nexus
+import com.google.gson.annotations.JsonAdapter
+import com.squareup.moshi.JsonClass
+
/**
* This object is POSTed by clients _after_ having created
* a EBICS subscriber at the sandbox.
*/
+@JsonClass(generateAdapter = true)
data class EbicsSubscriberInfoRequest(
val ebicsURL: String,
val hostID: String,
diff --git a/nexus/src/main/kotlin/Main.kt b/nexus/src/main/kotlin/Main.kt
index 6683112..3f1d9e7 100644
--- a/nexus/src/main/kotlin/Main.kt
+++ b/nexus/src/main/kotlin/Main.kt
@@ -19,6 +19,8 @@
package tech.libeufin.nexus
+import com.ryanharter.ktor.moshi.moshi
+import com.squareup.moshi.JsonDataException
import io.ktor.application.ApplicationCallPipeline
import io.ktor.application.call
import io.ktor.application.install
@@ -38,7 +40,6 @@ import io.ktor.routing.post
import io.ktor.routing.routing
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
-import org.apache.commons.codec.digest.Crypt
import org.apache.xml.security.binding.xmldsig.RSAKeyValueType
import org.apache.xml.security.binding.xmldsig.SignatureType
import org.jetbrains.exposed.sql.transactions.transaction
@@ -156,6 +157,10 @@ fun main() {
val server = embeddedServer(Netty, port = 5001) {
install(ContentNegotiation) {
+
+ moshi {
+ }
+
gson {
setDateFormat(DateFormat.LONG)
setPrettyPrinting()
@@ -168,6 +173,11 @@ fun main() {
call.respondText("Internal server error.\n",
ContentType.Text.Plain, HttpStatusCode.InternalServerError)
}
+ exception<JsonDataException> { cause ->
+ logger.error("Exception while handling '${call.request.uri}'",
cause)
+ call.respondText("Bad request\n", ContentType.Text.Plain,
HttpStatusCode.BadRequest)
+ }
+
exception<NotAnIdError> { cause ->
logger.error("Exception while handling '${call.request.uri}'",
cause)
call.respondText("Bad request\n", ContentType.Text.Plain,
HttpStatusCode.BadRequest)
@@ -253,17 +263,7 @@ fun main() {
post("/ebics/subscribers") {
- // FIXME: parsed object is not enforced!
- val body = try {
- call.receive<EbicsSubscriberInfoRequest>()
- } catch (e: Exception) {
- e.printStackTrace()
- call.respond(
- HttpStatusCode.BadRequest,
- NexusError(e.message.toString())
- )
- return@post
- }
+ val body = call.receive<EbicsSubscriberInfoRequest>()
val pairA = CryptoUtil.generateRsaKeyPair(2048)
val pairB = CryptoUtil.generateRsaKeyPair(2048)
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libeufin] branch master updated: Use 'moshi' to enforce JSON fields.,
gnunet <=