Esempio n. 1
0
        /// <summary>Handles an exception before the response has been written out.</summary>
        /// <param name='exception'>Exception thrown.</param>
        /// <param name='service'>Data service doing the processing.</param>
        /// <param name='accept'>'Accept' header value; possibly null.</param>
        /// <param name='acceptCharset'>'Accept-Charset' header; possibly null.</param>
        /// <returns>An action that can serialize the exception into a stream.</returns>
        internal static Action <Stream> HandleBeforeWritingException(Exception exception, IDataService service, string accept, string acceptCharset)
        {
            Debug.Assert(WebUtil.IsCatchableExceptionType(exception), "WebUtil.IsCatchableExceptionType(exception)");
            Debug.Assert(exception != null, "exception != null");
            Debug.Assert(service != null, "service != null");

            string   contentType;
            Encoding encoding;

            TryGetResponseFormatForError(accept, acceptCharset, out contentType, out encoding);

            bool verbose             = (service.Configuration != null) ? service.Configuration.UseVerboseErrors : false;
            HandleExceptionArgs args = new HandleExceptionArgs(exception, false, contentType, verbose);

            service.InternalHandleException(args);
            DataServiceHostWrapper host = service.OperationContext.Host;

            host.ResponseVersion = XmlConstants.DataServiceVersion1Dot0 + ";";
            host.ProcessException(args);
            Action <Stream> action = ProcessBenignException(exception, service);

            if (action != null)
            {
                return(action);
            }
            else
            {
                return(CreateErrorSerializer(args, encoding));
            }
        }
Esempio n. 2
0
 void IDataServiceHost.ProcessException(HandleExceptionArgs args)
 {
     WebUtil.CheckArgumentNull <HandleExceptionArgs>(args, "args");
     this.responseStatusCode = args.ResponseStatusCode;
     this.responseHeaders[System.Net.HttpResponseHeader.ContentType] = args.ResponseContentType;
     this.responseHeaders[System.Net.HttpResponseHeader.Allow]       = args.ResponseAllowHeader;
 }
Esempio n. 3
0
        /// <summary>Handles an exception when processing a batch response.</summary>
        /// <param name='service'>Data service doing the processing.</param>
        /// <param name="host">host to which we need to write the exception message</param>
        /// <param name='exception'>Exception thrown.</param>
        /// <param name='writer'>Output writer for the batch.</param>
        internal static void HandleBatchProcessException(IDataService service, DataServiceHostWrapper host, Exception exception, StreamWriter writer)
        {
            Debug.Assert(service != null, "service != null");
            Debug.Assert(host != null, "host != null");
            Debug.Assert(exception != null, "exception != null");
            Debug.Assert(writer != null, "writer != null");
            Debug.Assert(service.Configuration != null, "service.Configuration != null");
            Debug.Assert(WebUtil.IsCatchableExceptionType(exception), "WebUtil.IsCatchableExceptionType(exception)");

            string contentType;
            Encoding encoding;
            TryGetResponseFormatForError(host, out contentType, out encoding);

            HandleExceptionArgs args = new HandleExceptionArgs(exception, false, contentType, service.Configuration.UseVerboseErrors);
            service.InternalHandleException(args);
            host.ResponseVersion = XmlConstants.DataServiceVersion1Dot0 + ";";
            host.ProcessException(args);

            writer.Flush();
            Action<Stream> errorWriter = ProcessBenignException(exception, service);
            if (errorWriter == null)
            {
                errorWriter = CreateErrorSerializer(args, encoding);
            }

            errorWriter(writer.BaseStream);
            writer.WriteLine();
        }
Esempio n. 4
0
        /// <summary>Handles an exception when processing a batch response.</summary>
        /// <param name='service'>Data service doing the processing.</param>
        /// <param name="host">host to which we need to write the exception message</param>
        /// <param name='exception'>Exception thrown.</param>
        /// <param name='writer'>Output writer for the batch.</param>
        internal static void HandleBatchProcessException(IDataService service, DataServiceHostWrapper host, Exception exception, StreamWriter writer)
        {
            Debug.Assert(service != null, "service != null");
            Debug.Assert(host != null, "host != null");
            Debug.Assert(exception != null, "exception != null");
            Debug.Assert(writer != null, "writer != null");
            Debug.Assert(service.Configuration != null, "service.Configuration != null");
            Debug.Assert(WebUtil.IsCatchableExceptionType(exception), "WebUtil.IsCatchableExceptionType(exception)");

            string   contentType;
            Encoding encoding;

            TryGetResponseFormatForError(host, out contentType, out encoding);

            HandleExceptionArgs args = new HandleExceptionArgs(exception, false, contentType, service.Configuration.UseVerboseErrors);

            service.InternalHandleException(args);
            host.ResponseVersion = XmlConstants.DataServiceVersion1Dot0 + ";";
            host.ProcessException(args);

            writer.Flush();
            Action <Stream> errorWriter = ProcessBenignException(exception, service);

            if (errorWriter == null)
            {
                errorWriter = CreateErrorSerializer(args, encoding);
            }

            errorWriter(writer.BaseStream);
            writer.WriteLine();
        }
