Example #1
0
        /// <summary>
        /// Reads message from buffer.
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="bufferManager"></param>
        /// <param name="contentType"></param>
        /// <returns></returns>
        public override Message ReadMessage(ArraySegment <byte> buffer, BufferManager bufferManager, string contentType)
        {
            byte[] msgContents = new byte[buffer.Count];

            Array.Copy(buffer.Array, buffer.Offset, msgContents, 0, msgContents.Length);
            bufferManager.ReturnBuffer(buffer.Array);


            string content = Encoding.UTF8.GetString(buffer.Array, buffer.Offset, buffer.Count);

            try
            {
                MemoryStream memoryStream = new MemoryStream();
                XmlDocument  document     = new XmlDocument();
                document.LoadXml(content);
                document.Save(memoryStream);
                memoryStream.Seek(0, SeekOrigin.Begin);
                TextReader rdr = new StreamReader(memoryStream);
                content = rdr.ReadToEnd();
                rdr.Close();
            }
            catch (Exception exc)
            {
                // Log content as is
            }

            foreach (IChannelController controller in _controllers)
            {
                ITrafficListener listener = controller as ITrafficListener;
                if (listener != null)
                {
                    listener.LogResponse(content);
                }
            }

            if (contentType == Internals.Http.HttpHelper.APPLICATIONSOAPXML)
            {
                MemoryStream validateStream = new MemoryStream(msgContents);
                foreach (IChannelController controller in _controllers)
                {
                    IValidatingController validatingController = controller as IValidatingController;
                    if (validatingController != null)
                    {
                        validatingController.Validate(validateStream);
                    }
                }
                validateStream.Close();
            }

            MemoryStream stream  = new MemoryStream(msgContents);
            Message      message = ReadMessage(stream, int.MaxValue, contentType);

            return(message);
        }
Example #2
0
        public override Message ReadMessage(ArraySegment <byte> buffer, BufferManager bufferManager, string contentType)
        {
            byte[] msgContents = new byte[buffer.Count];

            Array.Copy(buffer.Array, buffer.Offset, msgContents, 0, msgContents.Length);
            bufferManager.ReturnBuffer(buffer.Array);

            string content = Encoding.UTF8.GetString(buffer.Array);

            if (_listener != null)
            {
                _listener.LogResponse(content);
            }

            MemoryStream stream = new MemoryStream(msgContents);

            return(ReadMessage(stream, int.MaxValue));
        }
        void LogResponse(byte[] messageBytes, int count)
        {
            int offset = 0;

            while (messageBytes[offset] != '<' && offset < count)
            {
                offset++;
            }
            string content = FormatContent(Encoding.UTF8.GetString(messageBytes, offset, count - offset));

            content = FormatContent(content);

            foreach (IChannelController controller in _controllers)
            {
                ITrafficListener listener = controller as ITrafficListener;
                if (listener != null)
                {
                    listener.LogResponse(content);
                }
            }
        }