mirror of
https://github.com/corda/corda.git
synced 2025-06-17 22:58:19 +00:00
Corda-1505 catch connection failure exception and re-throw as RPCException (#3203)
* CORDA-1505: catch connection failure exception and rethrow as RPCException * CORDA-1443: remove incorrect import * CORDA-1443: fix some failing tests * CORDA-1505: fix broken CordaRPCClient test * fix tests * CORDA-1505: catch connection failure exception and rethrow as RPCException * CORDA-1443: remove incorrect import * CORDA-1443: fix some failing tests * CORDA-1505: fix broken CordaRPCClient test * fix tests * CORDA-1505: changed exception handling to RPCException * CORDA-1505: changed exception handling to RPCException
This commit is contained in:
@ -21,7 +21,6 @@ import net.corda.node.services.Permissions.Companion.all
|
|||||||
import net.corda.testing.core.*
|
import net.corda.testing.core.*
|
||||||
import net.corda.testing.node.User
|
import net.corda.testing.node.User
|
||||||
import net.corda.testing.node.internal.NodeBasedTest
|
import net.corda.testing.node.internal.NodeBasedTest
|
||||||
import org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException
|
|
||||||
import org.apache.activemq.artemis.api.core.ActiveMQSecurityException
|
import org.apache.activemq.artemis.api.core.ActiveMQSecurityException
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.assertj.core.api.Assertions.assertThatExceptionOfType
|
import org.assertj.core.api.Assertions.assertThatExceptionOfType
|
||||||
@ -102,7 +101,7 @@ class CordaRPCClientTest : NodeBasedTest(listOf("net.corda.finance.contracts", C
|
|||||||
}
|
}
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
} catch (e: ActiveMQNotConnectedException) {
|
} catch (e: RPCException) {
|
||||||
println("... node is not running.")
|
println("... node is not running.")
|
||||||
nodeIsShut.onCompleted()
|
nodeIsShut.onCompleted()
|
||||||
} catch (e: ActiveMQSecurityException) {
|
} catch (e: ActiveMQSecurityException) {
|
||||||
|
@ -14,13 +14,13 @@ import net.corda.node.services.messaging.RPCServerConfiguration
|
|||||||
import net.corda.nodeapi.RPCApi
|
import net.corda.nodeapi.RPCApi
|
||||||
import net.corda.nodeapi.eventually
|
import net.corda.nodeapi.eventually
|
||||||
import net.corda.testing.core.SerializationEnvironmentRule
|
import net.corda.testing.core.SerializationEnvironmentRule
|
||||||
|
import net.corda.testing.core.freePort
|
||||||
import net.corda.testing.internal.testThreadFactory
|
import net.corda.testing.internal.testThreadFactory
|
||||||
import net.corda.testing.node.internal.*
|
import net.corda.testing.node.internal.*
|
||||||
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration
|
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration
|
||||||
import org.apache.activemq.artemis.api.core.SimpleString
|
import org.apache.activemq.artemis.api.core.SimpleString
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.*
|
||||||
import org.junit.Assert.assertTrue
|
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
@ -326,6 +326,21 @@ class RPCStabilityTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `client throws RPCException after initial connection attempt fails`() {
|
||||||
|
val client = CordaRPCClient(NetworkHostAndPort("localhost", freePort()))
|
||||||
|
var exceptionMessage: String? = null
|
||||||
|
try {
|
||||||
|
client.start("user", "pass").proxy
|
||||||
|
} catch (e1: RPCException) {
|
||||||
|
exceptionMessage = e1.message
|
||||||
|
} catch (e2: Exception) {
|
||||||
|
fail("Expected RPCException to be thrown. Received ${e2.javaClass.simpleName} instead.")
|
||||||
|
}
|
||||||
|
assertNotNull(exceptionMessage)
|
||||||
|
assertEquals("Cannot connect to server(s). Tried with all available servers.", exceptionMessage)
|
||||||
|
}
|
||||||
|
|
||||||
interface ServerOps : RPCOps {
|
interface ServerOps : RPCOps {
|
||||||
fun serverId(): String
|
fun serverId(): String
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ import net.corda.core.utilities.getOrThrow
|
|||||||
import net.corda.nodeapi.RPCApi
|
import net.corda.nodeapi.RPCApi
|
||||||
import net.corda.nodeapi.internal.DeduplicationChecker
|
import net.corda.nodeapi.internal.DeduplicationChecker
|
||||||
import org.apache.activemq.artemis.api.core.ActiveMQException
|
import org.apache.activemq.artemis.api.core.ActiveMQException
|
||||||
|
import org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException
|
||||||
import org.apache.activemq.artemis.api.core.RoutingType
|
import org.apache.activemq.artemis.api.core.RoutingType
|
||||||
import org.apache.activemq.artemis.api.core.SimpleString
|
import org.apache.activemq.artemis.api.core.SimpleString
|
||||||
import org.apache.activemq.artemis.api.core.client.ActiveMQClient.DEFAULT_ACK_BATCH_SIZE
|
import org.apache.activemq.artemis.api.core.client.ActiveMQClient.DEFAULT_ACK_BATCH_SIZE
|
||||||
@ -214,7 +215,11 @@ class RPCClientProxyHandler(
|
|||||||
// If there's only one available, that one will be retried continuously as configured in rpcConfiguration.
|
// If there's only one available, that one will be retried continuously as configured in rpcConfiguration.
|
||||||
// There is no failover on first attempt, meaning that if a connection cannot be established, the serverLocator
|
// There is no failover on first attempt, meaning that if a connection cannot be established, the serverLocator
|
||||||
// will try another transport if it exists or throw an exception otherwise.
|
// will try another transport if it exists or throw an exception otherwise.
|
||||||
sessionFactory = serverLocator.createSessionFactory()
|
try {
|
||||||
|
sessionFactory = serverLocator.createSessionFactory()
|
||||||
|
} catch (e: ActiveMQNotConnectedException) {
|
||||||
|
throw (RPCException("Cannot connect to server(s). Tried with all available servers.", e))
|
||||||
|
}
|
||||||
// Depending on how the client is constructed, connection failure is treated differently
|
// Depending on how the client is constructed, connection failure is treated differently
|
||||||
if (serverLocator.staticTransportConfigurations.size == 1) {
|
if (serverLocator.staticTransportConfigurations.size == 1) {
|
||||||
sessionFactory!!.addFailoverListener(this::failoverHandler)
|
sessionFactory!!.addFailoverListener(this::failoverHandler)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.corda.node.services.rpc
|
package net.corda.node.services.rpc
|
||||||
|
|
||||||
import net.corda.client.rpc.CordaRPCClient
|
import net.corda.client.rpc.CordaRPCClient
|
||||||
|
import net.corda.client.rpc.RPCException
|
||||||
import net.corda.core.internal.div
|
import net.corda.core.internal.div
|
||||||
import net.corda.core.utilities.getOrThrow
|
import net.corda.core.utilities.getOrThrow
|
||||||
import net.corda.node.services.Permissions.Companion.all
|
import net.corda.node.services.Permissions.Companion.all
|
||||||
@ -16,7 +17,6 @@ import net.corda.testing.internal.saveToTrustStore
|
|||||||
import net.corda.testing.internal.useSslRpcOverrides
|
import net.corda.testing.internal.useSslRpcOverrides
|
||||||
import net.corda.testing.node.User
|
import net.corda.testing.node.User
|
||||||
import org.apache.activemq.artemis.api.core.ActiveMQException
|
import org.apache.activemq.artemis.api.core.ActiveMQException
|
||||||
import org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException
|
|
||||||
import org.apache.activemq.artemis.api.core.ActiveMQSecurityException
|
import org.apache.activemq.artemis.api.core.ActiveMQSecurityException
|
||||||
import org.assertj.core.api.Assertions
|
import org.assertj.core.api.Assertions
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
@ -90,7 +90,7 @@ class RpcSslTest {
|
|||||||
successful = true
|
successful = true
|
||||||
}
|
}
|
||||||
connection.close()
|
connection.close()
|
||||||
}.isInstanceOf(ActiveMQNotConnectedException::class.java)
|
}.isInstanceOf(RPCException::class.java)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ class RpcSslTest {
|
|||||||
clientAdmin.start(NODE_RPC_USER, NODE_RPC_USER).use { connection ->
|
clientAdmin.start(NODE_RPC_USER, NODE_RPC_USER).use { connection ->
|
||||||
connection.proxy.nodeInfo()
|
connection.proxy.nodeInfo()
|
||||||
}
|
}
|
||||||
}.isInstanceOf(ActiveMQException::class.java)
|
}.isInstanceOf(RPCException::class.java)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.corda.node.services.rpc
|
package net.corda.node.services.rpc
|
||||||
|
|
||||||
|
import net.corda.client.rpc.RPCException
|
||||||
import net.corda.client.rpc.internal.RPCClient
|
import net.corda.client.rpc.internal.RPCClient
|
||||||
import net.corda.core.context.AuthServiceId
|
import net.corda.core.context.AuthServiceId
|
||||||
import net.corda.core.identity.CordaX500Name
|
import net.corda.core.identity.CordaX500Name
|
||||||
@ -24,7 +25,6 @@ import net.corda.testing.internal.createNodeSslConfig
|
|||||||
import net.corda.testing.internal.saveToKeyStore
|
import net.corda.testing.internal.saveToKeyStore
|
||||||
import net.corda.testing.internal.saveToTrustStore
|
import net.corda.testing.internal.saveToTrustStore
|
||||||
import org.apache.activemq.artemis.api.core.ActiveMQConnectionTimedOutException
|
import org.apache.activemq.artemis.api.core.ActiveMQConnectionTimedOutException
|
||||||
import org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException
|
|
||||||
import org.apache.activemq.artemis.api.core.management.ActiveMQServerControl
|
import org.apache.activemq.artemis.api.core.management.ActiveMQServerControl
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||||
@ -89,7 +89,7 @@ class ArtemisRpcTests {
|
|||||||
|
|
||||||
assertThatThrownBy {
|
assertThatThrownBy {
|
||||||
testSslCommunication(createNodeSslConfig(tempFolder.root.toPath()), brokerSslOptions, true, clientSslOptions)
|
testSslCommunication(createNodeSslConfig(tempFolder.root.toPath()), brokerSslOptions, true, clientSslOptions)
|
||||||
}.isInstanceOf(ActiveMQNotConnectedException::class.java)
|
}.isInstanceOf(RPCException::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun testSslCommunication(nodeSSlconfig: SSLConfiguration, brokerSslOptions: BrokerRpcSslOptions?, useSslForBroker: Boolean, clientSslOptions: ClientRpcSslOptions?, address: NetworkHostAndPort = ports.nextHostAndPort(),
|
private fun testSslCommunication(nodeSSlconfig: SSLConfiguration, brokerSslOptions: BrokerRpcSslOptions?, useSslForBroker: Boolean, clientSslOptions: ClientRpcSslOptions?, address: NetworkHostAndPort = ports.nextHostAndPort(),
|
||||||
|
@ -3,10 +3,10 @@ package net.corda.irs.web
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import net.corda.client.jackson.JacksonSupport
|
import net.corda.client.jackson.JacksonSupport
|
||||||
import net.corda.client.rpc.CordaRPCClient
|
import net.corda.client.rpc.CordaRPCClient
|
||||||
|
import net.corda.client.rpc.RPCException
|
||||||
import net.corda.core.messaging.CordaRPCOps
|
import net.corda.core.messaging.CordaRPCOps
|
||||||
import net.corda.core.utilities.NetworkHostAndPort
|
import net.corda.core.utilities.NetworkHostAndPort
|
||||||
import net.corda.finance.plugin.registerFinanceJSONMappers
|
import net.corda.finance.plugin.registerFinanceJSONMappers
|
||||||
import org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException
|
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.beans.factory.annotation.Value
|
import org.springframework.beans.factory.annotation.Value
|
||||||
@ -39,7 +39,7 @@ class IrsDemoWebApplication {
|
|||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
return CordaRPCClient(NetworkHostAndPort.parse(cordaHost)).start(cordaUser, cordaPassword).proxy
|
return CordaRPCClient(NetworkHostAndPort.parse(cordaHost)).start(cordaUser, cordaPassword).proxy
|
||||||
} catch (ex: ActiveMQNotConnectedException) {
|
} catch (ex: RPCException) {
|
||||||
if (maxRetries-- > 0) {
|
if (maxRetries-- > 0) {
|
||||||
Thread.sleep(1000)
|
Thread.sleep(1000)
|
||||||
} else {
|
} else {
|
||||||
|
@ -3,6 +3,7 @@ package net.corda.tools.shell
|
|||||||
import com.google.common.io.Files
|
import com.google.common.io.Files
|
||||||
import com.jcraft.jsch.ChannelExec
|
import com.jcraft.jsch.ChannelExec
|
||||||
import com.jcraft.jsch.JSch
|
import com.jcraft.jsch.JSch
|
||||||
|
import net.corda.client.rpc.RPCException
|
||||||
import net.corda.core.internal.div
|
import net.corda.core.internal.div
|
||||||
import net.corda.core.messaging.CordaRPCOps
|
import net.corda.core.messaging.CordaRPCOps
|
||||||
import net.corda.core.utilities.getOrThrow
|
import net.corda.core.utilities.getOrThrow
|
||||||
@ -21,7 +22,6 @@ import net.corda.testing.internal.saveToKeyStore
|
|||||||
import net.corda.testing.internal.saveToTrustStore
|
import net.corda.testing.internal.saveToTrustStore
|
||||||
import net.corda.testing.internal.useSslRpcOverrides
|
import net.corda.testing.internal.useSslRpcOverrides
|
||||||
import net.corda.testing.node.User
|
import net.corda.testing.node.User
|
||||||
import org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException
|
|
||||||
import org.apache.activemq.artemis.api.core.ActiveMQSecurityException
|
import org.apache.activemq.artemis.api.core.ActiveMQSecurityException
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||||
@ -120,7 +120,7 @@ class InteractiveShellIntegrationTest {
|
|||||||
|
|
||||||
InteractiveShell.startShell(conf)
|
InteractiveShell.startShell(conf)
|
||||||
|
|
||||||
assertThatThrownBy { InteractiveShell.nodeInfo() }.isInstanceOf(ActiveMQNotConnectedException::class.java)
|
assertThatThrownBy { InteractiveShell.nodeInfo() }.isInstanceOf(RPCException::class.java)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package net.corda.webserver.internal
|
|||||||
import com.google.common.html.HtmlEscapers.htmlEscaper
|
import com.google.common.html.HtmlEscapers.htmlEscaper
|
||||||
import net.corda.client.jackson.JacksonSupport
|
import net.corda.client.jackson.JacksonSupport
|
||||||
import net.corda.client.rpc.CordaRPCClient
|
import net.corda.client.rpc.CordaRPCClient
|
||||||
|
import net.corda.client.rpc.RPCException
|
||||||
import net.corda.core.messaging.CordaRPCOps
|
import net.corda.core.messaging.CordaRPCOps
|
||||||
import net.corda.core.utilities.contextLogger
|
import net.corda.core.utilities.contextLogger
|
||||||
import net.corda.webserver.WebServerConfig
|
import net.corda.webserver.WebServerConfig
|
||||||
@ -13,7 +14,6 @@ import net.corda.webserver.servlets.CorDappInfoServlet
|
|||||||
import net.corda.webserver.servlets.DataUploadServlet
|
import net.corda.webserver.servlets.DataUploadServlet
|
||||||
import net.corda.webserver.servlets.ObjectMapperConfig
|
import net.corda.webserver.servlets.ObjectMapperConfig
|
||||||
import net.corda.webserver.servlets.ResponseFilter
|
import net.corda.webserver.servlets.ResponseFilter
|
||||||
import org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException
|
|
||||||
import org.eclipse.jetty.server.Connector
|
import org.eclipse.jetty.server.Connector
|
||||||
import org.eclipse.jetty.server.HttpConfiguration
|
import org.eclipse.jetty.server.HttpConfiguration
|
||||||
import org.eclipse.jetty.server.HttpConnectionFactory
|
import org.eclipse.jetty.server.HttpConnectionFactory
|
||||||
@ -178,7 +178,7 @@ class NodeWebServer(val config: WebServerConfig) {
|
|||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
return connectLocalRpcAsNodeUser()
|
return connectLocalRpcAsNodeUser()
|
||||||
} catch (e: ActiveMQNotConnectedException) {
|
} catch (e: RPCException) {
|
||||||
log.debug("Could not connect to ${config.rpcAddress} due to exception: ", e)
|
log.debug("Could not connect to ${config.rpcAddress} due to exception: ", e)
|
||||||
Thread.sleep(retryDelay)
|
Thread.sleep(retryDelay)
|
||||||
// This error will happen if the server has yet to create the keystore
|
// This error will happen if the server has yet to create the keystore
|
||||||
|
Reference in New Issue
Block a user