diff --git a/.ci/api-current.txt b/.ci/api-current.txt index 6652183c39..e0280f9d4f 100644 --- a/.ci/api-current.txt +++ b/.ci/api-current.txt @@ -6568,10 +6568,6 @@ public final class net.corda.client.rpc.CordaRPCClient extends java.lang.Object public static final net.corda.client.rpc.CordaRPCClient$Companion Companion ## public static final class net.corda.client.rpc.CordaRPCClient$Companion extends java.lang.Object - @NotNull - public final net.corda.client.rpc.CordaRPCClient createWithSsl(java.util.List, net.corda.core.messaging.ClientRpcSslOptions, net.corda.client.rpc.CordaRPCClientConfiguration) - @NotNull - public final net.corda.client.rpc.CordaRPCClient createWithSsl(net.corda.core.utilities.NetworkHostAndPort, net.corda.core.messaging.ClientRpcSslOptions, net.corda.client.rpc.CordaRPCClientConfiguration) ## public class net.corda.client.rpc.CordaRPCClientConfiguration extends java.lang.Object public (java.time.Duration) diff --git a/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/CordaRPCClientTest.kt b/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/CordaRPCClientTest.kt index cc031f4f83..6763abb814 100644 --- a/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/CordaRPCClientTest.kt +++ b/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/CordaRPCClientTest.kt @@ -1,6 +1,5 @@ package net.corda.client.rpc -import net.corda.client.rpc.internal.createCordaRPCClientWithSslAndClassLoader import net.corda.core.context.* import net.corda.core.contracts.FungibleAsset import net.corda.core.crypto.random63BitValue @@ -269,7 +268,7 @@ class CordaRPCClientTest : NodeBasedTest(listOf("net.corda.finance"), notaries = val address = NetworkHostAndPort.parse(args[0]) val financeClassLoader = URLClassLoader(arrayOf(Paths.get(args[1]).toUri().toURL())) val rpcUser = CordaRPCClientTest.rpcUser - val client = createCordaRPCClientWithSslAndClassLoader(address, classLoader = financeClassLoader) + val client = CordaRPCClient(address, classLoader = financeClassLoader) val state = client.use(rpcUser.username, rpcUser.password) { // financeClassLoader should be allowing the Cash.State to materialise @Suppress("DEPRECATION") diff --git a/client/rpc/src/main/kotlin/net/corda/client/rpc/CordaRPCClient.kt b/client/rpc/src/main/kotlin/net/corda/client/rpc/CordaRPCClient.kt index 196fcdbb98..0abedf5445 100644 --- a/client/rpc/src/main/kotlin/net/corda/client/rpc/CordaRPCClient.kt +++ b/client/rpc/src/main/kotlin/net/corda/client/rpc/CordaRPCClient.kt @@ -23,6 +23,7 @@ import net.corda.serialization.internal.amqp.SerializationFactoryCacheKey import net.corda.serialization.internal.amqp.SerializerFactory import java.time.Duration import java.util.ServiceLoader +import java.net.URLClassLoader /** * This class is essentially just a wrapper for an RPCConnection and can be treated identically. @@ -251,11 +252,11 @@ open class CordaRPCClientConfiguration @JvmOverloads constructor( * a classloader will need to be provided that contains the associated CorDapp jars. */ class CordaRPCClient private constructor( - private val hostAndPort: NetworkHostAndPort, + private val hostAndPort: NetworkHostAndPort?, + private val haAddressPool: List, private val configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT, private val sslConfiguration: ClientRpcSslOptions? = null, - private val classLoader: ClassLoader? = null, - private val haAddressPool: List = emptyList() + private val classLoader: ClassLoader? = null ) { @JvmOverloads @@ -273,41 +274,24 @@ class CordaRPCClient private constructor( classLoader: ClassLoader? = null ) : this(hostAndPort = hostAndPort, haAddressPool = emptyList(), sslConfiguration = sslConfiguration, classLoader = classLoader) - /** - * @param haAddressPool A list of [NetworkHostAndPort] representing the addresses of servers in HA mode. - * The client will attempt to connect to a live server by trying each address in the list. If the servers are not in - * HA mode, the client will round-robin from the beginning of the list and try all servers. - * @param configuration An optional configuration used to tweak client behaviour. - */ @JvmOverloads - constructor(haAddressPool: List, configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT) : this(haAddressPool.first(), configuration, null, null, haAddressPool) + constructor( + hostAndPort: NetworkHostAndPort, + configuration: CordaRPCClientConfiguration, + sslConfiguration: ClientRpcSslOptions?, + classLoader: ClassLoader? = null + ) : this(hostAndPort = hostAndPort, haAddressPool = emptyList(), configuration = configuration, sslConfiguration = sslConfiguration, classLoader = classLoader) - companion object { - fun createWithSsl( - hostAndPort: NetworkHostAndPort, - sslConfiguration: ClientRpcSslOptions, - configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT - ): CordaRPCClient { - return CordaRPCClient(hostAndPort, configuration, sslConfiguration) - } + @JvmOverloads + constructor( + haAddressPool: List, + configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT, + sslConfiguration: ClientRpcSslOptions? = null, + classLoader: ClassLoader? = null + ) : this(hostAndPort = null, haAddressPool = haAddressPool, configuration = configuration, sslConfiguration = sslConfiguration, classLoader = classLoader) - fun createWithSsl( - haAddressPool: List, - sslConfiguration: ClientRpcSslOptions, - configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT - ): CordaRPCClient { - return CordaRPCClient(haAddressPool.first(), configuration, sslConfiguration, haAddressPool = haAddressPool) - } - - internal fun createWithSslAndClassLoader( - hostAndPort: NetworkHostAndPort, - configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT, - sslConfiguration: ClientRpcSslOptions? = null, - classLoader: ClassLoader? = null - ): CordaRPCClient { - return CordaRPCClient(hostAndPort, configuration, sslConfiguration, classLoader = classLoader) - } - } + // Here to keep the keep ABI compatibility happy + companion object {} init { try { @@ -334,7 +318,7 @@ class CordaRPCClient private constructor( return when { // Client->RPC broker haAddressPool.isEmpty() -> RPCClient( - rpcConnectorTcpTransport(hostAndPort, config = sslConfiguration), + rpcConnectorTcpTransport(hostAndPort!!, config = sslConfiguration), configuration, if (classLoader != null) AMQP_RPC_CLIENT_CONTEXT.withClassLoader(classLoader) else AMQP_RPC_CLIENT_CONTEXT) else -> { diff --git a/client/rpc/src/main/kotlin/net/corda/client/rpc/internal/CordaRPCClientUtils.kt b/client/rpc/src/main/kotlin/net/corda/client/rpc/internal/CordaRPCClientUtils.kt deleted file mode 100644 index 86a74d1728..0000000000 --- a/client/rpc/src/main/kotlin/net/corda/client/rpc/internal/CordaRPCClientUtils.kt +++ /dev/null @@ -1,14 +0,0 @@ -package net.corda.client.rpc.internal - -import net.corda.client.rpc.CordaRPCClient -import net.corda.client.rpc.CordaRPCClientConfiguration -import net.corda.core.utilities.NetworkHostAndPort -import net.corda.core.messaging.ClientRpcSslOptions - -/** Utility which exposes the internal Corda RPC constructor to other internal Corda components */ -fun createCordaRPCClientWithSslAndClassLoader( - hostAndPort: NetworkHostAndPort, - configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT, - sslConfiguration: ClientRpcSslOptions? = null, - classLoader: ClassLoader? = null -) = CordaRPCClient.createWithSslAndClassLoader(hostAndPort, configuration, sslConfiguration, classLoader) \ No newline at end of file diff --git a/docs/source/clientrpc.rst b/docs/source/clientrpc.rst index 8e511b4c7c..f2f8bdd7bb 100644 --- a/docs/source/clientrpc.rst +++ b/docs/source/clientrpc.rst @@ -440,8 +440,6 @@ Wire security ``CordaRPCClient`` has an optional constructor parameter of type ``ClientRpcSslOptions``, defaulted to ``null``, which allows communication with the node using SSL. Default ``null`` value means no SSL used in the context of RPC. -To use this feature, the ``CordaRPCClient`` object provides a static factory method ``createWithSsl``. - In order for this to work, the client needs to provide a truststore containing a certificate received from the node admin. (The Node does not expect the RPC client to present a certificate, as the client already authenticates using the mechanism described above.) diff --git a/node/src/integration-test/kotlin/net/corda/node/services/rpc/RpcSslTest.kt b/node/src/integration-test/kotlin/net/corda/node/services/rpc/RpcSslTest.kt index 1b141bfa2d..1ee908e307 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/rpc/RpcSslTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/rpc/RpcSslTest.kt @@ -47,7 +47,7 @@ class RpcSslTest { driver(DriverParameters(startNodesInProcess = true, notarySpecs = emptyList())) { val node = startNode(rpcUsers = listOf(user), customOverrides = brokerSslOptions.useSslRpcOverrides()).getOrThrow() - val client = CordaRPCClient.createWithSsl(node.rpcAddress, sslConfiguration = clientSslOptions) + val client = CordaRPCClient(node.rpcAddress, sslConfiguration = clientSslOptions) val connection = client.start(user.username, user.password) connection.proxy.apply { @@ -58,7 +58,7 @@ class RpcSslTest { connection.close() Assertions.assertThatThrownBy { - val connection2 = CordaRPCClient.createWithSsl(node.rpcAddress, sslConfiguration = clientSslOptions).start(user.username, "wrong") + val connection2 = CordaRPCClient(node.rpcAddress, sslConfiguration = clientSslOptions).start(user.username, "wrong") connection2.proxy.apply { nodeInfo() failedLogin = true @@ -86,7 +86,7 @@ class RpcSslTest { driver(DriverParameters(startNodesInProcess = true, notarySpecs = emptyList())) { val node = startNode(rpcUsers = listOf(user), customOverrides = brokerSslOptions.useSslRpcOverrides()).getOrThrow() Assertions.assertThatThrownBy { - val connection = CordaRPCClient.createWithSsl(node.rpcAddress, sslConfiguration = clientSslOptions).start(user.username, user.password) + val connection = CordaRPCClient(node.rpcAddress, sslConfiguration = clientSslOptions).start(user.username, user.password) connection.proxy.apply { nodeInfo() successful = true @@ -125,7 +125,7 @@ class RpcSslTest { driver(DriverParameters(startNodesInProcess = true, notarySpecs = emptyList())) { val node = startNode(customOverrides = brokerSslOptions.useSslRpcOverrides()).getOrThrow() - val client = CordaRPCClient.createWithSsl(node.rpcAddress, sslConfiguration = clientSslOptions) + val client = CordaRPCClient(node.rpcAddress, sslConfiguration = clientSslOptions) Assertions.assertThatThrownBy { client.start(NODE_RPC_USER, NODE_RPC_USER).use { connection -> @@ -133,7 +133,7 @@ class RpcSslTest { } }.isInstanceOf(ActiveMQException::class.java) - val clientAdmin = CordaRPCClient.createWithSsl(node.rpcAdminAddress, sslConfiguration = clientSslOptions) + val clientAdmin = CordaRPCClient(node.rpcAdminAddress, sslConfiguration = clientSslOptions) Assertions.assertThatThrownBy { clientAdmin.start(NODE_RPC_USER, NODE_RPC_USER).use { connection -> diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt index c39bc14594..6b6f9c0e57 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt @@ -5,7 +5,8 @@ import com.typesafe.config.Config import com.typesafe.config.ConfigFactory import com.typesafe.config.ConfigRenderOptions import com.typesafe.config.ConfigValueFactory -import net.corda.client.rpc.internal.createCordaRPCClientWithSslAndClassLoader +import net.corda.client.rpc.CordaRPCClient +import net.corda.client.rpc.CordaRPCClientConfiguration import net.corda.cliutils.CommonCliConstants.BASE_DIR import net.corda.core.concurrent.CordaFuture import net.corda.core.concurrent.firstOf @@ -164,7 +165,7 @@ class DriverDSLImpl( private fun establishRpc(config: NodeConfig, processDeathFuture: CordaFuture): CordaFuture { val rpcAddress = config.corda.rpcOptions.address val clientRpcSslOptions = clientSslOptionsCompatibleWith(config.corda.rpcOptions) - val client = createCordaRPCClientWithSslAndClassLoader(rpcAddress, sslConfiguration = clientRpcSslOptions) + val client = CordaRPCClient(rpcAddress, sslConfiguration = clientRpcSslOptions) val connectionFuture = poll(executorService, "RPC connection") { try { config.corda.rpcUsers[0].run { client.start(username, password) } diff --git a/tools/shell/src/main/kotlin/net/corda/tools/shell/InteractiveShell.kt b/tools/shell/src/main/kotlin/net/corda/tools/shell/InteractiveShell.kt index d7bce425a6..94868f2a68 100644 --- a/tools/shell/src/main/kotlin/net/corda/tools/shell/InteractiveShell.kt +++ b/tools/shell/src/main/kotlin/net/corda/tools/shell/InteractiveShell.kt @@ -8,10 +8,10 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator import net.corda.client.jackson.JacksonSupport import net.corda.client.jackson.StringToMethodCallParser +import net.corda.client.rpc.CordaRPCClient import net.corda.client.rpc.CordaRPCClientConfiguration import net.corda.client.rpc.CordaRPCConnection import net.corda.client.rpc.PermissionException -import net.corda.client.rpc.internal.createCordaRPCClientWithSslAndClassLoader import net.corda.core.CordaException import net.corda.core.concurrent.CordaFuture import net.corda.core.contracts.UniqueIdentifier @@ -95,7 +95,7 @@ object InteractiveShell { */ fun startShell(configuration: ShellConfiguration, classLoader: ClassLoader? = null) { rpcOps = { username: String, credentials: String -> - val client = createCordaRPCClientWithSslAndClassLoader(hostAndPort = configuration.hostAndPort, + val client = CordaRPCClient(hostAndPort = configuration.hostAndPort, configuration = CordaRPCClientConfiguration.DEFAULT.copy( maxReconnectAttempts = 1 ), diff --git a/webserver/src/main/kotlin/net/corda/webserver/internal/NodeWebServer.kt b/webserver/src/main/kotlin/net/corda/webserver/internal/NodeWebServer.kt index 7615a4af5a..3f8a96b1db 100644 --- a/webserver/src/main/kotlin/net/corda/webserver/internal/NodeWebServer.kt +++ b/webserver/src/main/kotlin/net/corda/webserver/internal/NodeWebServer.kt @@ -199,7 +199,7 @@ class NodeWebServer(val config: WebServerConfig) { private fun connectLocalRpcAsNodeUser(): CordaRPCOps { log.info("Connecting to node at ${config.rpcAddress} as ${config.runAs}") - val client = CordaRPCClient(config.rpcAddress, classLoader = javaClass.classLoader) + val client = CordaRPCClient(hostAndPort = config.rpcAddress, classLoader = javaClass.classLoader) val connection = client.start(config.runAs.username, config.runAs.password) return connection.proxy }