/// <summary>
        /// Receives a <see cref="ReceivedTransportMessage"/> using the underlying implementation of <see cref="IReceiveMessages"/>
        /// decrypting the message body if necessary, and remove the additional encryption headers
        /// </summary>
        public ReceivedTransportMessage ReceiveMessage(ITransactionContext context)
        {
            var receivedTransportMessage = innerReceiveMessages.ReceiveMessage(context);

            if (receivedTransportMessage == null)
            {
                return(null);
            }

            byte[] body;
            var    headers = receivedTransportMessage.Headers.Clone();

            if (headers.ContainsKey(Headers.Encrypted))
            {
                var iv = receivedTransportMessage.GetStringHeader(Headers.EncryptionSalt);
                body = helper.Decrypt(receivedTransportMessage.Body, iv);

                headers.Remove(Headers.EncryptionSalt);
                headers.Remove(Headers.Encrypted);
            }
            else
            {
                body = receivedTransportMessage.Body;
            }

            return(new ReceivedTransportMessage
            {
                Id = receivedTransportMessage.Id,
                Headers = headers,
                Label = receivedTransportMessage.Label,
                Body = body,
            });
        }
示例#2
0
        /// <summary>
        /// Receives a <see cref="ReceivedTransportMessage"/> using the underlying implementation of <see cref="IReceiveMessages"/>
        /// decrypting the message body if necessary, and remove the additional encryption headers
        /// </summary>
        public ReceivedTransportMessage ReceiveMessage(ITransactionContext context)
        {
            var message = innerReceiveMessages.ReceiveMessage(context);

            if (message == null)
            {
                return(null);
            }

            var clone = new ReceivedTransportMessage
            {
                Body    = message.Body,
                Headers = message.Headers.Clone(),
                Label   = message.Label,
                Id      = message.Id
            };

            var headers = clone.Headers;

            if (encryptionHelper != null)
            {
                if (headers.ContainsKey(Headers.Encrypted))
                {
                    var iv = clone.GetStringHeader(Headers.EncryptionSalt);
                    clone.Body = encryptionHelper.Decrypt(clone.Body, iv);

                    headers.Remove(Headers.EncryptionSalt);
                    headers.Remove(Headers.Encrypted);
                }
            }

            if (compressionHelper != null)
            {
                if (headers.ContainsKey(Headers.Compression))
                {
                    var compressionType = (headers[Headers.Compression] ?? "").ToString();

                    switch (compressionType)
                    {
                    case Headers.CompressionTypes.GZip:
                        clone.Body = compressionHelper.Decompress(clone.Body);
                        break;

                    default:
                        throw new ArgumentException(
                                  string.Format(
                                      "Received message has the {0} header, but the compression type is set to {1} which cannot be handled",
                                      Headers.Compression, compressionType));
                    }

                    headers.Remove(Headers.Compression);
                }
            }

            return(clone);
        }