mirror of
https://github.com/corda/corda.git
synced 2025-02-20 09:26:41 +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:
parent
f0db76d854
commit
bff419e9af
@ -21,7 +21,6 @@ import net.corda.node.services.Permissions.Companion.all
|
||||
import net.corda.testing.core.*
|
||||
import net.corda.testing.node.User
|
||||
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.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatExceptionOfType
|
||||
@ -102,7 +101,7 @@ class CordaRPCClientTest : NodeBasedTest(listOf("net.corda.finance.contracts", C
|
||||
}
|
||||
count++
|
||||
}
|
||||
} catch (e: ActiveMQNotConnectedException) {
|
||||
} catch (e: RPCException) {
|
||||
println("... node is not running.")
|
||||
nodeIsShut.onCompleted()
|
||||
} catch (e: ActiveMQSecurityException) {
|
||||
|
@ -14,13 +14,13 @@ import net.corda.node.services.messaging.RPCServerConfiguration
|
||||
import net.corda.nodeapi.RPCApi
|
||||
import net.corda.nodeapi.eventually
|
||||
import net.corda.testing.core.SerializationEnvironmentRule
|
||||
import net.corda.testing.core.freePort
|
||||
import net.corda.testing.internal.testThreadFactory
|
||||
import net.corda.testing.node.internal.*
|
||||
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration
|
||||
import org.apache.activemq.artemis.api.core.SimpleString
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
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 {
|
||||
fun serverId(): String
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import net.corda.core.utilities.getOrThrow
|
||||
import net.corda.nodeapi.RPCApi
|
||||
import net.corda.nodeapi.internal.DeduplicationChecker
|
||||
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.SimpleString
|
||||
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.
|
||||
// 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.
|
||||
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
|
||||
if (serverLocator.staticTransportConfigurations.size == 1) {
|
||||
sessionFactory!!.addFailoverListener(this::failoverHandler)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.corda.node.services.rpc
|
||||
|
||||
import net.corda.client.rpc.CordaRPCClient
|
||||
import net.corda.client.rpc.RPCException
|
||||
import net.corda.core.internal.div
|
||||
import net.corda.core.utilities.getOrThrow
|
||||
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.node.User
|
||||
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.assertj.core.api.Assertions
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
@ -90,7 +90,7 @@ class RpcSslTest {
|
||||
successful = true
|
||||
}
|
||||
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 ->
|
||||
connection.proxy.nodeInfo()
|
||||
}
|
||||
}.isInstanceOf(ActiveMQException::class.java)
|
||||
}.isInstanceOf(RPCException::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.corda.node.services.rpc
|
||||
|
||||
import net.corda.client.rpc.RPCException
|
||||
import net.corda.client.rpc.internal.RPCClient
|
||||
import net.corda.core.context.AuthServiceId
|
||||
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.saveToTrustStore
|
||||
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.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||
@ -89,7 +89,7 @@ class ArtemisRpcTests {
|
||||
|
||||
assertThatThrownBy {
|
||||
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(),
|
||||
|
@ -3,10 +3,10 @@ package net.corda.irs.web
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import net.corda.client.jackson.JacksonSupport
|
||||
import net.corda.client.rpc.CordaRPCClient
|
||||
import net.corda.client.rpc.RPCException
|
||||
import net.corda.core.messaging.CordaRPCOps
|
||||
import net.corda.core.utilities.NetworkHostAndPort
|
||||
import net.corda.finance.plugin.registerFinanceJSONMappers
|
||||
import org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
@ -39,7 +39,7 @@ class IrsDemoWebApplication {
|
||||
do {
|
||||
try {
|
||||
return CordaRPCClient(NetworkHostAndPort.parse(cordaHost)).start(cordaUser, cordaPassword).proxy
|
||||
} catch (ex: ActiveMQNotConnectedException) {
|
||||
} catch (ex: RPCException) {
|
||||
if (maxRetries-- > 0) {
|
||||
Thread.sleep(1000)
|
||||
} else {
|
||||
|
@ -3,6 +3,7 @@ package net.corda.tools.shell
|
||||
import com.google.common.io.Files
|
||||
import com.jcraft.jsch.ChannelExec
|
||||
import com.jcraft.jsch.JSch
|
||||
import net.corda.client.rpc.RPCException
|
||||
import net.corda.core.internal.div
|
||||
import net.corda.core.messaging.CordaRPCOps
|
||||
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.useSslRpcOverrides
|
||||
import net.corda.testing.node.User
|
||||
import org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException
|
||||
import org.apache.activemq.artemis.api.core.ActiveMQSecurityException
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||
@ -120,7 +120,7 @@ class InteractiveShellIntegrationTest {
|
||||
|
||||
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 net.corda.client.jackson.JacksonSupport
|
||||
import net.corda.client.rpc.CordaRPCClient
|
||||
import net.corda.client.rpc.RPCException
|
||||
import net.corda.core.messaging.CordaRPCOps
|
||||
import net.corda.core.utilities.contextLogger
|
||||
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.ObjectMapperConfig
|
||||
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.HttpConfiguration
|
||||
import org.eclipse.jetty.server.HttpConnectionFactory
|
||||
@ -178,7 +178,7 @@ class NodeWebServer(val config: WebServerConfig) {
|
||||
while (true) {
|
||||
try {
|
||||
return connectLocalRpcAsNodeUser()
|
||||
} catch (e: ActiveMQNotConnectedException) {
|
||||
} catch (e: RPCException) {
|
||||
log.debug("Could not connect to ${config.rpcAddress} due to exception: ", e)
|
||||
Thread.sleep(retryDelay)
|
||||
// This error will happen if the server has yet to create the keystore
|
||||
|
Loading…
x
Reference in New Issue
Block a user