Author: kostat
Date: 2007-01-04 09:10:41 -0500 (Thu, 04 Jan 2007)
New Revision: 70478
Modified:
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/MyHost.jvm.cs
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/Resources/Global.asax.cs
Log:
workaround TARGET_JVM platform issues
Modified:
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/MyHost.jvm.cs
===================================================================
--- trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/MyHost.jvm.cs
2007-01-04 14:09:28 UTC (rev 70477)
+++ trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/MyHost.jvm.cs
2007-01-04 14:10:41 UTC (rev 70478)
@@ -10,8 +10,8 @@
using System.Collections;
using System.Runtime.Remoting.Messaging;
using System.Reflection;
-using System.Threading;
-using System.Runtime.Serialization;
+using System.Threading;
+using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization.Formatters.Soap;
using System.Collections.Specialized;
@@ -25,14 +25,19 @@
public const string EXCEPTION_HEADER = "NunitWebException";
private const string CURRENT_WEBTEST = "NunitWebCurrentTest";
public AppDomain AppDomain
- { get { return AppDomain.CurrentDomain; } }
-
- public static string Serialize (object o)
- {
- if (o == null)
- return string.Empty;
+ { get { return AppDomain.CurrentDomain; } }
+
+ public static string Serialize (object o) {
+ return Serialize (o, new SoapFormatter ());
+ }
+ public static string SerializeBinary (object o) {
+ return Serialize (o, new SoapFormatter ());
+ }
+ public static string Serialize (object o, IFormatter f)
+ {
+ if (o == null)
+ return string.Empty;
using (MemoryStream ms = new MemoryStream ()) {
- SoapFormatter f = new SoapFormatter ();
try {
f.Serialize (ms, o);
}
@@ -43,19 +48,24 @@
else
throw;
}
- return HttpUtility.UrlEncode (ms.ToArray());
+ return HttpUtility.UrlEncode (ms.ToArray ());
}
- }
-
- public static object Deserialize (string s)
- {
- if (s == null || s == string.Empty)
- return null;
+ }
+
+ public static object Deserialize (string s) {
+ return Deserialize (s, new SoapFormatter ());
+ }
+ public static object DeserializeBinary (string s) {
+ return Deserialize (s, new SoapFormatter ());
+ }
+ public static object Deserialize (string s, IFormatter b)
+ {
+ if (s == null || s == string.Empty)
+ return null;
using (MemoryStream ms = new MemoryStream ()) {
byte [] ba = HttpUtility.UrlDecodeToBytes (s);
ms.Write (ba, 0, ba.Length);
ms.Position = 0;
- SoapFormatter b = new SoapFormatter ();
try {
return b.Deserialize (ms);
}
@@ -63,9 +73,9 @@
throw;
}
}
- }
-
- public WebTest Run (WebTest t)
+ }
+
+ public WebTest Run (WebTest t)
{
NameValueCollection headers = new NameValueCollection
();
headers.Add (INVOKER_HEADER, Serialize (t.Invoker));
@@ -81,25 +91,36 @@
WebResponse response = null;
try {
- try {
- response = wr.GetResponse ();
+
+ response = wr.GetResponse ();
+ HttpStatusCode status = ((HttpWebResponse)
response).StatusCode;
+ if (status != HttpStatusCode.OK && status !=
HttpStatusCode.Found)
+ throw new WebException
(((HttpWebResponse) response).StatusCode.ToString ());
+
+ t.Response = t.Request.ExtractResponse
(response);
+ string etype = response.Headers
[EXCEPTION_HEADER];
+
+ if (!String.IsNullOrEmpty (etype)) {
+ Exception e;
+ string data = t.Response.Body;
+ int start = data.IndexOf
(EXCEPTION_HEADER);
+ if (start >= 0) {
+ start +=
EXCEPTION_HEADER.Length;
+ int end = data.IndexOf
(EXCEPTION_HEADER, start);
+ int length =
int.Parse(data.Substring(start, end - start));
+
+ string serialized =
data.Substring (end + EXCEPTION_HEADER.Length, length);
+ e = (Exception)
DeserializeBinary (serialized);
+ }
+ else
+ e = (Exception)
Activator.CreateInstance (Type.GetType(etype));
+
+ if (e != null)
+ RethrowException (e);
}
- catch (WebException we) {
- //StreamReader sr = new StreamReader
(we.Response.GetResponseStream ());
- //throw new WebException (we.Message +
Environment.NewLine
- // + "Response:" +
Environment.NewLine + sr.ReadToEnd (), we);
- response = we.Response;
- if (((HttpWebResponse)
response).StatusCode == HttpStatusCode.OK)
- throw;//so we don't have a
false positive test
- }
- Exception e = (Exception) Deserialize (
- response.Headers[EXCEPTION_HEADER]);
- if (e != null)
- RethrowException (e);
- t.UserData = Deserialize
(response.Headers[USER_HEADER]);
- t.Response = t.Request.ExtractResponse
(response);
+ t.UserData = Deserialize (response.Headers
[USER_HEADER]);
}
finally {
if (response != null)
@@ -116,15 +137,7 @@
private static void RethrowException (Exception inner)
{
- Exception outer;
- try { //Try create a similar exception and keep the
inner intact
- outer = (Exception) Activator.CreateInstance
(inner.GetType (),
- new object []{inner.ToString (),
inner});
- }
- catch { //Failed to create a similar, fallback to the
inner, ruining the call stack
- throw inner;
- }
- throw outer;
+ throw inner;
}
public static WebTest GetCurrentTest ()
@@ -147,10 +160,18 @@
{
if (ex == null)
return;
+ //bug #6946
+ if (ex is TargetInvocationException)
+ ex = ex.InnerException;
if (HttpContext.Current.Items[EXCEPTION_HEADER] != null)
return; //register only the first exception
HttpContext.Current.Response.AddHeader
(EXCEPTION_HEADER,
- Serialize (ex));
+ ex.GetType().FullName);
+ HttpContext.Current.Response.Write (EXCEPTION_HEADER);
+ string serialized = SerializeBinary (ex);
+ HttpContext.Current.Response.Write (serialized.Length);
+ HttpContext.Current.Response.Write (EXCEPTION_HEADER);
+ HttpContext.Current.Response.Write (serialized);
HttpContext.Current.Items[EXCEPTION_HEADER] = ex;
}
}
Modified:
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/Resources/Global.asax.cs
===================================================================
---
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/Resources/Global.asax.cs
2007-01-04 14:09:28 UTC (rev 70477)
+++
trunk/mcs/class/System.Web/Test/mainsoft/NunitWeb/NunitWeb/Resources/Global.asax.cs
2007-01-04 14:10:41 UTC (rev 70478)
@@ -4,12 +4,17 @@
{
public partial class Global : System.Web.HttpApplication
{
- void Application_Error (object sender, EventArgs e)
+ protected void Application_Error (object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
Exception objErr = Server.GetLastError
().GetBaseException ();
MonoTests.SystemWeb.Framework.WebTest.RegisterException
(objErr);
Server.ClearError ();
}
+
+ protected void Application_OnEndRequest (object sender,
EventArgs e) {
+ // Ensure the headers are sent
+
MonoTests.SystemWeb.Framework.WebTest.CurrentTest.SendHeaders ();
+ }
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches