mirror of
https://github.com/corda/corda.git
synced 2024-12-25 07:31:10 +00:00
CORDA-2434 - CordaRPCClient now only has c'tors rather a mix of c'tors and factory methods (#4569) (#4578)
(cherry picked from commit 24a7821dce
)
This commit is contained in:
parent
6bced399d7
commit
3b1929371c
@ -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 net.corda.client.rpc.CordaRPCClient$Companion Companion
|
||||||
##
|
##
|
||||||
public static final class net.corda.client.rpc.CordaRPCClient$Companion extends java.lang.Object
|
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.utilities.NetworkHostAndPort>, 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 class net.corda.client.rpc.CordaRPCClientConfiguration extends java.lang.Object
|
||||||
public <init>(java.time.Duration)
|
public <init>(java.time.Duration)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.corda.client.rpc
|
package net.corda.client.rpc
|
||||||
|
|
||||||
import net.corda.client.rpc.internal.createCordaRPCClientWithSslAndClassLoader
|
|
||||||
import net.corda.core.context.*
|
import net.corda.core.context.*
|
||||||
import net.corda.core.contracts.FungibleAsset
|
import net.corda.core.contracts.FungibleAsset
|
||||||
import net.corda.core.crypto.random63BitValue
|
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 address = NetworkHostAndPort.parse(args[0])
|
||||||
val financeClassLoader = URLClassLoader(arrayOf(Paths.get(args[1]).toUri().toURL()))
|
val financeClassLoader = URLClassLoader(arrayOf(Paths.get(args[1]).toUri().toURL()))
|
||||||
val rpcUser = CordaRPCClientTest.rpcUser
|
val rpcUser = CordaRPCClientTest.rpcUser
|
||||||
val client = createCordaRPCClientWithSslAndClassLoader(address, classLoader = financeClassLoader)
|
val client = CordaRPCClient(address, classLoader = financeClassLoader)
|
||||||
val state = client.use(rpcUser.username, rpcUser.password) {
|
val state = client.use(rpcUser.username, rpcUser.password) {
|
||||||
// financeClassLoader should be allowing the Cash.State to materialise
|
// financeClassLoader should be allowing the Cash.State to materialise
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
|
@ -23,6 +23,7 @@ import net.corda.serialization.internal.amqp.SerializationFactoryCacheKey
|
|||||||
import net.corda.serialization.internal.amqp.SerializerFactory
|
import net.corda.serialization.internal.amqp.SerializerFactory
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.util.ServiceLoader
|
import java.util.ServiceLoader
|
||||||
|
import java.net.URLClassLoader
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is essentially just a wrapper for an RPCConnection<CordaRPCOps> and can be treated identically.
|
* This class is essentially just a wrapper for an RPCConnection<CordaRPCOps> 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.
|
* a classloader will need to be provided that contains the associated CorDapp jars.
|
||||||
*/
|
*/
|
||||||
class CordaRPCClient private constructor(
|
class CordaRPCClient private constructor(
|
||||||
private val hostAndPort: NetworkHostAndPort,
|
private val hostAndPort: NetworkHostAndPort?,
|
||||||
|
private val haAddressPool: List<NetworkHostAndPort>,
|
||||||
private val configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT,
|
private val configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT,
|
||||||
private val sslConfiguration: ClientRpcSslOptions? = null,
|
private val sslConfiguration: ClientRpcSslOptions? = null,
|
||||||
private val classLoader: ClassLoader? = null,
|
private val classLoader: ClassLoader? = null
|
||||||
private val haAddressPool: List<NetworkHostAndPort> = emptyList()
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
@ -273,41 +274,24 @@ class CordaRPCClient private constructor(
|
|||||||
classLoader: ClassLoader? = null
|
classLoader: ClassLoader? = null
|
||||||
) : this(hostAndPort = hostAndPort, haAddressPool = emptyList(), sslConfiguration = sslConfiguration, classLoader = classLoader)
|
) : 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
|
@JvmOverloads
|
||||||
constructor(haAddressPool: List<NetworkHostAndPort>, configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT) : this(haAddressPool.first(), configuration, null, null, haAddressPool)
|
constructor(
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun createWithSsl(
|
|
||||||
hostAndPort: NetworkHostAndPort,
|
hostAndPort: NetworkHostAndPort,
|
||||||
sslConfiguration: ClientRpcSslOptions,
|
configuration: CordaRPCClientConfiguration,
|
||||||
configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT
|
sslConfiguration: ClientRpcSslOptions?,
|
||||||
): CordaRPCClient {
|
classLoader: ClassLoader? = null
|
||||||
return CordaRPCClient(hostAndPort, configuration, sslConfiguration)
|
) : this(hostAndPort = hostAndPort, haAddressPool = emptyList(), configuration = configuration, sslConfiguration = sslConfiguration, classLoader = classLoader)
|
||||||
}
|
|
||||||
|
|
||||||
fun createWithSsl(
|
@JvmOverloads
|
||||||
|
constructor(
|
||||||
haAddressPool: List<NetworkHostAndPort>,
|
haAddressPool: List<NetworkHostAndPort>,
|
||||||
sslConfiguration: ClientRpcSslOptions,
|
|
||||||
configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT
|
|
||||||
): CordaRPCClient {
|
|
||||||
return CordaRPCClient(haAddressPool.first(), configuration, sslConfiguration, haAddressPool = haAddressPool)
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun createWithSslAndClassLoader(
|
|
||||||
hostAndPort: NetworkHostAndPort,
|
|
||||||
configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT,
|
configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT,
|
||||||
sslConfiguration: ClientRpcSslOptions? = null,
|
sslConfiguration: ClientRpcSslOptions? = null,
|
||||||
classLoader: ClassLoader? = null
|
classLoader: ClassLoader? = null
|
||||||
): CordaRPCClient {
|
) : this(hostAndPort = null, haAddressPool = haAddressPool, configuration = configuration, sslConfiguration = sslConfiguration, classLoader = classLoader)
|
||||||
return CordaRPCClient(hostAndPort, configuration, sslConfiguration, classLoader = classLoader)
|
|
||||||
}
|
// Here to keep the keep ABI compatibility happy
|
||||||
}
|
companion object {}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
try {
|
try {
|
||||||
@ -334,7 +318,7 @@ class CordaRPCClient private constructor(
|
|||||||
return when {
|
return when {
|
||||||
// Client->RPC broker
|
// Client->RPC broker
|
||||||
haAddressPool.isEmpty() -> RPCClient(
|
haAddressPool.isEmpty() -> RPCClient(
|
||||||
rpcConnectorTcpTransport(hostAndPort, config = sslConfiguration),
|
rpcConnectorTcpTransport(hostAndPort!!, config = sslConfiguration),
|
||||||
configuration,
|
configuration,
|
||||||
if (classLoader != null) AMQP_RPC_CLIENT_CONTEXT.withClassLoader(classLoader) else AMQP_RPC_CLIENT_CONTEXT)
|
if (classLoader != null) AMQP_RPC_CLIENT_CONTEXT.withClassLoader(classLoader) else AMQP_RPC_CLIENT_CONTEXT)
|
||||||
else -> {
|
else -> {
|
||||||
|
@ -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)
|
|
@ -440,8 +440,6 @@ Wire security
|
|||||||
``CordaRPCClient`` has an optional constructor parameter of type ``ClientRpcSslOptions``, defaulted to ``null``, which allows
|
``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.
|
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.
|
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.)
|
(The Node does not expect the RPC client to present a certificate, as the client already authenticates using the mechanism described above.)
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class RpcSslTest {
|
|||||||
|
|
||||||
driver(DriverParameters(startNodesInProcess = true, notarySpecs = emptyList())) {
|
driver(DriverParameters(startNodesInProcess = true, notarySpecs = emptyList())) {
|
||||||
val node = startNode(rpcUsers = listOf(user), customOverrides = brokerSslOptions.useSslRpcOverrides()).getOrThrow()
|
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)
|
val connection = client.start(user.username, user.password)
|
||||||
|
|
||||||
connection.proxy.apply {
|
connection.proxy.apply {
|
||||||
@ -58,7 +58,7 @@ class RpcSslTest {
|
|||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
Assertions.assertThatThrownBy {
|
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 {
|
connection2.proxy.apply {
|
||||||
nodeInfo()
|
nodeInfo()
|
||||||
failedLogin = true
|
failedLogin = true
|
||||||
@ -86,7 +86,7 @@ class RpcSslTest {
|
|||||||
driver(DriverParameters(startNodesInProcess = true, notarySpecs = emptyList())) {
|
driver(DriverParameters(startNodesInProcess = true, notarySpecs = emptyList())) {
|
||||||
val node = startNode(rpcUsers = listOf(user), customOverrides = brokerSslOptions.useSslRpcOverrides()).getOrThrow()
|
val node = startNode(rpcUsers = listOf(user), customOverrides = brokerSslOptions.useSslRpcOverrides()).getOrThrow()
|
||||||
Assertions.assertThatThrownBy {
|
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 {
|
connection.proxy.apply {
|
||||||
nodeInfo()
|
nodeInfo()
|
||||||
successful = true
|
successful = true
|
||||||
@ -125,7 +125,7 @@ class RpcSslTest {
|
|||||||
|
|
||||||
driver(DriverParameters(startNodesInProcess = true, notarySpecs = emptyList())) {
|
driver(DriverParameters(startNodesInProcess = true, notarySpecs = emptyList())) {
|
||||||
val node = startNode(customOverrides = brokerSslOptions.useSslRpcOverrides()).getOrThrow()
|
val node = startNode(customOverrides = brokerSslOptions.useSslRpcOverrides()).getOrThrow()
|
||||||
val client = CordaRPCClient.createWithSsl(node.rpcAddress, sslConfiguration = clientSslOptions)
|
val client = CordaRPCClient(node.rpcAddress, sslConfiguration = clientSslOptions)
|
||||||
|
|
||||||
Assertions.assertThatThrownBy {
|
Assertions.assertThatThrownBy {
|
||||||
client.start(NODE_RPC_USER, NODE_RPC_USER).use { connection ->
|
client.start(NODE_RPC_USER, NODE_RPC_USER).use { connection ->
|
||||||
@ -133,7 +133,7 @@ class RpcSslTest {
|
|||||||
}
|
}
|
||||||
}.isInstanceOf(ActiveMQException::class.java)
|
}.isInstanceOf(ActiveMQException::class.java)
|
||||||
|
|
||||||
val clientAdmin = CordaRPCClient.createWithSsl(node.rpcAdminAddress, sslConfiguration = clientSslOptions)
|
val clientAdmin = CordaRPCClient(node.rpcAdminAddress, sslConfiguration = clientSslOptions)
|
||||||
|
|
||||||
Assertions.assertThatThrownBy {
|
Assertions.assertThatThrownBy {
|
||||||
clientAdmin.start(NODE_RPC_USER, NODE_RPC_USER).use { connection ->
|
clientAdmin.start(NODE_RPC_USER, NODE_RPC_USER).use { connection ->
|
||||||
|
@ -5,7 +5,8 @@ import com.typesafe.config.Config
|
|||||||
import com.typesafe.config.ConfigFactory
|
import com.typesafe.config.ConfigFactory
|
||||||
import com.typesafe.config.ConfigRenderOptions
|
import com.typesafe.config.ConfigRenderOptions
|
||||||
import com.typesafe.config.ConfigValueFactory
|
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.cliutils.CommonCliConstants.BASE_DIR
|
||||||
import net.corda.core.concurrent.CordaFuture
|
import net.corda.core.concurrent.CordaFuture
|
||||||
import net.corda.core.concurrent.firstOf
|
import net.corda.core.concurrent.firstOf
|
||||||
@ -164,7 +165,7 @@ class DriverDSLImpl(
|
|||||||
private fun establishRpc(config: NodeConfig, processDeathFuture: CordaFuture<out Process>): CordaFuture<CordaRPCOps> {
|
private fun establishRpc(config: NodeConfig, processDeathFuture: CordaFuture<out Process>): CordaFuture<CordaRPCOps> {
|
||||||
val rpcAddress = config.corda.rpcOptions.address
|
val rpcAddress = config.corda.rpcOptions.address
|
||||||
val clientRpcSslOptions = clientSslOptionsCompatibleWith(config.corda.rpcOptions)
|
val clientRpcSslOptions = clientSslOptionsCompatibleWith(config.corda.rpcOptions)
|
||||||
val client = createCordaRPCClientWithSslAndClassLoader(rpcAddress, sslConfiguration = clientRpcSslOptions)
|
val client = CordaRPCClient(rpcAddress, sslConfiguration = clientRpcSslOptions)
|
||||||
val connectionFuture = poll(executorService, "RPC connection") {
|
val connectionFuture = poll(executorService, "RPC connection") {
|
||||||
try {
|
try {
|
||||||
config.corda.rpcUsers[0].run { client.start(username, password) }
|
config.corda.rpcUsers[0].run { client.start(username, password) }
|
||||||
|
@ -8,10 +8,10 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
|
|||||||
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator
|
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator
|
||||||
import net.corda.client.jackson.JacksonSupport
|
import net.corda.client.jackson.JacksonSupport
|
||||||
import net.corda.client.jackson.StringToMethodCallParser
|
import net.corda.client.jackson.StringToMethodCallParser
|
||||||
|
import net.corda.client.rpc.CordaRPCClient
|
||||||
import net.corda.client.rpc.CordaRPCClientConfiguration
|
import net.corda.client.rpc.CordaRPCClientConfiguration
|
||||||
import net.corda.client.rpc.CordaRPCConnection
|
import net.corda.client.rpc.CordaRPCConnection
|
||||||
import net.corda.client.rpc.PermissionException
|
import net.corda.client.rpc.PermissionException
|
||||||
import net.corda.client.rpc.internal.createCordaRPCClientWithSslAndClassLoader
|
|
||||||
import net.corda.core.CordaException
|
import net.corda.core.CordaException
|
||||||
import net.corda.core.concurrent.CordaFuture
|
import net.corda.core.concurrent.CordaFuture
|
||||||
import net.corda.core.contracts.UniqueIdentifier
|
import net.corda.core.contracts.UniqueIdentifier
|
||||||
@ -95,7 +95,7 @@ object InteractiveShell {
|
|||||||
*/
|
*/
|
||||||
fun startShell(configuration: ShellConfiguration, classLoader: ClassLoader? = null) {
|
fun startShell(configuration: ShellConfiguration, classLoader: ClassLoader? = null) {
|
||||||
rpcOps = { username: String, credentials: String ->
|
rpcOps = { username: String, credentials: String ->
|
||||||
val client = createCordaRPCClientWithSslAndClassLoader(hostAndPort = configuration.hostAndPort,
|
val client = CordaRPCClient(hostAndPort = configuration.hostAndPort,
|
||||||
configuration = CordaRPCClientConfiguration.DEFAULT.copy(
|
configuration = CordaRPCClientConfiguration.DEFAULT.copy(
|
||||||
maxReconnectAttempts = 1
|
maxReconnectAttempts = 1
|
||||||
),
|
),
|
||||||
|
@ -199,7 +199,7 @@ class NodeWebServer(val config: WebServerConfig) {
|
|||||||
|
|
||||||
private fun connectLocalRpcAsNodeUser(): CordaRPCOps {
|
private fun connectLocalRpcAsNodeUser(): CordaRPCOps {
|
||||||
log.info("Connecting to node at ${config.rpcAddress} as ${config.runAs}")
|
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)
|
val connection = client.start(config.runAs.username, config.runAs.password)
|
||||||
return connection.proxy
|
return connection.proxy
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user