diff --git a/core/src/main/kotlin/com/r3corda/core/node/CordaPluginRegistry.kt b/core/src/main/kotlin/com/r3corda/core/node/CordaPluginRegistry.kt index 89492ee373..57c26f9fe2 100644 --- a/core/src/main/kotlin/com/r3corda/core/node/CordaPluginRegistry.kt +++ b/core/src/main/kotlin/com/r3corda/core/node/CordaPluginRegistry.kt @@ -12,6 +12,13 @@ interface CordaPluginRegistry { */ val webApis: List> + /** + * Map of static serving endpoints to the matching resource directory. All endpoints will be prefixed with "/web" and postfixed with "\*. + * Resource directories can be either on disk directories (especially when debugging) in the form "a/b/c". Serving from a JAR can + * be specified with: javaClass.getResource("").toExternalForm() + */ + val staticServeDirs: Map + /** * A Map with an entry for each consumed protocol used by the webAPIs. * The key of each map entry should contain the ProtocolLogic class name. diff --git a/node/src/main/kotlin/com/r3corda/node/internal/Node.kt b/node/src/main/kotlin/com/r3corda/node/internal/Node.kt index 1c5c167b76..af24eff634 100644 --- a/node/src/main/kotlin/com/r3corda/node/internal/Node.kt +++ b/node/src/main/kotlin/com/r3corda/node/internal/Node.kt @@ -16,8 +16,13 @@ import com.r3corda.node.servlets.Config import com.r3corda.node.servlets.DataUploadServlet import com.r3corda.node.servlets.ResponseFilter import com.r3corda.node.utilities.AffinityExecutor +import org.eclipse.jetty.server.Handler import org.eclipse.jetty.server.Server +import org.eclipse.jetty.server.handler.DefaultHandler import org.eclipse.jetty.server.handler.HandlerCollection +import org.eclipse.jetty.server.handler.HandlerList +import org.eclipse.jetty.server.handler.ResourceHandler +import org.eclipse.jetty.servlet.DefaultServlet import org.eclipse.jetty.servlet.ServletContextHandler import org.eclipse.jetty.servlet.ServletHolder import org.eclipse.jetty.webapp.WebAppContext @@ -116,6 +121,16 @@ class Node(dir: Path, val p2pAddr: HostAndPort, val webServerAddr: HostAndPort, resourceConfig.register(customAPI) } + val staticDirMaps = pluginRegistries.map { x -> x.staticServeDirs } + val staticDirs = staticDirMaps.flatMap { it.keys }.zip(staticDirMaps.flatMap { it.values }) + staticDirs.forEach { + val staticDir = ServletHolder(DefaultServlet::class.java) + staticDir.setInitParameter("resourceBase", it.second) + staticDir.setInitParameter("dirAllowed", "true") + staticDir.setInitParameter("pathInfoOnly", "true") + addServlet(staticDir, "/web/${it.first}/*") + } + // Give the app a slightly better name in JMX rather than a randomly generated one and enable JMX resourceConfig.addProperties(mapOf(ServerProperties.APPLICATION_NAME to "node.api", ServerProperties.MONITORING_STATISTICS_MBEANS_ENABLED to "true")) diff --git a/node/src/main/kotlin/com/r3corda/node/services/clientapi/NodeInterestRates.kt b/node/src/main/kotlin/com/r3corda/node/services/clientapi/NodeInterestRates.kt index d69dd39e2a..9c208e38a1 100644 --- a/node/src/main/kotlin/com/r3corda/node/services/clientapi/NodeInterestRates.kt +++ b/node/src/main/kotlin/com/r3corda/node/services/clientapi/NodeInterestRates.kt @@ -102,7 +102,7 @@ object NodeInterestRates { class FixingServicePlugin : CordaPluginRegistry { override val webApis: List> = emptyList() override val requiredProtocols: Map> = mapOf(Pair(TwoPartyDealProtocol.FixingRoleDecider::class.java.name, setOf(Duration::class.java.name, StateRef::class.java.name))) - + override val staticServeDirs: Map = emptyMap() } // File upload support diff --git a/src/main/kotlin/com/r3corda/demos/IRSDemo.kt b/src/main/kotlin/com/r3corda/demos/IRSDemo.kt index 619287e7de..36bdc2e863 100644 --- a/src/main/kotlin/com/r3corda/demos/IRSDemo.kt +++ b/src/main/kotlin/com/r3corda/demos/IRSDemo.kt @@ -243,6 +243,7 @@ object CliParamsSpec { class IRSDemoPluginRegistry : CordaPluginRegistry { override val webApis: List> = listOf(InterestRateSwapAPI::class.java) + override val staticServeDirs: Map = mapOf("irsdemo" to javaClass.getResource("irswebdemo").toExternalForm()) override val requiredProtocols: Map> = mapOf( Pair(AutoOfferProtocol.Requester::class.java.name, setOf(InterestRateSwap.State::class.java.name)), Pair(UpdateBusinessDayProtocol.Broadcast::class.java.name, setOf(java.time.LocalDate::class.java.name)), @@ -384,7 +385,6 @@ private fun startNode(params: CliParams.RunNode, networkMap: SingleMessageRecipi val node = logElapsedTime("Node startup") { Node(params.dir, params.networkAddress, params.apiAddress, config, networkMapId, advertisedServices, DemoClock()).start() } - // TODO: This should all be replaced by the identity service being updated // as the network map changes. if (params.tradeWithAddrs.size != params.tradeWithIdentities.size) { diff --git a/src/main/kotlin/com/r3corda/demos/api/InterestRateSwapAPI.kt b/src/main/kotlin/com/r3corda/demos/api/InterestRateSwapAPI.kt index 76dcdd4bfe..2b680086e9 100644 --- a/src/main/kotlin/com/r3corda/demos/api/InterestRateSwapAPI.kt +++ b/src/main/kotlin/com/r3corda/demos/api/InterestRateSwapAPI.kt @@ -121,24 +121,23 @@ class InterestRateSwapAPI(val services: ServiceHub) { return Response.ok().build() } - @GET - @Path("web/{filepath: (.*(.html|.css|.js|.png|.jpg|.gif|.json|ttf|woff|woff2))?}") - fun serveWeb(@PathParam("filepath") filepath: String) : Response { - try { - val resourcePath = if(filepath == "") { "index.html" } else { filepath } - val resource = javaClass.getResourceAsStream("irswebdemo/" + resourcePath) - if(resource != null) { - val cacheControl = CacheControl(); - cacheControl.maxAge = 0 - logger.info("200: serving ${filepath}") - return Response.ok(resource).cacheControl(cacheControl).build() - } - - logger.info("404: could not find: ${filepath}") - return Response.status(Response.Status.NOT_FOUND).build() - } catch(ex: Exception) { - logger.info("500: error when serving: ${filepath}. ${ex.toString()}") - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build() - } - } + //@GET + //@Path("web/{filepath: (.*(.html|.css|.js|.png|.jpg|.gif|.json|ttf|woff|woff2))?}") + //fun serveWeb(@PathParam("filepath") filepath: String) : Response { + // try { + // val resourcePath = if(filepath == "") { "index.html" } else { filepath } + // val resource = javaClass.getResourceAsStream("irswebdemo/" + resourcePath) + // if(resource != null) { + // val cacheControl = CacheControl(); + // cacheControl.maxAge = 0 + // logger.info("200: serving ${filepath}") + // return Response.ok(resource).cacheControl(cacheControl).build() + // } + // logger.info("404: could not find: ${filepath}") + // return Response.status(Response.Status.NOT_FOUND).build() + // } catch(ex: Exception) { + // logger.info("500: error when serving: ${filepath}. ${ex.toString()}") + // return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build() + // } + //} } diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/.bowerrc b/src/main/resources/com/r3corda/demos/irswebdemo/.bowerrc similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/.bowerrc rename to src/main/resources/com/r3corda/demos/irswebdemo/.bowerrc diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/.gitignore b/src/main/resources/com/r3corda/demos/irswebdemo/.gitignore similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/.gitignore rename to src/main/resources/com/r3corda/demos/irswebdemo/.gitignore diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/bower.json b/src/main/resources/com/r3corda/demos/irswebdemo/bower.json similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/bower.json rename to src/main/resources/com/r3corda/demos/irswebdemo/bower.json diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/css/main.css b/src/main/resources/com/r3corda/demos/irswebdemo/css/main.css similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/css/main.css rename to src/main/resources/com/r3corda/demos/irswebdemo/css/main.css diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/index.html b/src/main/resources/com/r3corda/demos/irswebdemo/index.html similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/index.html rename to src/main/resources/com/r3corda/demos/irswebdemo/index.html diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/js/Deal.js b/src/main/resources/com/r3corda/demos/irswebdemo/js/Deal.js similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/js/Deal.js rename to src/main/resources/com/r3corda/demos/irswebdemo/js/Deal.js diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/js/app.js b/src/main/resources/com/r3corda/demos/irswebdemo/js/app.js similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/js/app.js rename to src/main/resources/com/r3corda/demos/irswebdemo/js/app.js diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/js/controllers/CreateDeal.js b/src/main/resources/com/r3corda/demos/irswebdemo/js/controllers/CreateDeal.js similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/js/controllers/CreateDeal.js rename to src/main/resources/com/r3corda/demos/irswebdemo/js/controllers/CreateDeal.js diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/js/controllers/Deal.js b/src/main/resources/com/r3corda/demos/irswebdemo/js/controllers/Deal.js similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/js/controllers/Deal.js rename to src/main/resources/com/r3corda/demos/irswebdemo/js/controllers/Deal.js diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/js/controllers/Home.js b/src/main/resources/com/r3corda/demos/irswebdemo/js/controllers/Home.js similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/js/controllers/Home.js rename to src/main/resources/com/r3corda/demos/irswebdemo/js/controllers/Home.js diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/js/require-config.js b/src/main/resources/com/r3corda/demos/irswebdemo/js/require-config.js similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/js/require-config.js rename to src/main/resources/com/r3corda/demos/irswebdemo/js/require-config.js diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/js/routes.js b/src/main/resources/com/r3corda/demos/irswebdemo/js/routes.js similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/js/routes.js rename to src/main/resources/com/r3corda/demos/irswebdemo/js/routes.js diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/js/services/NodeApi.js b/src/main/resources/com/r3corda/demos/irswebdemo/js/services/NodeApi.js similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/js/services/NodeApi.js rename to src/main/resources/com/r3corda/demos/irswebdemo/js/services/NodeApi.js diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/js/utils/dayCountBasisLookup.js b/src/main/resources/com/r3corda/demos/irswebdemo/js/utils/dayCountBasisLookup.js similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/js/utils/dayCountBasisLookup.js rename to src/main/resources/com/r3corda/demos/irswebdemo/js/utils/dayCountBasisLookup.js diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/js/utils/semantic.js b/src/main/resources/com/r3corda/demos/irswebdemo/js/utils/semantic.js similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/js/utils/semantic.js rename to src/main/resources/com/r3corda/demos/irswebdemo/js/utils/semantic.js diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/js/viewmodel/Common.js b/src/main/resources/com/r3corda/demos/irswebdemo/js/viewmodel/Common.js similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/js/viewmodel/Common.js rename to src/main/resources/com/r3corda/demos/irswebdemo/js/viewmodel/Common.js diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/js/viewmodel/Deal.js b/src/main/resources/com/r3corda/demos/irswebdemo/js/viewmodel/Deal.js similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/js/viewmodel/Deal.js rename to src/main/resources/com/r3corda/demos/irswebdemo/js/viewmodel/Deal.js diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/js/viewmodel/FixedLeg.js b/src/main/resources/com/r3corda/demos/irswebdemo/js/viewmodel/FixedLeg.js similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/js/viewmodel/FixedLeg.js rename to src/main/resources/com/r3corda/demos/irswebdemo/js/viewmodel/FixedLeg.js diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/js/viewmodel/FixedRate.js b/src/main/resources/com/r3corda/demos/irswebdemo/js/viewmodel/FixedRate.js similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/js/viewmodel/FixedRate.js rename to src/main/resources/com/r3corda/demos/irswebdemo/js/viewmodel/FixedRate.js diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/js/viewmodel/FloatingLeg.js b/src/main/resources/com/r3corda/demos/irswebdemo/js/viewmodel/FloatingLeg.js similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/js/viewmodel/FloatingLeg.js rename to src/main/resources/com/r3corda/demos/irswebdemo/js/viewmodel/FloatingLeg.js diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/view/create-deal.html b/src/main/resources/com/r3corda/demos/irswebdemo/view/create-deal.html similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/view/create-deal.html rename to src/main/resources/com/r3corda/demos/irswebdemo/view/create-deal.html diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/view/deal.html b/src/main/resources/com/r3corda/demos/irswebdemo/view/deal.html similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/view/deal.html rename to src/main/resources/com/r3corda/demos/irswebdemo/view/deal.html diff --git a/src/main/resources/com/r3corda/demos/api/irswebdemo/view/home.html b/src/main/resources/com/r3corda/demos/irswebdemo/view/home.html similarity index 100% rename from src/main/resources/com/r3corda/demos/api/irswebdemo/view/home.html rename to src/main/resources/com/r3corda/demos/irswebdemo/view/home.html