Overhaul of the Bank of Corda demo to fix two problems it had:

1. The runRPCCashIssue and runWebCashIssue gradle tasks didn't work because they were using the wrong ports
2. Notary lookup was failing because the lookup name didn't include the correct CN for the notary name (this slipped through when reverting the network parameters)

The ports change occurred in #1922 which was attempting the fix the runIssuer gradle task. This is actually a misleading and redundant task as all it does is start up the nodes, which is what the documented deployNodes already does. The ports runIssuer allocated to the nodes were different to the ones specified in deployNodes.

To make sure we have integration tests which closely match deployNodes, the BoC demo has been updated to make use of CordformDefinition. This keeps the node definitions in one place, removing the need to have disparate files in sync. runIssuer has been removed.
This commit is contained in:
Shams Asari
2017-11-23 22:27:24 +00:00
parent b45d9e957b
commit 5c53a91785
33 changed files with 395 additions and 363 deletions

View File

@ -6,6 +6,7 @@ import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody
import org.slf4j.LoggerFactory
import java.io.IOException
import java.net.URL
import java.util.concurrent.TimeUnit
@ -14,11 +15,13 @@ import java.util.concurrent.TimeUnit
*/
object HttpUtils {
private val logger = LoggerFactory.getLogger(javaClass)
private val client by lazy {
OkHttpClient.Builder()
.connectTimeout(5, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS).build()
}
val defaultMapper: ObjectMapper by lazy {
net.corda.client.jackson.JacksonSupport.createNonRpcMapper()
}
@ -28,9 +31,9 @@ object HttpUtils {
return makeRequest(Request.Builder().url(url).header("Content-Type", "application/json").put(body).build())
}
fun postJson(url: URL, data: String): Boolean {
fun postJson(url: URL, data: String) {
val body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), data)
return makeRequest(Request.Builder().url(url).header("Content-Type", "application/json").post(body).build())
makeExceptionalRequest(Request.Builder().url(url).header("Content-Type", "application/json").post(body).build())
}
fun postPlain(url: URL, data: String): Boolean {
@ -44,6 +47,14 @@ object HttpUtils {
return mapper.readValue(parameterisedUrl, T::class.java)
}
// TODO Move everything to use this instead of makeRequest
private fun makeExceptionalRequest(request: Request) {
val response = client.newCall(request).execute()
if (!response.isSuccessful) {
throw IOException("${request.method()} to ${request.url()} returned a ${response.code()}: ${response.body().string()}")
}
}
private fun makeRequest(request: Request): Boolean {
val response = client.newCall(request).execute()