Esempio n. 5
0
        /// <summary>Handles an exception when processing a batch request.</summary>
        /// <param name='service'>Data service doing the processing.</param>
        /// <param name='exception'>Exception thrown.</param>
        /// <param name='writer'>Output writer for the batch.</param>
        internal static void HandleBatchRequestException(IDataService service, Exception exception, StreamWriter writer)
        {
            Debug.Assert(service != null, "service != null");
            Debug.Assert(exception != null, "exception != null");
            Debug.Assert(writer != null, "writer != null");
            Debug.Assert(service.Configuration != null, "service.Configuration != null - it should have been initialized by now");
            Debug.Assert(WebUtil.IsCatchableExceptionType(exception), "WebUtil.IsCatchableExceptionType(exception) - ");

            string   contentType;
            Encoding encoding;
            DataServiceHostWrapper host = service.OperationContext == null ? null : service.OperationContext.Host;

            TryGetResponseFormatForError(host, out contentType, out encoding);
            encoding = writer.Encoding;

            HandleExceptionArgs args = new HandleExceptionArgs(exception, false, contentType, service.Configuration.UseVerboseErrors);

            service.InternalHandleException(args);
            writer.Flush();

            Action <Stream> errorWriter = CreateErrorSerializer(args, encoding);

            errorWriter(writer.BaseStream);
            writer.WriteLine();
        }
Esempio n. 6
0
 public void WriteException(HandleExceptionArgs args)
 {
     using (XmlWriter writer = XmlWriter.Create(this.outputStream))
     {
         ErrorHandler.SerializeXmlError(args, writer);
     }
 }
Esempio n. 7
0
        internal static void HandleDuringWritingException(Exception exception, IDataService service, string contentType, ODataMessageWriter messageWriter, Stream responseStream, Encoding encoding)
        {
            HandleExceptionArgs args = new HandleExceptionArgs(exception, true, contentType, service.Configuration.UseVerboseErrors);

            service.InternalHandleException(args);
            service.OperationContext.Host.ProcessException(args);
            SerializeODataError(args, messageWriter, responseStream, encoding);
        }
Esempio n. 8
0
        /// <summary>Serializes an error in XML format.</summary>
        /// <param name='args'>Arguments describing the error.</param>
        /// <param name='writer'>Writer to which error should be serialized.</param>
        internal static void SerializeXmlError(HandleExceptionArgs args, XmlWriter writer)
        {
            Debug.Assert(args != null, "args != null");
            Debug.Assert(writer != null, "writer != null");
            ErrorHandler serializer = new ErrorHandler(args, null);

            serializer.SerializeXmlError(writer);
        }
Esempio n. 9
0
        internal static void HandleDuringWritingException(Exception exception, IDataService service, string contentType, IExceptionWriter exceptionWriter)
        {
            HandleExceptionArgs args = new HandleExceptionArgs(exception, true, contentType, service.Configuration.UseVerboseErrors);

            service.InternalHandleException(args);
            service.OperationContext.Host.ProcessException(args);
            exceptionWriter.WriteException(args);
        }
Esempio n. 10
0
        protected virtual void HandleException(HandleExceptionArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            throw new NotImplementedException();
        }
Esempio n. 11
0
 private static Action<Stream> CreateErrorSerializer(ODataFormat responseFormat, HandleExceptionArgs args, Encoding encoding)
 {
     ErrorHandler handler = new ErrorHandler(args, encoding);
     if (responseFormat == ODataFormat.VerboseJson)
     {
         return new Action<Stream>(handler.SerializeJsonErrorToStream);
     }
     return new Action<Stream>(handler.SerializeXmlErrorToStream);
 }
