From: Jens Geyer Date: Sat, 6 Jul 2013 07:29:19 +0000 (+0200) Subject: THRIFT-2080 C# multiplex processor does not catch IOException X-Git-Tag: 0.9.1~44 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=6b9e1c6a87d745c224f6737b07b3ed7d72fcd6e0;p=common%2Fthrift.git THRIFT-2080 C# multiplex processor does not catch IOException Patch: Jens Geyer --- diff --git a/lib/csharp/src/Protocol/TMultiplexedProcessor.cs b/lib/csharp/src/Protocol/TMultiplexedProcessor.cs index 29fac9e5..4ce8d62f 100644 --- a/lib/csharp/src/Protocol/TMultiplexedProcessor.cs +++ b/lib/csharp/src/Protocol/TMultiplexedProcessor.cs @@ -25,6 +25,7 @@ using System; using System.Text; using Thrift.Transport; using System.Collections.Generic; +using System.IO; namespace Thrift.Protocol { @@ -102,46 +103,56 @@ namespace Thrift.Protocol message header. This pulls the message "off the wire", which we'll deal with at the end of this method. */ - TMessage message = iprot.ReadMessageBegin(); - - if ((message.Type != TMessageType.Call) && (message.Type != TMessageType.Oneway)) + try { - Fail( oprot, message, - TApplicationException.ExceptionType.InvalidMessageType, - "Message type CALL or ONEWAY expected"); - return false; - } + TMessage message = iprot.ReadMessageBegin(); + + if ((message.Type != TMessageType.Call) && (message.Type != TMessageType.Oneway)) + { + Fail(oprot, message, + TApplicationException.ExceptionType.InvalidMessageType, + "Message type CALL or ONEWAY expected"); + return false; + } + + // Extract the service name + int index = message.Name.IndexOf(TMultiplexedProtocol.SEPARATOR); + if (index < 0) + { + Fail(oprot, message, + TApplicationException.ExceptionType.InvalidProtocol, + "Service name not found in message name: " + message.Name + ". " + + "Did you forget to use a TMultiplexProtocol in your client?"); + return false; + } + + // Create a new TMessage, something that can be consumed by any TProtocol + string serviceName = message.Name.Substring(0, index); + TProcessor actualProcessor; + if (!ServiceProcessorMap.TryGetValue(serviceName, out actualProcessor)) + { + Fail(oprot, message, + TApplicationException.ExceptionType.InternalError, + "Service name not found: " + serviceName + ". " + + "Did you forget to call RegisterProcessor()?"); + return false; + } + + // Create a new TMessage, removing the service name + TMessage newMessage = new TMessage( + message.Name.Substring(serviceName.Length + TMultiplexedProtocol.SEPARATOR.Length), + message.Type, + message.SeqID); + + // Dispatch processing to the stored processor + return actualProcessor.Process(new StoredMessageProtocol(iprot, newMessage), oprot); - // Extract the service name - int index = message.Name.IndexOf(TMultiplexedProtocol.SEPARATOR); - if (index < 0) { - Fail( oprot, message, - TApplicationException.ExceptionType.InvalidProtocol, - "Service name not found in message name: " + message.Name + ". "+ - "Did you forget to use a TMultiplexProtocol in your client?"); - return false; } - - // Create a new TMessage, something that can be consumed by any TProtocol - string serviceName = message.Name.Substring(0, index); - TProcessor actualProcessor; - if( ! ServiceProcessorMap.TryGetValue(serviceName, out actualProcessor)) + catch (IOException) { - Fail( oprot, message, - TApplicationException.ExceptionType.InternalError, - "Service name not found: " + serviceName + ". "+ - "Did you forget to call RegisterProcessor()?"); - return false; + return false; // similar to all other processors } - // Create a new TMessage, removing the service name - TMessage newMessage = new TMessage( - message.Name.Substring(serviceName.Length + TMultiplexedProtocol.SEPARATOR.Length), - message.Type, - message.SeqID); - - // Dispatch processing to the stored processor - return actualProcessor.Process(new StoredMessageProtocol(iprot, newMessage), oprot); } /**