mirror of
https://github.com/corda/corda.git
synced 2025-04-15 15:07:03 +00:00
ENT-2681: Re-throw original exception when parsing using old format failed. (#1550)
* ENT-2681: Add explicit warning in the log explaining why parsing according to new configuration format has failed. (Before trying ot use old config format) * ENT-2681: Correctly report original error when parsing using old config format failed.
This commit is contained in:
parent
bac265d418
commit
7a62e65ec7
@ -1,6 +1,7 @@
|
||||
package net.corda.bridge.services.config
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigException
|
||||
import com.typesafe.config.ConfigRenderOptions
|
||||
import net.corda.bridge.FirewallCmdLineOptions
|
||||
import net.corda.bridge.services.api.*
|
||||
@ -17,6 +18,8 @@ fun Config.parseAsFirewallConfiguration(): FirewallConfiguration {
|
||||
parseAs<FirewallConfigurationImpl>()
|
||||
} catch (ex: UnknownConfigurationKeysException) {
|
||||
|
||||
FirewallCmdLineOptions.logger.info("Attempting to parse using old format")
|
||||
|
||||
// Previously `proxyConfig` was known as `socksProxyConfig`
|
||||
data class Version3BridgeOutboundConfigurationImpl(val artemisBrokerAddress: NetworkHostAndPort,
|
||||
val alternateArtemisBrokerAddresses: List<NetworkHostAndPort>,
|
||||
@ -80,14 +83,20 @@ fun Config.parseAsFirewallConfiguration(): FirewallConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
// Note: "Ignore" is needed to disregard any default properties from "firewalldefault.conf" that are not applicable to V3 configuration
|
||||
val oldStyleConfig = parseAs<Version3BridgeConfigurationImpl>(UnknownConfigKeysPolicy.IGNORE::handle)
|
||||
val newStyleConfig = oldStyleConfig.toConfig()
|
||||
|
||||
val configAsString = newStyleConfig.toConfig().root().render(ConfigRenderOptions.defaults())
|
||||
FirewallCmdLineOptions.logger.warn("Old style config used. To avoid seeing this warning in the future, please upgrade to new style. " +
|
||||
"New style config will look as follows:\n$configAsString")
|
||||
newStyleConfig
|
||||
try {
|
||||
// Note: "Ignore" is needed to disregard any default properties from "firewalldefault.conf" that are not applicable to V3 configuration
|
||||
val oldStyleConfig = parseAs<Version3BridgeConfigurationImpl>(UnknownConfigKeysPolicy.IGNORE::handle)
|
||||
val newStyleConfig = oldStyleConfig.toConfig()
|
||||
|
||||
val configAsString = newStyleConfig.toConfig().root().render(ConfigRenderOptions.defaults())
|
||||
FirewallCmdLineOptions.logger.warn("Old style config used. To avoid seeing this warning in the future, please upgrade to new style. " +
|
||||
"New style config will look as follows:\n$configAsString")
|
||||
newStyleConfig
|
||||
} catch (oldFormatEx: ConfigException) {
|
||||
FirewallCmdLineOptions.logger.error("Old format parsing failed as well.")
|
||||
throw ex
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,10 @@ import net.corda.bridge.services.api.FirewallMode
|
||||
import net.corda.core.identity.CordaX500Name
|
||||
import net.corda.core.internal.div
|
||||
import net.corda.core.utilities.NetworkHostAndPort
|
||||
import net.corda.nodeapi.internal.config.UnknownConfigurationKeysException
|
||||
import net.corda.nodeapi.internal.protonwrapper.netty.ProxyVersion
|
||||
import net.corda.testing.core.SerializationEnvironmentRule
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Rule
|
||||
@ -174,4 +176,13 @@ class ConfigTest {
|
||||
assertEquals("proxyUser", config.outboundConfig!!.proxyConfig!!.userName)
|
||||
assertEquals("pwd", config.outboundConfig!!.proxyConfig!!.password)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Load invalid option config`() {
|
||||
val configResource = "/net/corda/bridge/invalidoption/firewall.conf"
|
||||
|
||||
Assertions.assertThatThrownBy { createAndLoadConfigFromResource(tempFolder.root.toPath(), configResource) }
|
||||
.isInstanceOf(UnknownConfigurationKeysException::class.java)
|
||||
.hasMessageContaining("invalidOption")
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
firewallMode = SenderReceiver
|
||||
outboundConfig : {
|
||||
artemisBrokerAddress = "localhost:11005"
|
||||
proxyConfig : {
|
||||
version = SOCKS5
|
||||
proxyAddress = "localhost:12345"
|
||||
userName = "proxyUser"
|
||||
password = "pwd"
|
||||
}
|
||||
}
|
||||
|
||||
invalidOption = "fooBar"
|
||||
|
||||
inboundConfig : {
|
||||
listeningAddress = "0.0.0.0:10005"
|
||||
}
|
||||
networkParametersPath = network-parameters
|
||||
|
||||
healthCheckPhrase = "ISpeakAMQP!"
|
Loading…
x
Reference in New Issue
Block a user