Esempio n. 12
0
 void IDataServiceHost.ProcessException(HandleExceptionArgs args)
 {
     WebUtil.CheckArgumentNull<HandleExceptionArgs>(args, "args");
     this.errorFound = true;
     if (!args.ResponseWritten)
     {
         ((IDataServiceHost) this).ResponseStatusCode = args.ResponseStatusCode;
         ((IDataServiceHost) this).ResponseContentType = args.ResponseContentType;
         if (args.ResponseAllowHeader != null)
         {
             WebOperationContext.Current.OutgoingResponse.Headers[HttpResponseHeader.Allow] = args.ResponseAllowHeader;
         }
     }
 }
Esempio n. 13
0
 /// <summary>
 /// Method to handle a data service exception during processing.
 /// </summary>
 /// <param name="args">Exception handling description.</param>
 void IDataServiceHost.ProcessException(HandleExceptionArgs args)
 {
     Debug.Assert(this.operationContext != null, "this.operationContext != null");
     this.errorFound = true;
     if (!args.ResponseWritten)
     {
         ((IDataServiceHost)this).ResponseStatusCode  = args.ResponseStatusCode;
         ((IDataServiceHost)this).ResponseContentType = args.ResponseContentType;
         if (args.ResponseAllowHeader != null)
         {
             this.operationContext.OutgoingResponse.Headers[HttpResponseHeader.Allow] = args.ResponseAllowHeader;
         }
     }
 }
Esempio n. 14
0
 void IDataServiceHost.ProcessException(HandleExceptionArgs args)
 {
     WebUtil.CheckArgumentNull <HandleExceptionArgs>(args, "args");
     this.errorFound = true;
     if (!args.ResponseWritten)
     {
         ((IDataServiceHost)this).ResponseStatusCode  = args.ResponseStatusCode;
         ((IDataServiceHost)this).ResponseContentType = args.ResponseContentType;
         if (args.ResponseAllowHeader != null)
         {
             WebOperationContext.Current.OutgoingResponse.Headers[HttpResponseHeader.Allow] = args.ResponseAllowHeader;
         }
     }
 }
Esempio n. 15
0
        /// <summary>Handles an exception while the response is being written out.</summary>
        /// <param name='exception'>Exception thrown.</param>
        /// <param name='service'>Data service doing the processing.</param>
        /// <param name='contentType'>MIME type of output stream.</param>
        /// <param name='exceptionWriter'>Serializer-specific exception writer.</param>
        internal static void HandleDuringWritingException(Exception exception, IDataService service, string contentType, IExceptionWriter exceptionWriter)
        {
            Debug.Assert(service != null, "service != null");
            Debug.Assert(exception != null, "exception != null");
            Debug.Assert(exceptionWriter != null, "exceptionWriter != null");
            Debug.Assert(service.Configuration != null, "service.Configuration != null");
            Debug.Assert(WebUtil.IsCatchableExceptionType(exception), "WebUtil.IsCatchableExceptionType(exception)");

            HandleExceptionArgs args = new HandleExceptionArgs(exception, true, contentType, service.Configuration.UseVerboseErrors);

            service.InternalHandleException(args);
            service.OperationContext.Host.ProcessException(args);
            exceptionWriter.WriteException(args);
        }
Esempio n. 16
0
        /// <summary>Creates a delegate that can serialize an error for the specified arguments.</summary>
        /// <param name="args">Arguments for the exception being handled.</param>
        /// <param name="encoding">Encoding to created over stream.</param>
        /// <returns>A delegate that can serialize an error for the specified arguments.</returns>
        private static Action <Stream> CreateErrorSerializer(HandleExceptionArgs args, Encoding encoding)
        {
            Debug.Assert(args != null, "args != null");
            Debug.Assert(encoding != null, "encoding != null");
            ErrorHandler handler = new ErrorHandler(args, encoding);

            if (WebUtil.CompareMimeType(args.ResponseContentType, XmlConstants.MimeApplicationJson))
            {
                return(handler.SerializeJsonErrorToStream);
            }
            else
            {
                return(handler.SerializeXmlErrorToStream);
            }
        }
Esempio n. 17
0
        /// <summary>Method to handle a data service exception during processing.</summary>
        /// <param name="args">Exception handling description.</param>
        void IDataServiceHost.ProcessException(HandleExceptionArgs args)
        {
            // This would typically set headers on the host.
            WebUtil.CheckArgumentNull(args, "args");
            Debug.Assert(WebUtil.IsCatchableExceptionType(args.Exception), "WebUtil.IsCatchableExceptionType(args.Exception)");
            this.responseStatusCode = args.ResponseStatusCode;
            this.responseHeaders[HttpResponseHeader.ContentType] = args.ResponseContentType;
            this.responseHeaders[HttpResponseHeader.Allow]       = args.ResponseAllowHeader;

            // Only write the headers if the response is not written
            if (!args.ResponseWritten)
            {
                System.Data.Services.Serializers.BatchWriter.WriteBoundaryAndHeaders(this.writer, this, this.contentId, this.boundary);
            }
        }
 //
 public static void HandleException(HandleExceptionArgs args)
 {
     if (args.Exception.GetType() == typeof(DbEntityValidationException))
     {
         var ex = args.Exception as DbEntityValidationException;
         args.Exception = new DataServiceException(500, ex.Message);
     }
     else
     {
         var message = GetExceptionMessgae(args.Exception);
         if (message != null)
         {
             args.Exception = new DataServiceException(500, message);
         }
     }
 }
