mirror of
https://github.com/corda/corda.git
synced 2024-12-19 21:17:58 +00:00
Merge pull request #469 from corda/clint-reducebuildsize
Webserver no longer depends on node.
This commit is contained in:
commit
fcdcb0bdcf
@ -136,7 +136,7 @@ dependencies {
|
||||
compile "com.google.guava:guava:$guava_version"
|
||||
|
||||
runtime project(path: ":node:capsule", configuration: 'runtimeArtifacts')
|
||||
runtime project(path: ":node:webserver:webcapsule", configuration: 'runtimeArtifacts')
|
||||
runtime project(path: ":webserver:webcapsule", configuration: 'runtimeArtifacts')
|
||||
|
||||
// For the buildCordappDependenciesJar task
|
||||
runtime project(':client:jfx')
|
||||
@ -144,7 +144,7 @@ dependencies {
|
||||
runtime project(':client:rpc')
|
||||
runtime project(':core')
|
||||
runtime project(':finance')
|
||||
runtime project(':node:webserver')
|
||||
runtime project(':webserver')
|
||||
testCompile project(':test-utils')
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ dependencies {
|
||||
}
|
||||
|
||||
runtime project(path: ":node:capsule", configuration: 'runtimeArtifacts')
|
||||
runtime project(path: ":node:webserver:webcapsule", configuration: 'runtimeArtifacts')
|
||||
runtime project(path: ":webserver:webcapsule", configuration: 'runtimeArtifacts')
|
||||
}
|
||||
|
||||
mainClassName = "net.corda.docs.ClientRpcTutorialKt"
|
||||
|
@ -37,7 +37,7 @@ dependencies {
|
||||
|
||||
// Corda integration dependencies
|
||||
runtime project(path: ":node:capsule", configuration: 'runtimeArtifacts')
|
||||
runtime project(path: ":node:webserver:webcapsule", configuration: 'runtimeArtifacts')
|
||||
runtime project(path: ":webserver:webcapsule", configuration: 'runtimeArtifacts')
|
||||
compile project(':core')
|
||||
compile project(':test-utils')
|
||||
|
||||
|
@ -37,7 +37,7 @@ dependencies {
|
||||
|
||||
// Corda integration dependencies
|
||||
runtime project(path: ":node:capsule", configuration: 'runtimeArtifacts')
|
||||
runtime project(path: ":node:webserver:webcapsule", configuration: 'runtimeArtifacts')
|
||||
runtime project(path: ":webserver:webcapsule", configuration: 'runtimeArtifacts')
|
||||
compile project(':core')
|
||||
compile project(':client:jfx')
|
||||
compile project(':client:rpc')
|
||||
|
@ -40,10 +40,10 @@ dependencies {
|
||||
|
||||
// Corda integration dependencies
|
||||
runtime project(path: ":node:capsule", configuration: 'runtimeArtifacts')
|
||||
runtime project(path: ":node:webserver:webcapsule", configuration: 'runtimeArtifacts')
|
||||
runtime project(path: ":webserver:webcapsule", configuration: 'runtimeArtifacts')
|
||||
compile project(':core')
|
||||
compile project(':finance')
|
||||
compile project(':node:webserver')
|
||||
compile project(':webserver')
|
||||
compile project(':test-utils')
|
||||
|
||||
// Javax is required for webapis
|
||||
|
@ -13,7 +13,7 @@ dependencies {
|
||||
|
||||
// Corda integration dependencies
|
||||
runtime project(path: ":node:capsule", configuration: 'runtimeArtifacts')
|
||||
runtime project(path: ":node:webserver:webcapsule", configuration: 'runtimeArtifacts')
|
||||
runtime project(path: ":webserver:webcapsule", configuration: 'runtimeArtifacts')
|
||||
compile project(':core')
|
||||
compile project(':finance')
|
||||
testCompile project(':test-utils')
|
||||
|
@ -37,7 +37,7 @@ dependencies {
|
||||
|
||||
// Corda integration dependencies
|
||||
runtime project(path: ":node:capsule", configuration: 'runtimeArtifacts')
|
||||
runtime project(path: ":node:webserver:webcapsule", configuration: 'runtimeArtifacts')
|
||||
runtime project(path: ":webserver:webcapsule", configuration: 'runtimeArtifacts')
|
||||
compile project(':core')
|
||||
compile project(':client:jfx')
|
||||
compile project(':client:rpc')
|
||||
|
@ -41,10 +41,10 @@ dependencies {
|
||||
|
||||
// Corda integration dependencies
|
||||
runtime project(path: ":node:capsule", configuration: 'runtimeArtifacts')
|
||||
runtime project(path: ":node:webserver:webcapsule", configuration: 'runtimeArtifacts')
|
||||
runtime project(path: ":webserver:webcapsule", configuration: 'runtimeArtifacts')
|
||||
compile project(':core')
|
||||
compile project(':node')
|
||||
compile project(':node:webserver')
|
||||
compile project(':webserver')
|
||||
compile project(':finance')
|
||||
testCompile project(':test-utils')
|
||||
|
||||
|
@ -37,7 +37,7 @@ dependencies {
|
||||
|
||||
// Corda integration dependencies
|
||||
runtime project(path: ":node:capsule", configuration: 'runtimeArtifacts')
|
||||
runtime project(path: ":node:webserver:webcapsule", configuration: 'runtimeArtifacts')
|
||||
runtime project(path: ":webserver:webcapsule", configuration: 'runtimeArtifacts')
|
||||
compile project(':core')
|
||||
compile project(':finance')
|
||||
compile project(':test-utils')
|
||||
|
@ -9,12 +9,12 @@ include 'node-api'
|
||||
include 'node-schemas'
|
||||
include 'node'
|
||||
include 'node:capsule'
|
||||
include 'node:webserver'
|
||||
include 'node:webserver:webcapsule'
|
||||
include 'client:jackson'
|
||||
include 'client:jfx'
|
||||
include 'client:mock'
|
||||
include 'client:rpc'
|
||||
include 'webserver'
|
||||
include 'webserver:webcapsule'
|
||||
include 'experimental'
|
||||
include 'experimental:sandbox'
|
||||
include 'verifier'
|
||||
|
@ -14,7 +14,7 @@ dependencies {
|
||||
compile project(':finance')
|
||||
compile project(':core')
|
||||
compile project(':node')
|
||||
compile project(':node:webserver')
|
||||
compile project(':webserver')
|
||||
compile project(':verifier')
|
||||
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
|
||||
|
@ -107,7 +107,7 @@ distributions {
|
||||
rename 'corda-(.*)', 'corda.jar'
|
||||
into 'corda'
|
||||
}
|
||||
from(project(':node:webserver:webcapsule').tasks.buildWebserverJar) {
|
||||
from(project(':webserver:webcapsule').tasks.buildWebserverJar) {
|
||||
rename 'corda-webserver-(.*)', 'corda-webserver.jar'
|
||||
into 'corda'
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ apply plugin: 'kotlin'
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'net.corda.plugins.publish-utils'
|
||||
|
||||
// TODO: Break dependency on node and move to another location such as a submodule of client.
|
||||
description 'Corda node web server'
|
||||
|
||||
configurations {
|
||||
@ -20,43 +19,41 @@ sourceSets {
|
||||
}
|
||||
test {
|
||||
resources {
|
||||
srcDir "../config/test"
|
||||
srcDir "$rootDir/config/test"
|
||||
}
|
||||
}
|
||||
main {
|
||||
resources {
|
||||
srcDir "../config/dev"
|
||||
srcDir "$rootDir/config/dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':core')
|
||||
compile project(':node') // TODO: Break this dependency
|
||||
compile project(':client:rpc')
|
||||
compile project(':client:jackson')
|
||||
testCompile project(':node')
|
||||
|
||||
// Web stuff: for HTTP[S] servlets
|
||||
compile "org.eclipse.jetty:jetty-servlet:${jetty_version}"
|
||||
compile "org.eclipse.jetty:jetty-webapp:${jetty_version}"
|
||||
compile "org.eclipse.jetty:jetty-servlet:$jetty_version"
|
||||
compile "org.eclipse.jetty:jetty-webapp:$jetty_version"
|
||||
compile "javax.servlet:javax.servlet-api:3.1.0"
|
||||
compile "org.jolokia:jolokia-agent-war:$jolokia_version"
|
||||
compile "commons-fileupload:commons-fileupload:$fileupload_version"
|
||||
|
||||
// Jersey for JAX-RS implementation for use in Jetty
|
||||
compile "org.glassfish.jersey.core:jersey-server:${jersey_version}"
|
||||
compile "org.glassfish.jersey.containers:jersey-container-servlet-core:${jersey_version}"
|
||||
compile "org.glassfish.jersey.containers:jersey-container-jetty-http:${jersey_version}"
|
||||
// NOTE there is a Jackson version clash between jersey-media-json-jackson (v2.5.4) and jackson-module-kotlin (v.2.5.5)
|
||||
// Have not found an Issue in the issue tracker for Jersey for this issue
|
||||
compile ("org.glassfish.jersey.media:jersey-media-json-jackson:${jersey_version}") {
|
||||
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-annotations'
|
||||
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-databind'
|
||||
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-core'
|
||||
}
|
||||
// Log4J: logging framework (with SLF4J bindings)
|
||||
compile "org.apache.logging.log4j:log4j-slf4j-impl:$log4j_version"
|
||||
compile "org.apache.logging.log4j:log4j-core:$log4j_version"
|
||||
|
||||
compile ("com.fasterxml.jackson.module:jackson-module-kotlin:${jackson_version}") {
|
||||
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-annotations'
|
||||
}
|
||||
// JOpt: for command line flags.
|
||||
compile "net.sf.jopt-simple:jopt-simple:$jopt_simple_version"
|
||||
|
||||
// Jersey for JAX-RS implementation for use in Jetty
|
||||
compile "org.glassfish.jersey.core:jersey-server:$jersey_version"
|
||||
compile "org.glassfish.jersey.containers:jersey-container-servlet-core:$jersey_version"
|
||||
compile "org.glassfish.jersey.containers:jersey-container-jetty-http:$jersey_version"
|
||||
compile "org.glassfish.jersey.media:jersey-media-json-jackson:$jersey_version"
|
||||
|
||||
testCompile "junit:junit:$junit_version"
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package net.corda.webserver
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import com.typesafe.config.ConfigParseOptions
|
||||
import com.typesafe.config.ConfigRenderOptions
|
||||
import joptsimple.OptionParser
|
||||
import joptsimple.util.EnumConverter
|
||||
import net.corda.core.div
|
||||
import net.corda.core.utilities.loggerFor
|
||||
import org.slf4j.event.Level
|
||||
import java.io.PrintStream
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
|
||||
// NOTE: Do not use any logger in this class as args parsing is done before the logger is setup.
|
||||
class ArgsParser {
|
||||
private val optionParser = OptionParser()
|
||||
// The intent of allowing a command line configurable directory and config path is to allow deployment flexibility.
|
||||
// Other general configuration should live inside the config file unless we regularly need temporary overrides on the command line
|
||||
private val baseDirectoryArg = optionParser
|
||||
.accepts("base-directory", "The node working directory where all the files are kept")
|
||||
.withRequiredArg()
|
||||
.defaultsTo(".")
|
||||
private val configFileArg = optionParser
|
||||
.accepts("config-file", "The path to the config file")
|
||||
.withRequiredArg()
|
||||
.defaultsTo("node.conf")
|
||||
private val loggerLevel = optionParser
|
||||
.accepts("logging-level", "Enable logging at this level and higher")
|
||||
.withRequiredArg()
|
||||
.withValuesConvertedBy(object : EnumConverter<Level>(Level::class.java) {})
|
||||
.defaultsTo(Level.INFO)
|
||||
private val logToConsoleArg = optionParser.accepts("log-to-console", "If set, prints logging to the console as well as to a file.")
|
||||
private val helpArg = optionParser.accepts("help").forHelp()
|
||||
|
||||
fun parse(vararg args: String): CmdLineOptions {
|
||||
val optionSet = optionParser.parse(*args)
|
||||
require(!optionSet.has(baseDirectoryArg) || !optionSet.has(configFileArg)) {
|
||||
"${baseDirectoryArg.options()[0]} and ${configFileArg.options()[0]} cannot be specified together"
|
||||
}
|
||||
val baseDirectory = Paths.get(optionSet.valueOf(baseDirectoryArg)).normalize().toAbsolutePath()
|
||||
val configFile = baseDirectory / optionSet.valueOf(configFileArg)
|
||||
val help = optionSet.has(helpArg)
|
||||
val loggingLevel = optionSet.valueOf(loggerLevel)
|
||||
val logToConsole = optionSet.has(logToConsoleArg)
|
||||
return CmdLineOptions(baseDirectory, configFile, help, loggingLevel, logToConsole)
|
||||
}
|
||||
|
||||
fun printHelp(sink: PrintStream) = optionParser.printHelpOn(sink)
|
||||
}
|
||||
|
||||
data class CmdLineOptions(val baseDirectory: Path,
|
||||
val configFile: Path,
|
||||
val help: Boolean,
|
||||
val loggingLevel: Level,
|
||||
val logToConsole: Boolean) {
|
||||
|
||||
fun loadConfig(allowMissingConfig: Boolean = false, configOverrides: Map<String, Any?> = emptyMap()): Config {
|
||||
return loadConfig(baseDirectory, configFile, allowMissingConfig, configOverrides)
|
||||
}
|
||||
|
||||
private fun loadConfig(baseDirectory: Path,
|
||||
configFile: Path = baseDirectory / "node.conf",
|
||||
allowMissingConfig: Boolean = false,
|
||||
configOverrides: Map<String, Any?> = emptyMap()): Config {
|
||||
val parseOptions = ConfigParseOptions.defaults()
|
||||
val defaultConfig = ConfigFactory.parseResources("web-reference.conf", parseOptions.setAllowMissing(false))
|
||||
val appConfig = ConfigFactory.parseFile(configFile.toFile(), parseOptions.setAllowMissing(allowMissingConfig))
|
||||
val overrideConfig = ConfigFactory.parseMap(configOverrides + mapOf(
|
||||
// Add substitution values here
|
||||
"basedir" to baseDirectory.toString())
|
||||
)
|
||||
val finalConfig = overrideConfig
|
||||
.withFallback(appConfig)
|
||||
.withFallback(defaultConfig)
|
||||
.resolve()
|
||||
val log = loggerFor<CmdLineOptions>()
|
||||
log.info("Config:\n${finalConfig.root().render(ConfigRenderOptions.defaults())}")
|
||||
return finalConfig
|
||||
}
|
||||
}
|
@ -5,8 +5,6 @@ package net.corda.webserver
|
||||
import com.typesafe.config.ConfigException
|
||||
import net.corda.core.div
|
||||
import net.corda.core.rootCause
|
||||
import net.corda.node.ArgsParser
|
||||
import net.corda.node.services.config.FullNodeConfiguration
|
||||
import net.corda.webserver.internal.NodeWebServer
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.lang.management.ManagementFactory
|
||||
@ -36,18 +34,18 @@ fun main(args: Array<String>) {
|
||||
System.setProperty("consoleLogLevel", "info")
|
||||
}
|
||||
|
||||
System.setProperty("log-path", (cmdlineOptions.baseDirectory / "web/logs").toString())
|
||||
System.setProperty("log-path", (cmdlineOptions.baseDirectory / "logs/web").toString())
|
||||
val log = LoggerFactory.getLogger("Main")
|
||||
println("Logs can be found in ${System.getProperty("log-path")}")
|
||||
|
||||
val conf = try {
|
||||
FullNodeConfiguration(cmdlineOptions.baseDirectory, cmdlineOptions.loadConfig())
|
||||
WebServerConfig(cmdlineOptions.baseDirectory, cmdlineOptions.loadConfig())
|
||||
} catch (e: ConfigException) {
|
||||
println("Unable to load the configuration file: ${e.rootCause.message}")
|
||||
exitProcess(2)
|
||||
}
|
||||
|
||||
log.info("Main class: ${FullNodeConfiguration::class.java.protectionDomain.codeSource.location.toURI().path}")
|
||||
log.info("Main class: ${WebServerConfig::class.java.protectionDomain.codeSource.location.toURI().path}")
|
||||
val info = ManagementFactory.getRuntimeMXBean()
|
||||
log.info("CommandLine Args: ${info.inputArguments.joinToString(" ")}")
|
||||
log.info("Application Args: ${args.joinToString(" ")}")
|
||||
@ -68,4 +66,4 @@ fun main(args: Array<String>) {
|
||||
log.error("Exception during node startup", e)
|
||||
exitProcess(1)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package net.corda.webserver
|
||||
|
||||
import com.google.common.net.HostAndPort
|
||||
import com.typesafe.config.Config
|
||||
import net.corda.core.div
|
||||
import net.corda.nodeapi.User
|
||||
import net.corda.nodeapi.config.SSLConfiguration
|
||||
import net.corda.nodeapi.config.getListOrElse
|
||||
import net.corda.nodeapi.config.getValue
|
||||
import java.nio.file.Path
|
||||
|
||||
/**
|
||||
* [baseDirectory] is not retrieved from the config file but rather from a command line argument.
|
||||
*/
|
||||
class WebServerConfig(val baseDirectory: Path, val config: Config) : SSLConfiguration {
|
||||
override val certificatesDirectory: Path get() = baseDirectory / "certificates"
|
||||
override val keyStorePassword: String by config
|
||||
override val trustStorePassword: String by config
|
||||
val exportJMXto: String get() = "http"
|
||||
val useHTTPS: Boolean by config
|
||||
val p2pAddress: HostAndPort by config // TODO: Use RPC port instead of P2P port (RPC requires authentication, P2P does not)
|
||||
val webAddress: HostAndPort by config
|
||||
}
|
@ -4,9 +4,8 @@ import net.corda.client.rpc.CordaRPCClient
|
||||
import net.corda.core.messaging.CordaRPCOps
|
||||
import net.corda.core.node.CordaPluginRegistry
|
||||
import net.corda.core.utilities.loggerFor
|
||||
import net.corda.node.printBasicNodeInfo
|
||||
import net.corda.node.services.config.FullNodeConfiguration
|
||||
import net.corda.nodeapi.ArtemisMessagingComponent
|
||||
import net.corda.webserver.WebServerConfig
|
||||
import net.corda.webserver.servlets.AttachmentDownloadServlet
|
||||
import net.corda.webserver.servlets.DataUploadServlet
|
||||
import net.corda.webserver.servlets.ObjectMapperConfig
|
||||
@ -22,20 +21,22 @@ import org.eclipse.jetty.webapp.WebAppContext
|
||||
import org.glassfish.jersey.server.ResourceConfig
|
||||
import org.glassfish.jersey.server.ServerProperties
|
||||
import org.glassfish.jersey.servlet.ServletContainer
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.lang.reflect.InvocationTargetException
|
||||
import java.util.*
|
||||
|
||||
class NodeWebServer(val config: FullNodeConfiguration) {
|
||||
class NodeWebServer(val config: WebServerConfig) {
|
||||
private companion object {
|
||||
val log = loggerFor<NodeWebServer>()
|
||||
val retryDelay = 1000L // Milliseconds
|
||||
}
|
||||
|
||||
val address = config.webAddress
|
||||
private var renderBasicInfoToConsole = true
|
||||
private lateinit var server: Server
|
||||
|
||||
fun start() {
|
||||
printBasicNodeInfo("Starting as webserver: ${config.webAddress}")
|
||||
logAndMaybePrint("Starting as webserver: ${config.webAddress}")
|
||||
server = initWebServer(retryConnectLocalRpc())
|
||||
}
|
||||
|
||||
@ -175,4 +176,11 @@ class NodeWebServer(val config: FullNodeConfiguration) {
|
||||
val pluginRegistries: List<CordaPluginRegistry> by lazy {
|
||||
ServiceLoader.load(CordaPluginRegistry::class.java).toList()
|
||||
}
|
||||
|
||||
/** Used for useful info that we always want to show, even when not logging to the console */
|
||||
fun logAndMaybePrint(description: String, info: String? = null) {
|
||||
val msg = if (info == null) description else "${description.padEnd(40)}: $info"
|
||||
val loggerName = if (renderBasicInfoToConsole) "BasicInfo" else "Main"
|
||||
LoggerFactory.getLogger(loggerName).info(msg)
|
||||
}
|
||||
}
|
3
webserver/src/main/resources/web-reference.conf
Normal file
3
webserver/src/main/resources/web-reference.conf
Normal file
@ -0,0 +1,3 @@
|
||||
useHTTPS = false
|
||||
keyStorePassword = "cordacadevpass"
|
||||
trustStorePassword = "trustpass"
|
@ -22,18 +22,18 @@ targetCompatibility = 1.6
|
||||
sourceSets {
|
||||
test {
|
||||
resources {
|
||||
srcDir "../../../config/test"
|
||||
srcDir "$rootDir/config/test"
|
||||
}
|
||||
}
|
||||
main {
|
||||
resources {
|
||||
srcDir "../../../config/dev"
|
||||
srcDir "$rootDir/config/dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':node:webserver')
|
||||
compile project(':webserver')
|
||||
}
|
||||
|
||||
task buildWebserverJar(type: FatCapsule) {
|
Loading…
Reference in New Issue
Block a user