/// <summary>
		/// Event handler for <see cref="HttpServer.HttpRequestReceived"/> events.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="args"></param>
		protected void OnHttpRequestReceived(object sender, HttpRequestReceivedEventArg args)
		{

			// NOTE: This method is run under different threads for different http requests.
            HttpListenerContext context = args.Context;
            if (string.IsNullOrEmpty(Thread.CurrentThread.Name))
            Thread.CurrentThread.Name = String.Format("Streaming (client: {0}:{1})", context.Request.RemoteEndPoint.Address, context.Request.RemoteEndPoint.Port);

		    AddContext(context);

			try
			{
			    Validate(context);

                WADORequestProcessor processor = new WADORequestProcessor();
                processor.Process(context);
				
			}
            catch (WADOException e)
            {
                SetResponseError(context, e.GetHttpCode(), e.Message);
            }
            catch (HttpException e)
            {
                SetResponseError(context, e.GetHttpCode(), e.Message);
            }
            catch (ServerTransientError e)
            {
                SetResponseError(context, (int)HttpStatusCode.NoContent, e.Message);
            }
            catch(StudyNotFoundException e)
            {
                SetResponseError(context, (int)HttpStatusCode.BadRequest, e.Message);
            }
            catch (Exception e)
			{
                if (e.InnerException!=null)
					SetResponseError(context, (int)HttpStatusCode.InternalServerError, e.InnerException.Message);
				else
                    SetResponseError(context, (int)HttpStatusCode.InternalServerError, e.Message);
			}
            finally
			{
               
                    // note: the connection might have been aborted or lost too
                    try
                    {
                        context.Response.OutputStream.Flush();
                        context.Response.OutputStream.Close();
                    }
                    catch(Exception ex)
                    {
                        Platform.Log(LogLevel.Warn, "Unexpected exception occurred: {0}", ex.Message);
                    }
                    finally
                    {
                        RemoveContext(context);
                    }
			}

		}
示例#2
0
        /// <summary>
        /// Event handler for <see cref="HttpServer.HttpRequestReceived"/> events.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        protected void OnHttpRequestReceived(object sender, HttpRequestReceivedEventArg args)
        {
            // NOTE: This method is run under different threads for different http requests.
            HttpListenerContext context = args.Context;

            if (string.IsNullOrEmpty(Thread.CurrentThread.Name))
            {
                Thread.CurrentThread.Name = String.Format("Streaming (client: {0}:{1})", context.Request.RemoteEndPoint.Address, context.Request.RemoteEndPoint.Port);
            }

            AddContext(context);

            try
            {
                Validate(context);

                WADORequestProcessor processor = new WADORequestProcessor();
                processor.Process(context);
            }
            catch (WADOException e)
            {
                SetResponseError(context, e.GetHttpCode(), e.Message);
            }
            catch (HttpException e)
            {
                SetResponseError(context, e.GetHttpCode(), e.Message);
            }
            catch (ServerTransientError e)
            {
                SetResponseError(context, (int)HttpStatusCode.NoContent, e.Message);
            }
            catch (StudyNotFoundException e)
            {
                SetResponseError(context, (int)HttpStatusCode.BadRequest, e.Message);
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    SetResponseError(context, (int)HttpStatusCode.InternalServerError, e.InnerException.Message);
                }
                else
                {
                    SetResponseError(context, (int)HttpStatusCode.InternalServerError, e.Message);
                }
            }
            finally
            {
                // note: the connection might have been aborted or lost too
                try
                {
                    context.Response.OutputStream.Flush();
                    context.Response.OutputStream.Close();
                }
                catch (Exception ex)
                {
                    Platform.Log(LogLevel.Warn, "Unexpected exception occurred: {0}", ex.Message);
                }
                finally
                {
                    RemoveContext(context);
                }
            }
        }