Esempio n. 19
0
 internal static void HandleBatchInStreamError(IDataService service, Exception exception, ODataBatchWriter batchWriter, Stream responseStream)
 {
     string str;
     Encoding encoding;
     string str2;
     Version version;
     DataServiceHostWrapper host = (service.OperationContext == null) ? null : service.OperationContext.Host;
     TryGetResponseFormatForError(service, host, RequestDescription.DataServiceDefaultResponseVersion, out str, out encoding, out str2, out version);
     HandleExceptionArgs args = new HandleExceptionArgs(exception, false, str2, service.Configuration.UseVerboseErrors);
     service.InternalHandleException(args);
     batchWriter.Flush();
     using (XmlWriter writer = XmlUtil.CreateXmlWriterAndWriteProcessingInstruction(responseStream, encoding))
     {
         ODataError error = CreateODataErrorFromExceptionArgs(args);
         ErrorUtils.WriteXmlError(writer, error, args.UseVerboseErrors, 100);
     }
 }
Esempio n. 20
0
 private static ODataError CreateODataErrorFromExceptionArgs(HandleExceptionArgs args)
 {
     string str;
     string str2;
     string str3;
     DataServiceException exception = ExtractErrorValues(args.Exception, out str, out str2, out str3);
     ODataError error = new ODataError {
         ErrorCode = str,
         Message = str2,
         MessageLanguage = str3
     };
     if (args.UseVerboseErrors)
     {
         Exception exception2 = (exception == null) ? args.Exception : exception.InnerException;
         error.InnerError = (exception2 == null) ? null : new ODataInnerError(exception2);
     }
     return error;
 }
Esempio n. 21
0
        private static ODataError CreateODataErrorFromExceptionArgs(HandleExceptionArgs args)
        {
            string str;
            string str2;
            string str3;
            DataServiceException exception = ExtractErrorValues(args.Exception, out str, out str2, out str3);
            ODataError           error     = new ODataError {
                ErrorCode       = str,
                Message         = str2,
                MessageLanguage = str3
            };

            if (args.UseVerboseErrors)
            {
                Exception exception2 = (exception == null) ? args.Exception : exception.InnerException;
                error.InnerError = (exception2 == null) ? null : new ODataInnerError(exception2);
            }
            return(error);
        }
Esempio n. 22
0
        internal static void HandleBatchInStreamError(IDataService service, Exception exception, ODataBatchWriter batchWriter, Stream responseStream)
        {
            string   str;
            Encoding encoding;
            string   str2;
            Version  version;
            DataServiceHostWrapper host = (service.OperationContext == null) ? null : service.OperationContext.Host;

            TryGetResponseFormatForError(service, host, RequestDescription.DataServiceDefaultResponseVersion, out str, out encoding, out str2, out version);
            HandleExceptionArgs args = new HandleExceptionArgs(exception, false, str2, service.Configuration.UseVerboseErrors);

            service.InternalHandleException(args);
            batchWriter.Flush();
            using (XmlWriter writer = XmlUtil.CreateXmlWriterAndWriteProcessingInstruction(responseStream, encoding))
            {
                ODataError error = CreateODataErrorFromExceptionArgs(args);
                ErrorUtils.WriteXmlError(writer, error, args.UseVerboseErrors, 100);
            }
        }
Esempio n. 23
0
        internal static void SerializeODataError(HandleExceptionArgs args, ODataMessageWriter writer, Stream outputStream, Encoding encoding)
        {
            ODataError error = CreateODataErrorFromExceptionArgs(args);

            try
            {
                writer.WriteError(error, args.UseVerboseErrors);
            }
            catch (InvalidOperationException)
            {
                if (!WebUtil.CompareMimeType(args.ResponseContentType, "application/json;odata=verbose"))
                {
                    WebUtil.Dispose(writer);
                    using (XmlWriter writer2 = XmlWriter.Create(outputStream, XmlUtil.CreateXmlWriterSettings(encoding)))
                    {
                        ErrorUtils.WriteXmlError(writer2, error, args.UseVerboseErrors, 100);
                    }
                }
            }
        }
