//http://localhost:8080/DirectoryTree.xsp
        public void Answer(WebRequest aRequest)
        {
            IServletPage page = getPage(aRequest.File);

            if (page != null)
            {
                try
                {
                    if (page.IsBuffered && !aRequest.Response.IsInMemoryStreamMode)
                    {
                        aRequest.Response.SwitchToMemoryStream();
                    }

                    page.Answer(aRequest);
                }
                catch (Exception ex)
                {
                    if (page.IsBuffered)
                    {
                        try
                        {
                            string sNewPage = page.getExceptionPage(aRequest);
                            if (sNewPage == null)
                            {
                                throw new Exception("No error page defined");
                            }

                            aRequest.Response.Reset();
                            ExceptionWebRequest exRequest = new ExceptionWebRequest(sNewPage, aRequest, ex);
                            aRequest.Server.InvokeRequest(exRequest);
                        }
                        catch (Exception innerEx)
                        {
                            try
                            {
                                aRequest.Response.Reset();
                                aRequest.Response.SendContent("text/html");
                                aRequest.Response.WriteLine("<html><body><pre>");
                                Util.WriteExceptionToResponse(innerEx, aRequest.Response);
                                aRequest.Response.WriteLine("</pre><br>Original exeception was:<pre>");
                                Util.WriteExceptionToResponse(ex, aRequest.Response);
                                aRequest.Response.WriteLine("</pre></body></html>");
                            }
                            catch (Exception innerEx2)
                            {
                                Util.WriteException(innerEx2);
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        public override XmlDocument getXML(WebRequest aRequest)
        {
            if (!(aRequest is ExceptionWebRequest))
            {
                throw new Exception("this is an exception only page");
            }

            XmlDocument xdoc = new XmlDocument();

            XmlElement elRoot = xdoc.CreateElement("page");

            xdoc.AppendChild(elRoot);

            XmlElement el;
            //XmlAttribute attr;
            XmlElement elExceptions = xdoc.CreateElement("exceptions");

            elRoot.AppendChild(elExceptions);

            ExceptionWebRequest eWebRequest = (ExceptionWebRequest)aRequest;
            Exception           ex          = eWebRequest.Exception;

            while (ex != null)
            {
                XmlElement elException = xdoc.CreateElement("exception");
                elExceptions.AppendChild(elException);

                el           = xdoc.CreateElement("message");
                el.InnerText = ex.Message;
                elException.AppendChild(el);

                el           = xdoc.CreateElement("short-type-name");
                el.InnerText = ex.GetType().Name;
                elException.AppendChild(el);

                el           = xdoc.CreateElement("full-type-name");
                el.InnerText = ex.GetType().FullName;
                elException.AppendChild(el);

                el           = xdoc.CreateElement("stack-trace");
                el.InnerText = ex.StackTrace;
                elException.AppendChild(el);

                ex = ex.InnerException;
            }

            return(xdoc);
        }