mirror of
https://github.com/corda/corda.git
synced 2024-12-27 00:21:12 +00:00
Moved IRS web folder up a level. Added support for static serving plugins.
This commit is contained in:
parent
88f4317606
commit
93f4440c14
@ -12,6 +12,13 @@ interface CordaPluginRegistry {
|
||||
*/
|
||||
val webApis: List<Class<*>>
|
||||
|
||||
/**
|
||||
* 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("<folder-in-jar>").toExternalForm()
|
||||
*/
|
||||
val staticServeDirs: Map<String, String>
|
||||
|
||||
/**
|
||||
* A Map with an entry for each consumed protocol used by the webAPIs.
|
||||
* The key of each map entry should contain the ProtocolLogic<T> class name.
|
||||
|
@ -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"))
|
||||
|
@ -102,7 +102,7 @@ object NodeInterestRates {
|
||||
class FixingServicePlugin : CordaPluginRegistry {
|
||||
override val webApis: List<Class<*>> = emptyList()
|
||||
override val requiredProtocols: Map<String, Set<String>> = mapOf(Pair(TwoPartyDealProtocol.FixingRoleDecider::class.java.name, setOf(Duration::class.java.name, StateRef::class.java.name)))
|
||||
|
||||
override val staticServeDirs: Map<String, String> = emptyMap()
|
||||
}
|
||||
|
||||
// File upload support
|
||||
|
@ -243,6 +243,7 @@ object CliParamsSpec {
|
||||
|
||||
class IRSDemoPluginRegistry : CordaPluginRegistry {
|
||||
override val webApis: List<Class<*>> = listOf(InterestRateSwapAPI::class.java)
|
||||
override val staticServeDirs: Map<String, String> = mapOf("irsdemo" to javaClass.getResource("irswebdemo").toExternalForm())
|
||||
override val requiredProtocols: Map<String, Set<String>> = 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) {
|
||||
|
@ -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()
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user