Esempio n. 24
0
        internal static void HandleBatchOperationError(IDataService service, DataServiceHostWrapper host, Exception exception, ODataBatchWriter batchWriter, Stream responseStream, Version defaultResponseVersion)
        {
            string   str;
            Encoding encoding;
            string   str2;
            Version  version;

            TryGetResponseFormatForError(service, host, defaultResponseVersion, out str, out encoding, out str2, out version);
            HandleExceptionArgs args = new HandleExceptionArgs(exception, false, str2, service.Configuration.UseVerboseErrors);

            service.InternalHandleException(args);
            Action <Stream> action = null;

            if (host != null)
            {
                host.ResponseVersion = version.ToString(2) + ";";
                host.ProcessException(args);
                action = ProcessBenignException(exception, service);
            }
            if (action == null)
            {
                ODataBatchOperationResponseMessage operationResponseMessage;
                if (host != null)
                {
                    operationResponseMessage = host.BatchServiceHost.GetOperationResponseMessage();
                    WebUtil.SetResponseHeadersForBatchRequests(operationResponseMessage, host.BatchServiceHost);
                }
                else
                {
                    operationResponseMessage            = batchWriter.CreateOperationResponseMessage();
                    operationResponseMessage.StatusCode = args.ResponseStatusCode;
                }
                using (ODataMessageWriter writer = ResponseBodyWriter.CreateMessageWriter(null, service, version, operationResponseMessage, str, null))
                {
                    SerializeODataError(args, writer, responseStream, encoding);
                }
            }
        }
Esempio n. 25
0
        internal static Action <Stream> HandleBeforeWritingException(Exception exception, IDataService service)
        {
            string   str;
            Encoding encoding;
            string   str2;
            Version  responseVersion    = null;
            DataServiceHostWrapper host = service.OperationContext.Host;

            TryGetResponseFormatForError(service, host, RequestDescription.DataServiceDefaultResponseVersion, out str, out encoding, out str2, out responseVersion);
            bool verboseResponse     = (service.Configuration != null) ? service.Configuration.UseVerboseErrors : false;
            HandleExceptionArgs args = new HandleExceptionArgs(exception, false, str2, verboseResponse);

            service.InternalHandleException(args);
            host.ResponseVersion = responseVersion.ToString(2) + ";";
            host.ProcessException(args);
            Action <Stream> action = ProcessBenignException(exception, service);
            ODataFormat     atom   = ODataFormat.Atom;

            if (WebUtil.GetContentFormat(str) == ContentFormat.VerboseJson)
            {
                atom = ODataFormat.VerboseJson;
            }
            return(action ?? CreateErrorSerializer(atom, args, encoding));
        }
Esempio n. 26
0
 internal static Action<Stream> HandleBeforeWritingException(Exception exception, IDataService service)
 {
     string str;
     Encoding encoding;
     string str2;
     Version responseVersion = null;
     DataServiceHostWrapper host = service.OperationContext.Host;
     TryGetResponseFormatForError(service, host, RequestDescription.DataServiceDefaultResponseVersion, out str, out encoding, out str2, out responseVersion);
     bool verboseResponse = (service.Configuration != null) ? service.Configuration.UseVerboseErrors : false;
     HandleExceptionArgs args = new HandleExceptionArgs(exception, false, str2, verboseResponse);
     service.InternalHandleException(args);
     host.ResponseVersion = responseVersion.ToString(2) + ";";
     host.ProcessException(args);
     Action<Stream> action = ProcessBenignException(exception, service);
     ODataFormat atom = ODataFormat.Atom;
     if (WebUtil.GetContentFormat(str) == ContentFormat.VerboseJson)
     {
         atom = ODataFormat.VerboseJson;
     }
     return (action ?? CreateErrorSerializer(atom, args, encoding));
 }
Esempio n. 27
0
 /// <summary>Creates a delegate that can serialize an error for the specified arguments.</summary>
 /// <param name="args">Arguments for the exception being handled.</param>
 /// <param name="encoding">Encoding to created over stream.</param>
 /// <returns>A delegate that can serialize an error for the specified arguments.</returns>
 private static Action<Stream> CreateErrorSerializer(HandleExceptionArgs args, Encoding encoding)
 {
     Debug.Assert(args != null, "args != null");
     Debug.Assert(encoding != null, "encoding != null");
     ErrorHandler handler = new ErrorHandler(args, encoding);
     if (WebUtil.CompareMimeType(args.ResponseContentType, XmlConstants.MimeApplicationJson))
     {
         return handler.SerializeJsonErrorToStream;
     }
     else
     {
         return handler.SerializeXmlErrorToStream;
     }
 }
