RPC: Report failures during deserialisation of method arguments to the client as an exception.

This commit is contained in:
Mike Hearn
2017-09-22 15:22:40 +02:00
committed by Mike Hearn
parent 4030903fee
commit 20a9892123
2 changed files with 47 additions and 10 deletions

View File

@ -128,15 +128,26 @@ object RPCApi {
}
companion object {
fun fromClientMessage(context: SerializationContext, message: ClientMessage): ClientToServer {
val tag = Tag.values()[message.getIntProperty(TAG_FIELD_NAME)]
return when (tag) {
RPCApi.ClientToServer.Tag.RPC_REQUEST -> RpcRequest(
clientAddress = MessageUtil.getJMSReplyTo(message),
id = RpcRequestId(message.getLongProperty(RPC_ID_FIELD_NAME)),
methodName = message.getStringProperty(METHOD_NAME_FIELD_NAME),
arguments = message.getBodyAsByteArray().deserialize(context = context)
)
RPCApi.ClientToServer.Tag.RPC_REQUEST -> {
val partialReq = RpcRequest(
clientAddress = MessageUtil.getJMSReplyTo(message),
id = RpcRequestId(message.getLongProperty(RPC_ID_FIELD_NAME)),
methodName = message.getStringProperty(METHOD_NAME_FIELD_NAME),
arguments = emptyList()
)
// Deserialisation of the arguments can fail, but we'd like to return a response mapped to
// this specific RPC, so we throw the partial request with ID and method name.
try {
val arguments = message.getBodyAsByteArray().deserialize<List<Any?>>(context = context)
return partialReq.copy(arguments = arguments)
} catch (t: Throwable) {
throw ArgumentDeserialisationException(t, partialReq)
}
}
RPCApi.ClientToServer.Tag.OBSERVABLES_CLOSED -> {
val ids = ArrayList<ObservableId>()
val buffer = message.bodyBuffer
@ -149,6 +160,7 @@ object RPCApi {
}
}
}
}
/**
@ -215,6 +227,13 @@ object RPCApi {
}
}
}
/**
* Thrown when the arguments passed to an RPC couldn't be deserialised by the server. This will
* typically indicate a missing application on the server side, or different versions between
* client and server.
*/
class ArgumentDeserialisationException(cause: Throwable, val reqWithNoArguments: ClientToServer.RpcRequest) : RPCException("Failed to deserialise RPC arguments: version or app skew between client and server?", cause)
}
data class ArtemisProducer(