From 782d50958dfca7729b23d49214687ee4d54753e7 Mon Sep 17 00:00:00 2001 From: Clinton Alexander Date: Mon, 6 Jun 2016 12:30:59 +0100 Subject: [PATCH] IRS demo endpoints are now parameterised for the Trade and Demo modes. Documentation fixes. --- docs/source/running-the-demos.rst | 4 ++-- src/main/kotlin/com/r3corda/demos/IRSDemo.kt | 25 +++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/docs/source/running-the-demos.rst b/docs/source/running-the-demos.rst index 19675c41d5..d54ceabc9c 100644 --- a/docs/source/running-the-demos.rst +++ b/docs/source/running-the-demos.rst @@ -58,13 +58,13 @@ Open three terminals. In the first run: **Other**:: - gradle installDist && ./build/install/r3prototyping/bin/irsdemo --role=NodeA + ./gradlew installDist && ./build/install/r3prototyping/bin/irsdemo --role=NodeA And in the second run: **Windows**:: -.\build\install\r3prototyping\bin\irsdemo.bat --role=NodeB + .\build\install\r3prototyping\bin\irsdemo.bat --role=NodeB **Other**:: diff --git a/src/main/kotlin/com/r3corda/demos/IRSDemo.kt b/src/main/kotlin/com/r3corda/demos/IRSDemo.kt index 6ad9aa8115..5d4fee14fe 100644 --- a/src/main/kotlin/com/r3corda/demos/IRSDemo.kt +++ b/src/main/kotlin/com/r3corda/demos/IRSDemo.kt @@ -19,6 +19,7 @@ import com.r3corda.demos.api.InterestRateSwapAPI import com.r3corda.demos.protocols.AutoOfferProtocol import com.r3corda.demos.protocols.ExitServerProtocol import com.r3corda.demos.protocols.UpdateBusinessDayProtocol +import com.r3corda.node.internal.AbstractNode import joptsimple.OptionParser import java.io.DataOutputStream import java.net.HttpURLConnection @@ -90,7 +91,13 @@ fun main(args: Array) { val tradeIdArgs = options.valuesOf(nonOptions) if (tradeIdArgs.size > 0) { val tradeId = tradeIdArgs[0] - if (runTrade(tradeId)) { + val host = if (options.has(networkAddressArg)) { + options.valueOf(networkAddressArg) + } else { + "http://localhost:" + Node.DEFAULT_PORT + 1 + } + + if (runTrade(tradeId, host)) { exitProcess(0) } else { exitProcess(1) @@ -103,7 +110,13 @@ fun main(args: Array) { val dateStrArgs = options.valuesOf(nonOptions) if (dateStrArgs.size > 0) { val dateStr = dateStrArgs[0] - runDateChange(dateStr) + val host = if (options.has(networkAddressArg)) { + options.valueOf(networkAddressArg) + } else { + "http://localhost:" + Node.DEFAULT_PORT + 1 + } + + runDateChange(dateStr, host) } else { println("Please provide a date") exitProcess(1) @@ -141,8 +154,8 @@ fun main(args: Array) { } } -private fun runDateChange(date: String) : Boolean{ - var url = URL("http://localhost:31338/api/irs/demodate") +private fun runDateChange(date: String, host: String) : Boolean { + val url = URL(host + "/api/irs/demodate") if(putJson(url, "\"" + date + "\"")) { println("Date changed") return true @@ -152,11 +165,11 @@ private fun runDateChange(date: String) : Boolean{ } } -private fun runTrade(tradeId: String) : Boolean { +private fun runTrade(tradeId: String, host: String) : Boolean { println("Uploading tradeID " + tradeId) val fileContents = IOUtils.toString(NodeParams::class.java.getResourceAsStream("example-irs-trade.json")) val tradeFile = fileContents.replace("tradeXXX", tradeId) - val url = URL("http://localhost:31338/api/irs/deals") + val url = URL(host + "/api/irs/deals") if(postJson(url, tradeFile)) { println("Trade sent") return true