Esempio n. 28
0
 void System.Data.Services.IDataService.InternalHandleException(HandleExceptionArgs args)
 {
 }
Esempio n. 29
0
 internal static void HandleBatchOperationError(IDataService service, DataServiceHostWrapper host, Exception exception, ODataBatchWriter batchWriter, Stream responseStream, Version defaultResponseVersion)
 {
     string str;
     Encoding encoding;
     string str2;
     Version version;
     TryGetResponseFormatForError(service, host, defaultResponseVersion, out str, out encoding, out str2, out version);
     HandleExceptionArgs args = new HandleExceptionArgs(exception, false, str2, service.Configuration.UseVerboseErrors);
     service.InternalHandleException(args);
     Action<Stream> action = null;
     if (host != null)
     {
         host.ResponseVersion = version.ToString(2) + ";";
         host.ProcessException(args);
         action = ProcessBenignException(exception, service);
     }
     if (action == null)
     {
         ODataBatchOperationResponseMessage operationResponseMessage;
         if (host != null)
         {
             operationResponseMessage = host.BatchServiceHost.GetOperationResponseMessage();
             WebUtil.SetResponseHeadersForBatchRequests(operationResponseMessage, host.BatchServiceHost);
         }
         else
         {
             operationResponseMessage = batchWriter.CreateOperationResponseMessage();
             operationResponseMessage.StatusCode = args.ResponseStatusCode;
         }
         using (ODataMessageWriter writer = ResponseBodyWriter.CreateMessageWriter(null, service, version, operationResponseMessage, str, null))
         {
             SerializeODataError(args, writer, responseStream, encoding);
         }
     }
 }
Esempio n. 30
0
 /// <summary>Serializes exception information.</summary>
 /// <param name="args">Description of exception to serialize.</param>
 public abstract void WriteException(HandleExceptionArgs args);
Esempio n. 31
0
 internal static void SerializeODataError(HandleExceptionArgs args, ODataMessageWriter writer, Stream outputStream, Encoding encoding)
 {
     ODataError error = CreateODataErrorFromExceptionArgs(args);
     try
     {
         writer.WriteError(error, args.UseVerboseErrors);
     }
     catch (InvalidOperationException)
     {
         if (!WebUtil.CompareMimeType(args.ResponseContentType, "application/json;odata=verbose"))
         {
             WebUtil.Dispose(writer);
             using (XmlWriter writer2 = XmlWriter.Create(outputStream, XmlUtil.CreateXmlWriterSettings(encoding)))
             {
                 ErrorUtils.WriteXmlError(writer2, error, args.UseVerboseErrors, 100);
             }
         }
     }
 }
Esempio n. 32
0
 private ErrorHandler(HandleExceptionArgs args, Encoding encoding)
 {
     this.exceptionArgs = args;
     this.encoding = encoding;
 }
Esempio n. 33
0
 /// <summary>Initializes a new <see cref="ErrorHandler"/> instance.</summary>
 /// <param name="args">Arguments for the exception being handled.</param>
 /// <param name="encoding">Encoding to created over stream; null if a higher-level writer will be provided.</param>
 private ErrorHandler(HandleExceptionArgs args, Encoding encoding)
 {
     Debug.Assert(args != null, "args != null");
     this.exceptionArgs = args;
     this.encoding      = encoding;
 }
Esempio n. 34
0
        /// <summary>Handles an exception while the response is being written out.</summary>
        /// <param name='exception'>Exception thrown.</param>
        /// <param name='service'>Data service doing the processing.</param>
        /// <param name='contentType'>MIME type of output stream.</param>
        /// <param name='exceptionWriter'>Serializer-specific exception writer.</param>
        internal static void HandleDuringWritingException(Exception exception, IDataService service, string contentType, IExceptionWriter exceptionWriter)
        {
            Debug.Assert(service != null, "service != null");
            Debug.Assert(exception != null, "exception != null");
            Debug.Assert(exceptionWriter != null, "exceptionWriter != null");
            Debug.Assert(service.Configuration != null, "service.Configuration != null");
            Debug.Assert(WebUtil.IsCatchableExceptionType(exception), "WebUtil.IsCatchableExceptionType(exception)");

            HandleExceptionArgs args = new HandleExceptionArgs(exception, true, contentType, service.Configuration.UseVerboseErrors);
            service.InternalHandleException(args);
            service.OperationContext.Host.ProcessException(args);
            exceptionWriter.WriteException(args);
        }
