mirror of
https://github.com/corda/corda.git
synced 2025-06-18 07:08:15 +00:00
ENT-5492: Don't do reconnect logic on illegal argument for attachments (#6693)
* ENT-5492: Don't do reconnect logic on illegal argument for attachments * Use a dedicated exception for missing attachments.
This commit is contained in:
@ -38,6 +38,7 @@ import net.corda.core.utilities.NetworkHostAndPort
|
|||||||
import net.corda.core.utilities.contextLogger
|
import net.corda.core.utilities.contextLogger
|
||||||
import net.corda.core.utilities.debug
|
import net.corda.core.utilities.debug
|
||||||
import net.corda.core.utilities.seconds
|
import net.corda.core.utilities.seconds
|
||||||
|
import net.corda.nodeapi.exceptions.MissingAttachmentException
|
||||||
import net.corda.nodeapi.exceptions.RejectedCommandException
|
import net.corda.nodeapi.exceptions.RejectedCommandException
|
||||||
import org.apache.activemq.artemis.api.core.ActiveMQConnectionTimedOutException
|
import org.apache.activemq.artemis.api.core.ActiveMQConnectionTimedOutException
|
||||||
import org.apache.activemq.artemis.api.core.ActiveMQSecurityException
|
import org.apache.activemq.artemis.api.core.ActiveMQSecurityException
|
||||||
@ -320,7 +321,7 @@ class ReconnectingCordaRPCOps private constructor(
|
|||||||
checkIfClosed()
|
checkIfClosed()
|
||||||
var remainingAttempts = maxNumberOfAttempts
|
var remainingAttempts = maxNumberOfAttempts
|
||||||
var lastException: Throwable? = null
|
var lastException: Throwable? = null
|
||||||
while (remainingAttempts != 0 && !reconnectingRPCConnection.isClosed()) {
|
loop@ while (remainingAttempts != 0 && !reconnectingRPCConnection.isClosed()) {
|
||||||
try {
|
try {
|
||||||
log.debug { "Invoking RPC $method..." }
|
log.debug { "Invoking RPC $method..." }
|
||||||
return method.invoke(reconnectingRPCConnection.proxy, *(args ?: emptyArray())).also {
|
return method.invoke(reconnectingRPCConnection.proxy, *(args ?: emptyArray())).also {
|
||||||
@ -353,6 +354,10 @@ class ReconnectingCordaRPCOps private constructor(
|
|||||||
is PermissionException -> {
|
is PermissionException -> {
|
||||||
throw RPCException("User does not have permission to perform operation ${method.name}.", e)
|
throw RPCException("User does not have permission to perform operation ${method.name}.", e)
|
||||||
}
|
}
|
||||||
|
is MissingAttachmentException -> {
|
||||||
|
log.warn("Failed to perform operation ${method.name}.", e)
|
||||||
|
break@loop
|
||||||
|
}
|
||||||
else -> {
|
else -> {
|
||||||
log.warn("Failed to perform operation ${method.name}.", e)
|
log.warn("Failed to perform operation ${method.name}.", e)
|
||||||
throw e.targetException
|
throw e.targetException
|
||||||
|
@ -35,6 +35,12 @@ class RejectedCommandException(message: String) :
|
|||||||
CordaRuntimeException(message),
|
CordaRuntimeException(message),
|
||||||
@Suppress("DEPRECATION") net.corda.core.ClientRelevantError
|
@Suppress("DEPRECATION") net.corda.core.ClientRelevantError
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrown to indicate that the command was rejected by the node, typically due to a special temporary mode.
|
||||||
|
*/
|
||||||
|
class MissingAttachmentException(message: String) :
|
||||||
|
CordaRuntimeException(message)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows an implementing [Throwable] to be propagated to RPC clients.
|
* Allows an implementing [Throwable] to be propagated to RPC clients.
|
||||||
*/
|
*/
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.corda.node.internal
|
package net.corda.node.internal
|
||||||
|
|
||||||
import net.corda.client.rpc.RPCException
|
|
||||||
import net.corda.client.rpc.notUsed
|
import net.corda.client.rpc.notUsed
|
||||||
import net.corda.common.logging.CordaVersion
|
import net.corda.common.logging.CordaVersion
|
||||||
import net.corda.core.CordaRuntimeException
|
import net.corda.core.CordaRuntimeException
|
||||||
@ -57,6 +56,7 @@ import net.corda.node.services.api.ServiceHubInternal
|
|||||||
import net.corda.node.services.rpc.CheckpointDumperImpl
|
import net.corda.node.services.rpc.CheckpointDumperImpl
|
||||||
import net.corda.node.services.rpc.context
|
import net.corda.node.services.rpc.context
|
||||||
import net.corda.node.services.statemachine.StateMachineManager
|
import net.corda.node.services.statemachine.StateMachineManager
|
||||||
|
import net.corda.nodeapi.exceptions.MissingAttachmentException
|
||||||
import net.corda.nodeapi.exceptions.NonRpcFlowException
|
import net.corda.nodeapi.exceptions.NonRpcFlowException
|
||||||
import net.corda.nodeapi.exceptions.RejectedCommandException
|
import net.corda.nodeapi.exceptions.RejectedCommandException
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
@ -288,7 +288,7 @@ internal class CordaRPCOpsImpl(
|
|||||||
|
|
||||||
override fun openAttachment(id: SecureHash): InputStream {
|
override fun openAttachment(id: SecureHash): InputStream {
|
||||||
return services.attachments.openAttachment(id)?.open() ?:
|
return services.attachments.openAttachment(id)?.open() ?:
|
||||||
throw RPCException("Unable to open attachment with id: $id")
|
throw MissingAttachmentException("Unable to open attachment with id: $id")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun uploadAttachment(jar: InputStream): SecureHash {
|
override fun uploadAttachment(jar: InputStream): SecureHash {
|
||||||
|
@ -2,7 +2,6 @@ package net.corda.node
|
|||||||
|
|
||||||
import co.paralleluniverse.fibers.Suspendable
|
import co.paralleluniverse.fibers.Suspendable
|
||||||
import net.corda.client.rpc.PermissionException
|
import net.corda.client.rpc.PermissionException
|
||||||
import net.corda.client.rpc.RPCException
|
|
||||||
import net.corda.core.context.AuthServiceId
|
import net.corda.core.context.AuthServiceId
|
||||||
import net.corda.core.context.InvocationContext
|
import net.corda.core.context.InvocationContext
|
||||||
import net.corda.core.contracts.Amount
|
import net.corda.core.contracts.Amount
|
||||||
@ -41,6 +40,7 @@ import net.corda.node.services.Permissions.Companion.invokeRpc
|
|||||||
import net.corda.node.services.Permissions.Companion.startFlow
|
import net.corda.node.services.Permissions.Companion.startFlow
|
||||||
import net.corda.node.services.rpc.CURRENT_RPC_CONTEXT
|
import net.corda.node.services.rpc.CURRENT_RPC_CONTEXT
|
||||||
import net.corda.node.services.rpc.RpcAuthContext
|
import net.corda.node.services.rpc.RpcAuthContext
|
||||||
|
import net.corda.nodeapi.exceptions.MissingAttachmentException
|
||||||
import net.corda.nodeapi.exceptions.NonRpcFlowException
|
import net.corda.nodeapi.exceptions.NonRpcFlowException
|
||||||
import net.corda.nodeapi.internal.config.User
|
import net.corda.nodeapi.internal.config.User
|
||||||
import net.corda.testing.core.ALICE_NAME
|
import net.corda.testing.core.ALICE_NAME
|
||||||
@ -361,7 +361,7 @@ class CordaRPCOpsImplTest {
|
|||||||
withPermissions(invokeRpc(CordaRPCOps::openAttachment)) {
|
withPermissions(invokeRpc(CordaRPCOps::openAttachment)) {
|
||||||
assertThatThrownBy {
|
assertThatThrownBy {
|
||||||
rpc.openAttachment(SecureHash.zeroHash)
|
rpc.openAttachment(SecureHash.zeroHash)
|
||||||
}.isInstanceOf(RPCException::class.java)
|
}.isInstanceOf(MissingAttachmentException::class.java)
|
||||||
.withFailMessage("Unable to open attachment with id: ${SecureHash.zeroHash}")
|
.withFailMessage("Unable to open attachment with id: ${SecureHash.zeroHash}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user