Esempio n. 35
0
 internal static void SerializeXmlError(HandleExceptionArgs args, XmlWriter writer)
 {
     new ErrorHandler(args, null).SerializeXmlError(writer);
 }
Esempio n. 36
0
 /// <summary>Serializes an error in XML format.</summary>
 /// <param name='args'>Arguments describing the error.</param>
 /// <param name='writer'>Writer to which error should be serialized.</param>
 internal static void SerializeXmlError(HandleExceptionArgs args, XmlWriter writer)
 {
     Debug.Assert(args != null, "args != null");
     Debug.Assert(writer != null, "writer != null");
     ErrorHandler serializer = new ErrorHandler(args, null);
     serializer.SerializeXmlError(writer);
 }
Esempio n. 37
0
        /// <summary>Handles an exception when processing a batch request.</summary>
        /// <param name='service'>Data service doing the processing.</param>
        /// <param name='exception'>Exception thrown.</param>
        /// <param name='writer'>Output writer for the batch.</param>
        internal static void HandleBatchRequestException(IDataService service, Exception exception, StreamWriter writer)
        {
            Debug.Assert(service != null, "service != null");
            Debug.Assert(exception != null, "exception != null");
            Debug.Assert(writer != null, "writer != null");
            Debug.Assert(service.Configuration != null, "service.Configuration != null - it should have been initialized by now");
            Debug.Assert(WebUtil.IsCatchableExceptionType(exception), "WebUtil.IsCatchableExceptionType(exception) - ");

            string contentType;
            Encoding encoding;
            DataServiceHostWrapper host = service.OperationContext == null ? null : service.OperationContext.Host;
            TryGetResponseFormatForError(host, out contentType, out encoding);
            encoding = writer.Encoding;

            HandleExceptionArgs args = new HandleExceptionArgs(exception, false, contentType, service.Configuration.UseVerboseErrors);
            service.InternalHandleException(args);
            writer.Flush();

            Action<Stream> errorWriter = CreateErrorSerializer(args, encoding);
            errorWriter(writer.BaseStream);
            writer.WriteLine();
        }
Esempio n. 38
0
 internal static void HandleDuringWritingException(Exception exception, IDataService service, string contentType, IExceptionWriter exceptionWriter)
 {
     HandleExceptionArgs args = new HandleExceptionArgs(exception, true, contentType, service.Configuration.UseVerboseErrors);
     service.InternalHandleException(args);
     service.OperationContext.Host.ProcessException(args);
     exceptionWriter.WriteException(args);
 }
Esempio n. 39
0
 internal static void HandleDuringWritingException(Exception exception, IDataService service, string contentType, ODataMessageWriter messageWriter, Stream responseStream, Encoding encoding)
 {
     HandleExceptionArgs args = new HandleExceptionArgs(exception, true, contentType, service.Configuration.UseVerboseErrors);
     service.InternalHandleException(args);
     service.OperationContext.Host.ProcessException(args);
     SerializeODataError(args, messageWriter, responseStream, encoding);
 }
Esempio n. 40
0
        /// <summary>Handles an exception before the response has been written out.</summary>
        /// <param name='exception'>Exception thrown.</param>
        /// <param name='service'>Data service doing the processing.</param>
        /// <param name='accept'>'Accept' header value; possibly null.</param>
        /// <param name='acceptCharset'>'Accept-Charset' header; possibly null.</param>
        /// <returns>An action that can serialize the exception into a stream.</returns>
        internal static Action<Stream> HandleBeforeWritingException(Exception exception, IDataService service, string accept, string acceptCharset)
        {
            Debug.Assert(WebUtil.IsCatchableExceptionType(exception), "WebUtil.IsCatchableExceptionType(exception)");
            Debug.Assert(exception != null, "exception != null");
            Debug.Assert(service != null, "service != null");

            string contentType;
            Encoding encoding;
            TryGetResponseFormatForError(accept, acceptCharset, out contentType, out encoding);

            bool verbose = (service.Configuration != null) ? service.Configuration.UseVerboseErrors : false;
            HandleExceptionArgs args = new HandleExceptionArgs(exception, false, contentType, verbose);
            service.InternalHandleException(args);
            DataServiceHostWrapper host = service.OperationContext.Host;
            host.ResponseVersion = XmlConstants.DataServiceVersion1Dot0 + ";";
            host.ProcessException(args);
            Action<Stream> action = ProcessBenignException(exception, service);
            if (action != null)
            {
                return action;
            }
            else
            {
                return CreateErrorSerializer(args, encoding);
            }
        }
Esempio n. 41
0
 private ErrorHandler(HandleExceptionArgs args, Encoding encoding)
 {
     this.exceptionArgs = args;
     this.encoding      = encoding;
 }
 /// <summary>
 /// Method to handle a data service exception during processing.
 /// </summary>
 /// <param name="args">Exception handling description.</param>
 void IDataServiceHost.ProcessException(HandleExceptionArgs args)
 {
     Debug.Assert(this.operationContext != null, "this.operationContext != null");
     this.errorFound = true;
     if (!args.ResponseWritten)
     {
         ((IDataServiceHost)this).ResponseStatusCode = args.ResponseStatusCode;
         ((IDataServiceHost)this).ResponseContentType = args.ResponseContentType;
         if (args.ResponseAllowHeader != null)
         {
             this.operationContext.OutgoingResponse.Headers[HttpResponseHeader.Allow] = args.ResponseAllowHeader;
         }
     }
 }
Esempio n. 43
0
 internal static void SerializeXmlError(HandleExceptionArgs args, XmlWriter writer)
 {
     new ErrorHandler(args, null).SerializeXmlError(writer);
 }
 /// <summary>Method to handle a data service exception during processing.</summary>
 /// <param name="args">Exception handling description.</param>
 internal void ProcessException(HandleExceptionArgs args)
 {
     this.host.ProcessException(args);
 }
 public void ProcessException(HandleExceptionArgs args)
 {
   throw new NotImplementedException();
 }
 /// <summary>
 /// Handles a data service exception using information in  the <paramref name="args"/> parameter.
 /// </summary>
 /// <param name="args"><see cref="T:System.Data.Services.HandleExceptionArgs"/>  that contains information on the exception object.</param>
 public void ProcessException(HandleExceptionArgs args) {
     throw new Exception("OData exception", args.Exception);
 }
Esempio n. 47
0
 protected virtual new void HandleException(HandleExceptionArgs args)
 {
   Contract.Requires(args != null);
 }
 public void ProcessException(HandleExceptionArgs args)
 {
     throw new NotImplementedException();
 }
        /// <summary>Method to handle a data service exception during processing.</summary>
        /// <param name="args">Exception handling description.</param>
        void IDataServiceHost.ProcessException(HandleExceptionArgs args)
        {
            // This would typically set headers on the host.
            WebUtil.CheckArgumentNull(args, "args");
            Debug.Assert(WebUtil.IsCatchableExceptionType(args.Exception), "WebUtil.IsCatchableExceptionType(args.Exception)");
            this.responseStatusCode = args.ResponseStatusCode;
            this.responseHeaders[HttpResponseHeader.ContentType] = args.ResponseContentType;
            this.responseHeaders[HttpResponseHeader.Allow] = args.ResponseAllowHeader;

            // Only write the headers if the response is not written
            if (!args.ResponseWritten)
            {
                System.Data.Services.Serializers.BatchWriter.WriteBoundaryAndHeaders(this.writer, this, this.contentId, this.boundary);
            }
        }
Esempio n. 50
0
 /// <summary>Initializes a new <see cref="ErrorHandler"/> instance.</summary>
 /// <param name="args">Arguments for the exception being handled.</param>
 /// <param name="encoding">Encoding to created over stream; null if a higher-level writer will be provided.</param>
 private ErrorHandler(HandleExceptionArgs args, Encoding encoding)
 {
     Debug.Assert(args != null, "args != null");
     this.exceptionArgs = args;
     this.encoding = encoding;
 }
Esempio n. 51
0
        private static Action <Stream> CreateErrorSerializer(ODataFormat responseFormat, HandleExceptionArgs args, Encoding encoding)
        {
            ErrorHandler handler = new ErrorHandler(args, encoding);

            if (responseFormat == ODataFormat.VerboseJson)
            {
                return(new Action <Stream>(handler.SerializeJsonErrorToStream));
            }
            return(new Action <Stream>(handler.SerializeXmlErrorToStream));
        }
Esempio n. 52
0
 void IDataServiceHost.ProcessException(HandleExceptionArgs args)
 {
     WebUtil.CheckArgumentNull<HandleExceptionArgs>(args, "args");
     this.responseStatusCode = args.ResponseStatusCode;
     this.responseHeaders[System.Net.HttpResponseHeader.ContentType] = args.ResponseContentType;
     this.responseHeaders[System.Net.HttpResponseHeader.Allow] = args.ResponseAllowHeader;
 }