Author: ilya
Date: 2005-06-19 05:19:18 -0400 (Sun, 19 Jun 2005)
New Revision: 46205
Modified:
trunk/mcs/class/System.Web/System.Web/ChangeLog
trunk/mcs/class/System.Web/System.Web/HttpApplication.cs
trunk/mcs/class/System.Web/System.Web/HttpApplicationFactory.cs
trunk/mcs/class/System.Web/System.Web/HttpContext.cs
trunk/mcs/class/System.Web/System.Web/HttpException.cs
trunk/mcs/class/System.Web/System.Web/HttpRequest.cs
trunk/mcs/class/System.Web/System.Web/HttpResponse.cs
trunk/mcs/class/System.Web/System.Web/HttpRuntime.cs
Log:
Modified: trunk/mcs/class/System.Web/System.Web/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web/ChangeLog 2005-06-19 09:09:48 UTC
(rev 46204)
+++ trunk/mcs/class/System.Web/System.Web/ChangeLog 2005-06-19 09:19:18 UTC
(rev 46205)
@@ -1,3 +1,18 @@
+2005-06-19 Svetlana Zholkovsky <svetlanaz-at-mainsoft.com>
+ * In following classes added TARGET_J2EE or/and TARGET_JVM
+ directives:
+ - HttpResponse.cs
+ - HttpRuntime.cs
+ - HttpUtility.cs
+ - CapabilitiesLoader.cs
+ - HttpApplication.cs
+ - HttpApplicationFactory.cs
+ - HttpContext.cs
+ - HttpException.cs
+ - HttpRequest.cs
+ * Added Mainsoft's specific files :
+ - GhHttpAsyncResult.jvm.cs
+
2005-06-10 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
* HttpRequest.cs: avoid one intermediate buffer when reading the request
Modified: trunk/mcs/class/System.Web/System.Web/HttpApplication.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web/HttpApplication.cs 2005-06-19
09:09:48 UTC (rev 46204)
+++ trunk/mcs/class/System.Web/System.Web/HttpApplication.cs 2005-06-19
09:19:18 UTC (rev 46205)
@@ -1056,7 +1056,11 @@
internal void Start ()
{
Reset ();
+#if !TARGET_J2EE
ExecuteNextAsync (null);
+#else
+ ExecuteNext(null);
+#endif
}
internal void ExecuteNextAsync (Exception lasterror)
@@ -1131,6 +1135,37 @@
ExecuteNext ((Exception) obj);
}
+#if TARGET_J2EE
+ private Exception HandleJavaException(Exception obj)
+ {
+ Exception lasterror = null;
+
+ if (obj is
System.Reflection.TargetInvocationException )
+ {
+ lasterror = obj.InnerException;
+#if DEBUG
+ if (lasterror is
java.lang.reflect.InvocationTargetException) {
+ Console.WriteLine("Got
java.lang.reflect.InvocationTargetException caused by");
+
java.lang.reflect.InvocationTargetException e1 =
(java.lang.reflect.InvocationTargetException)lasterror;
+ Console.WriteLine("{0},{1}",
e1.getTargetException().GetType(), e1.getTargetException().Message);
+
Console.WriteLine(e1.getTargetException().StackTrace);
+ } else
+#endif
+ if (lasterror is [EMAIL PROTECTED])
+ {
+ lasterror = null;
+ _app.CompleteRequest ();
+ }
+#if DEBUG
+ else {
+ Console.WriteLine("Error 1!!!
{0}:{1}", lasterror.GetType(), lasterror.Message);
+
Console.WriteLine(lasterror.StackTrace);
+ }
+#endif
+ }
+ return lasterror;
+ }
+#endif
private Exception ExecuteState (IStateHandler state,
ref bool readysync)
{
Exception lasterror = null;
@@ -1146,13 +1181,23 @@
_app.Context.EndTimeoutPossible ();
}
}
-
+#if TARGET_J2EE //Catch case of aborting by timeout
+ if (_app.Context.TimedOut) {
+ _app.CompleteRequest ();
+ return null;
+ }
+#endif
if (state.PossibleToTimeout) {
// Async Execute
_app.Context.TryWaitForTimeout
();
}
readysync =
state.CompletedSynchronously;
+#if TARGET_J2EE // Finishing execution for End without error
+ }catch ([EMAIL PROTECTED]){
+ lasterror = null;
+ _app.CompleteRequest ();
+#endif
} catch (ThreadAbortException obj) {
object o = obj.ExceptionState;
Type type = (o != null) ? o.GetType ()
: null;
@@ -1165,7 +1210,11 @@
_app.CompleteRequest ();
}
} catch (Exception obj) {
+#if TARGET_J2EE
+ lasterror = HandleJavaException(obj);
+#else
lasterror = obj;
+#endif
}
return lasterror;
@@ -1203,10 +1252,16 @@
#region Constructor
+#if TARGET_J2EE
public HttpApplication ()
{
+ }
+#else
+ public HttpApplication ()
+ {
assemblyLocation = GetType ().Assembly.Location;
}
+#endif
#endregion
@@ -1341,9 +1396,16 @@
HttpContext.Context = _savedContext;
RestorePrincipal ();
}
-
+#if TARGET_J2EE
internal void SetPrincipal (IPrincipal principal)
{
+ }
+ internal void RestorePrincipal ()
+ {
+ }
+#else
+ internal void SetPrincipal (IPrincipal principal)
+ {
// Don't overwrite _savedUser if called from inside a
step
if (_savedUser == null)
_savedUser = Thread.CurrentPrincipal;
@@ -1359,7 +1421,7 @@
Thread.CurrentPrincipal = _savedUser;
_savedUser = null;
}
-
+#endif
internal void ClearError ()
{
_lastError = null;
@@ -1583,7 +1645,15 @@
[Browsable (false)]
[DesignerSerializationVisibility
(DesignerSerializationVisibility.Hidden)]
public HttpSessionState Session {
+#if TARGET_J2EE
get {
+ if (null != _Context && null !=
_Context.Session)
+ return _Context.Session;
+
+ throw new HttpException ("Failed to get session
object");
+ }
+#else
+ get {
if (null != _Session)
return _Session;
@@ -1592,6 +1662,7 @@
throw new HttpException ("Failed to get session
object");
}
+#endif
}
[Browsable (false)]
Modified: trunk/mcs/class/System.Web/System.Web/HttpApplicationFactory.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web/HttpApplicationFactory.cs
2005-06-19 09:09:48 UTC (rev 46204)
+++ trunk/mcs/class/System.Web/System.Web/HttpApplicationFactory.cs
2005-06-19 09:19:18 UTC (rev 46205)
@@ -34,8 +34,13 @@
using System.IO;
using System.Reflection;
using System.Web.UI;
+using System.Web.SessionState;
+#if !TARGET_J2EE
using System.Web.Compilation;
-using System.Web.SessionState;
+#else
+using System.Web.Configuration;
+using vmw.common;
+#endif
namespace System.Web {
class HttpApplicationFactory {
@@ -53,30 +58,60 @@
static private int _appMaxFreePublicInstances = 32;
- private HttpApplicationState _state;
-
- static IHttpHandler custApplication;
-
- static private HttpApplicationFactory s_Factory = new
HttpApplicationFactory();
-
- public HttpApplicationFactory() {
- _appInitialized = false;
- _appFiredEnd = false;
-
- _appFreePublicList = new Stack();
- _appFreePublicInstances = 0;
- }
-
- static private string GetAppFilename (HttpContext context)
- {
- string physicalAppPath =
context.Request.PhysicalApplicationPath;
- string appFilePath = Path.Combine (physicalAppPath,
"Global.asax");
- if (File.Exists (appFilePath))
- return appFilePath;
-
- return Path.Combine (physicalAppPath, "global.asax");
- }
+ private HttpApplicationState _state;
+ static IHttpHandler custApplication;
+
+#if TARGET_J2EE
+ static private HttpApplicationFactory s_Factory {
+ get {
+ HttpApplicationFactory factory
=
(HttpApplicationFactory)AppDomain.CurrentDomain.GetData("HttpApplicationFactory");
+ if (factory == null) {
+ factory = new
HttpApplicationFactory();
+
AppDomain.CurrentDomain.SetData("HttpApplicationFactory", factory);
+ }
+ return factory;
+ }
+ }
+#else
+ static private HttpApplicationFactory s_Factory = new
HttpApplicationFactory();
+#endif
+ public HttpApplicationFactory() {
+ _appInitialized = false;
+ _appFiredEnd = false;
+
+ _appFreePublicList = new Stack();
+ _appFreePublicInstances = 0;
+ }
+
+ static private string GetAppFilename (HttpContext context)
+ {
+ string physicalAppPath =
context.Request.PhysicalApplicationPath;
+ string appFilePath = Path.Combine (physicalAppPath,
"Global.asax");
+ if (File.Exists (appFilePath))
+ return appFilePath;
+
+ return Path.Combine (physicalAppPath, "global.asax");
+ }
+#if TARGET_J2EE
+ void CompileApp(HttpContext context)
+ {
+
+ try
+ {
+ String url =
IAppDomainConfig.WAR_ROOT_SYMBOL+"/global.asax";
+ _appType =
System.Web.GH.PageMapper.GetObjectType(url);
+ }
+ catch (Exception e)
+ {
+ _appType = typeof (System.Web.HttpApplication);
+ }
+ _state = new HttpApplicationState ();
+
+ }
+#endif
+
+#if !TARGET_J2EE
void CompileApp (HttpContext context)
{
if (File.Exists (_appFilename)) {
@@ -92,62 +127,63 @@
_state = new HttpApplicationState ();
}
}
+#endif
- static bool IsEventHandler (MethodInfo m)
- {
- if (m.ReturnType != typeof (void))
- return false;
-
- ParameterInfo [] pi = m.GetParameters ();
- int length = pi.Length;
- if (length == 0)
- return true;
-
- if (length != 2)
- return false;
-
- if (pi [0].ParameterType != typeof (object) ||
- pi [1].ParameterType != typeof (EventArgs))
- return false;
-
- return true;
- }
-
- static void AddEvent (MethodInfo method, Hashtable
appTypeEventHandlers)
- {
- string name = method.Name.Replace ("_On", "_");
- if (appTypeEventHandlers [name] == null) {
- appTypeEventHandlers [name] = method;
- return;
- }
-
- ArrayList list;
- if (appTypeEventHandlers [name] is MethodInfo)
- list = new ArrayList ();
- else
- list = appTypeEventHandlers [name] as ArrayList;
-
- list.Add (method);
- }
-
- static Hashtable GetApplicationTypeEvents (HttpApplication app)
- {
- Type appType = app.GetType ();
- Hashtable appTypeEventHandlers = new Hashtable ();
- BindingFlags flags = BindingFlags.Public |
- BindingFlags.NonPublic |
- BindingFlags.Instance |
- BindingFlags.Static;
-
- MethodInfo [] methods = appType.GetMethods (flags);
- foreach (MethodInfo m in methods) {
- if (IsEventHandler (m))
- AddEvent (m, appTypeEventHandlers);
- }
-
- return appTypeEventHandlers;
- }
+ static bool IsEventHandler (MethodInfo m)
+ {
+ if (m.ReturnType != typeof (void))
+ return false;
+ ParameterInfo [] pi = m.GetParameters ();
+ int length = pi.Length;
+ if (length == 0)
+ return true;
+
+ if (length != 2)
+ return false;
+
+ if (pi [0].ParameterType != typeof (object) ||
+ pi [1].ParameterType != typeof (EventArgs))
+ return false;
+
+ return true;
+ }
+
+ static void AddEvent (MethodInfo method, Hashtable
appTypeEventHandlers)
+ {
+ string name = method.Name.Replace ("_On", "_");
+ if (appTypeEventHandlers [name] == null) {
+ appTypeEventHandlers [name] = method;
+ return;
+ }
+
+ ArrayList list;
+ if (appTypeEventHandlers [name] is MethodInfo)
+ list = new ArrayList ();
+ else
+ list = appTypeEventHandlers [name] as ArrayList;
+
+ list.Add (method);
+ }
+
+ static Hashtable GetApplicationTypeEvents (HttpApplication app)
+ {
+ Type appType = app.GetType ();
+ Hashtable appTypeEventHandlers = new Hashtable ();
+ BindingFlags flags = BindingFlags.Public |
+ BindingFlags.NonPublic |
+ BindingFlags.Instance |
+ BindingFlags.Static;
+
+ MethodInfo [] methods = appType.GetMethods (flags);
+ foreach (MethodInfo m in methods) {
+ if (IsEventHandler (m))
+ AddEvent (m, appTypeEventHandlers);
+ }
+
+ return appTypeEventHandlers;
+ }
+
static bool FireEvent (string method_name, object target,
object [] args)
{
Hashtable possibleEvents = GetApplicationTypeEvents
((HttpApplication) target);
@@ -166,10 +202,10 @@
return true;
}
- internal static void FireOnAppStart (HttpApplication app)
+ internal static void FireOnAppStart (HttpApplication app)
{
- object [] args = new object [] {app, EventArgs.Empty};
- FireEvent ("Application_Start", app, args);
+ object [] args = new object [] {app, EventArgs.Empty};
+ FireEvent ("Application_Start", app, args);
}
void FireOnAppEnd ()
@@ -206,18 +242,18 @@
HttpRuntime.UnloadAppDomain ();
}
- private void InitializeFactory (HttpContext context)
- {
- _appFilename = GetAppFilename (context);
-
- CompileApp (context);
-
- // Create a application object
- HttpApplication app = (HttpApplication)
HttpRuntime.CreateInternalObject (_appType);
-
- // Startup
- app.Startup(context,
HttpApplicationFactory.ApplicationState);
+ private void InitializeFactory (HttpContext context)
+ {
+ _appFilename = GetAppFilename (context);
+ CompileApp (context);
+
+ // Create a application object
+ HttpApplication app = (HttpApplication)
HttpRuntime.CreateInternalObject (_appType);
+
+ // Startup
+ app.Startup(context,
HttpApplicationFactory.ApplicationState);
+
// Shutdown the application if bin directory changes.
string binFiles = HttpRuntime.BinDirectory;
if (Directory.Exists (binFiles))
@@ -225,189 +261,218 @@
binWatcher = CreateWatcher (binFiles, new
FileSystemEventHandler (OnAppFileChanged));
- // Fire OnAppStart
- HttpApplicationFactory.FireOnAppStart (app);
-
- // Recycle our application instance
- RecyclePublicInstance(app);
- }
-
- private void Dispose() {
- ArrayList torelease = new ArrayList();
- lock (_appFreePublicList) {
- while (_appFreePublicList.Count > 0) {
- torelease.Add(_appFreePublicList.Pop());
- _appFreePublicInstances--;
- }
- }
-
- if (torelease.Count > 0) {
- foreach (Object obj in torelease) {
- ((HttpApplication) obj).Cleanup();
- }
- }
-
- if (!_appFiredEnd) {
- lock (this) {
- if (!_appFiredEnd) {
- FireOnAppEnd();
- _appFiredEnd = true;
- }
- }
- }
- }
-
- internal static IHttpHandler GetInstance(HttpContext context)
- {
- if (custApplication != null)
- return custApplication;
-
- if (!s_Factory._appInitialized) {
- lock (s_Factory) {
- if (!s_Factory._appInitialized) {
-
s_Factory.InitializeFactory(context);
- s_Factory._appInitialized =
true;
- }
- }
- }
-
- return s_Factory.GetPublicInstance(context);
- }
-
- internal static void RecycleInstance(HttpApplication app) {
- if (!s_Factory._appInitialized)
- throw new InvalidOperationException("Factory
not intialized");
-
- s_Factory.RecyclePublicInstance(app);
- }
-
- internal static void AttachEvents (HttpApplication app)
- {
- Hashtable possibleEvents = GetApplicationTypeEvents
(app);
- foreach (string key in possibleEvents.Keys) {
- int pos = key.IndexOf ('_');
- if (pos == -1 || key.Length <= pos + 1)
- continue;
-
- string moduleName = key.Substring (0, pos);
- object target;
- if (moduleName == "Application") {
- target = app;
- } else {
- target = app.Modules [moduleName];
- if (target == null)
- continue;
- }
-
- string eventName = key.Substring (pos + 1);
- EventInfo evt = target.GetType ().GetEvent
(eventName);
- if (evt == null)
- continue;
-
- string usualName = moduleName + "_" + eventName;
- object methodData = possibleEvents [usualName];
- if (methodData == null)
- continue;
-
- if (methodData is MethodInfo) {
- AddHandler (evt, target, app,
(MethodInfo) methodData);
- continue;
- }
-
- ArrayList list = (ArrayList) methodData;
- foreach (MethodInfo method in list)
- AddHandler (evt, target, app, method);
- }
- }
-
- static void AddHandler (EventInfo evt, object target,
HttpApplication app, MethodInfo method)
- {
- int length = method.GetParameters ().Length;
-
- if (length == 0) {
- NoParamsInvoker npi = new NoParamsInvoker (app,
method.Name);
- evt.AddEventHandler (target, npi.FakeDelegate);
- } else {
- evt.AddEventHandler (target,
Delegate.CreateDelegate (
- typeof (EventHandler),
app, method.Name));
- }
- }
-
- private IHttpHandler GetPublicInstance(HttpContext context) {
- HttpApplication app = null;
-
- lock (_appFreePublicList) {
- if (_appFreePublicInstances > 0) {
- app = (HttpApplication)
_appFreePublicList.Pop();
- _appFreePublicInstances--;
- }
- }
-
- if (app == null) {
- // Create non-public object
- app = (HttpApplication)
HttpRuntime.CreateInternalObject(_appType);
-
- app.Startup(context,
HttpApplicationFactory.ApplicationState);
- }
-
- return (IHttpHandler) app;
- }
-
- internal void RecyclePublicInstance(HttpApplication app) {
- lock (_appFreePublicList) {
- if (_appFreePublicInstances <
_appMaxFreePublicInstances) {
- _appFreePublicList.Push(app);
- _appFreePublicInstances++;
-
- app = null;
- }
- }
-
- if (app != null) {
- app.Cleanup();
- }
- }
-
- static HttpStaticObjectsCollection MakeStaticCollection
(ArrayList list)
- {
- if (list == null || list.Count == 0)
- return null;
-
- HttpStaticObjectsCollection coll = new
HttpStaticObjectsCollection ();
- foreach (ObjectTagBuilder tag in list) {
- coll.Add (tag);
- }
-
- return coll;
- }
-
- static internal HttpApplicationState ApplicationState {
- get {
- if (null == s_Factory._state) {
- HttpStaticObjectsCollection app =
MakeStaticCollection (GlobalAsaxCompiler.ApplicationObjects);
- HttpStaticObjectsCollection ses =
MakeStaticCollection (GlobalAsaxCompiler.SessionObjects);
- s_Factory._state = new
HttpApplicationState (app, ses);
- }
-
- return s_Factory._state;
- }
- }
-
- internal static void EndApplication() {
- s_Factory.Dispose();
- }
-
- public static void SetCustomApplication (IHttpHandler
customApplication)
- {
- custApplication = customApplication;
- }
-
- internal Type AppType {
- get { return _appType; }
- }
-
- internal static void SignalError(Exception exc) {
- // TODO: Raise an error (we probably don't have a
HttpContext)
- }
- }
-}
+ // Fire OnAppStart
+ HttpApplicationFactory.FireOnAppStart (app);
+
+ // Recycle our application instance
+ RecyclePublicInstance(app);
+ }
+
+ private void Dispose() {
+ ArrayList torelease = new ArrayList();
+ lock (_appFreePublicList) {
+ while (_appFreePublicList.Count > 0) {
+ torelease.Add(_appFreePublicList.Pop());
+ _appFreePublicInstances--;
+ }
+ }
+
+ if (torelease.Count > 0) {
+ foreach (Object obj in torelease) {
+ ((HttpApplication) obj).Cleanup();
+ }
+ }
+
+ if (!_appFiredEnd) {
+ lock (this) {
+ if (!_appFiredEnd) {
+ FireOnAppEnd();
+ _appFiredEnd = true;
+ }
+ }
+ }
+ }
+
+ internal static IHttpHandler GetInstance(HttpContext context)
+ {
+ if (custApplication != null)
+ return custApplication;
+
+ if (!s_Factory._appInitialized) {
+ lock (s_Factory) {
+ if (!s_Factory._appInitialized) {
+
s_Factory.InitializeFactory(context);
+ s_Factory._appInitialized =
true;
+ }
+ }
+ }
+
+ return s_Factory.GetPublicInstance(context);
+ }
+
+ internal static void RecycleInstance(HttpApplication app) {
+ if (!s_Factory._appInitialized)
+ throw new InvalidOperationException("Factory
not intialized");
+
+ s_Factory.RecyclePublicInstance(app);
+ }
+
+ internal static void AttachEvents (HttpApplication app)
+ {
+ Hashtable possibleEvents = GetApplicationTypeEvents
(app);
+ foreach (string key in possibleEvents.Keys) {
+ int pos = key.IndexOf ('_');
+ if (pos == -1 || key.Length <= pos + 1)
+ continue;
+
+ string moduleName = key.Substring (0, pos);
+ object target;
+ if (moduleName == "Application") {
+ target = app;
+ } else {
+ target = app.Modules [moduleName];
+ if (target == null)
+ continue;
+ }
+
+ string eventName = key.Substring (pos + 1);
+ EventInfo evt = target.GetType ().GetEvent
(eventName);
+ if (evt == null)
+ continue;
+
+ string usualName = moduleName + "_" + eventName;
+ object methodData = possibleEvents [usualName];
+ if (methodData == null)
+ continue;
+
+ if (methodData is MethodInfo) {
+ AddHandler (evt, target, app,
(MethodInfo) methodData);
+ continue;
+ }
+
+ ArrayList list = (ArrayList) methodData;
+ foreach (MethodInfo method in list)
+ AddHandler (evt, target, app, method);
+ }
+ }
+
+ static void AddHandler (EventInfo evt, object target,
HttpApplication app, MethodInfo method)
+ {
+ int length = method.GetParameters ().Length;
+
+ if (length == 0) {
+ NoParamsInvoker npi = new NoParamsInvoker (app,
method.Name);
+ evt.AddEventHandler (target, npi.FakeDelegate);
+ } else {
+ evt.AddEventHandler (target,
Delegate.CreateDelegate (
+ typeof (EventHandler),
app, method.Name));
+ }
+ }
+
+#if TARGET_J2EE
+ internal HttpApplication GetPublicInstance()
+ {
+ HttpApplication app = null;
+
+ lock (_appFreePublicList)
+ {
+ if (_appFreePublicInstances > 0)
+ {
+ app = (HttpApplication)
_appFreePublicList.Pop();
+ _appFreePublicInstances--;
+ }
+ }
+ return app;
+ }
+#endif
+
+ private IHttpHandler GetPublicInstance(HttpContext context) {
+ HttpApplication app = null;
+
+ lock (_appFreePublicList) {
+ if (_appFreePublicInstances > 0) {
+ app = (HttpApplication)
_appFreePublicList.Pop();
+ _appFreePublicInstances--;
+ }
+ }
+
+ if (app == null) {
+ // Create non-public object
+ app = (HttpApplication)
HttpRuntime.CreateInternalObject(_appType);
+
+ app.Startup(context,
HttpApplicationFactory.ApplicationState);
+ }
+
+ return (IHttpHandler) app;
+ }
+
+ internal void RecyclePublicInstance(HttpApplication app) {
+ lock (_appFreePublicList) {
+ if (_appFreePublicInstances <
_appMaxFreePublicInstances) {
+ _appFreePublicList.Push(app);
+ _appFreePublicInstances++;
+
+ app = null;
+ }
+ }
+
+ if (app != null) {
+ app.Cleanup();
+ }
+ }
+
+ static HttpStaticObjectsCollection MakeStaticCollection
(ArrayList list)
+ {
+ if (list == null || list.Count == 0)
+ return null;
+
+ HttpStaticObjectsCollection coll = new
HttpStaticObjectsCollection ();
+ foreach (ObjectTagBuilder tag in list) {
+ coll.Add (tag);
+ }
+
+ return coll;
+ }
+
+ static internal HttpApplicationState ApplicationState {
+#if TARGET_J2EE
+ get {
+ if (null == s_Factory._state) {
+ HttpStaticObjectsCollection app = null;
+ HttpStaticObjectsCollection ses = null;
+ s_Factory._state = new
HttpApplicationState (app, ses);
+ }
+
+ return s_Factory._state;
+ }
+#else
+ get {
+ if (null == s_Factory._state) {
+ HttpStaticObjectsCollection app =
MakeStaticCollection (GlobalAsaxCompiler.ApplicationObjects);
+ HttpStaticObjectsCollection ses =
MakeStaticCollection (GlobalAsaxCompiler.SessionObjects);
+ s_Factory._state = new
HttpApplicationState (app, ses);
+ }
+
+ return s_Factory._state;
+ }
+#endif
+ }
+
+ internal static void EndApplication() {
+ s_Factory.Dispose();
+ }
+
+ public static void SetCustomApplication (IHttpHandler
customApplication)
+ {
+ custApplication = customApplication;
+ }
+
+ internal Type AppType {
+ get { return _appType; }
+ }
+
+ internal static void SignalError(Exception exc) {
+ // TODO: Raise an error (we probably don't have a
HttpContext)
+ }
+ }
+}
Modified: trunk/mcs/class/System.Web/System.Web/HttpContext.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web/HttpContext.cs 2005-06-19
09:09:48 UTC (rev 46204)
+++ trunk/mcs/class/System.Web/System.Web/HttpContext.cs 2005-06-19
09:19:18 UTC (rev 46205)
@@ -65,6 +65,10 @@
string errorPage;
IPrincipal user;
+#if TARGET_J2EE
+ private object LOCK = new object();
+#endif
+
#if NET_2_0
private System.Web.UI.Page lastPage;
#endif
@@ -202,13 +206,33 @@
}
}
+#if TARGET_J2EE
public bool IsDebuggingEnabled
{
get {
+ return false;
+ }
+ }
+#else
+ public bool IsDebuggingEnabled
+ {
+ get {
return CompilationConfiguration.GetInstance
(this).Debug;
}
}
+#endif
+#if TARGET_J2EE
+ private bool _timedOut;
+ internal bool TimedOut {
+ get {
+ return _timedOut;
+ }
+ set {
+ _timedOut = value;
+ }
+ }
+#endif
public IDictionary Items
{
get {
@@ -280,16 +304,32 @@
set { user = value; }
}
+#if TARGET_J2EE
internal bool TimeoutPossible {
+ get { return (timeoutPossible==1);}
+ }
+ internal void EndTimeoutPossible () {
+ timeoutPossible = 0;
+ }
+ internal void TryWaitForTimeout () {
+ while (TimeoutPossible) {
+ Thread.Sleep (500);
+ }
+ }
+#endif
+
+#if !TARGET_J2EE
+ internal bool TimeoutPossible {
get { return (Interlocked.CompareExchange (ref
timeoutPossible, 1, 1) == 1); }
}
-
+#endif
internal void BeginTimeoutPossible ()
{
timeoutPossible = 1;
timeoutBegin = DateTime.UtcNow.Ticks;
}
+#if !TARGET_J2EE
internal void EndTimeoutPossible ()
{
Interlocked.CompareExchange (ref timeoutPossible, 0, 1);
@@ -301,6 +341,7 @@
Thread.Sleep (500);
}
}
+#endif
internal bool CheckIfTimeout (DateTime dt)
{
Modified: trunk/mcs/class/System.Web/System.Web/HttpException.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web/HttpException.cs 2005-06-19
09:09:48 UTC (rev 46204)
+++ trunk/mcs/class/System.Web/System.Web/HttpException.cs 2005-06-19
09:19:18 UTC (rev 46205)
@@ -34,8 +34,10 @@
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
using System.Text;
+using System.Web.Util;
+#if !TARGET_J2EE
using System.Web.Compilation;
-using System.Web.Util;
+#endif
namespace System.Web
{
@@ -133,11 +135,17 @@
builder.Append ("<table summary=\"Stack Trace\"
width=\"100%\" " +
"bgcolor=\"#ffffc\">\r\n<tr><td>");
WriteTextAsCode (builder,
InnerException.ToString ());
+#if TARGET_J2EE //Required, because toString of Java doesn't print stackTrace
+ WriteTextAsCode (builder,
InnerException.StackTrace);
+#endif
builder.Append
("</td></tr>\r\n</table>\r\n<p>\r\n");
}
builder.Append ("<hr>\r\n</body>\r\n</html>\r\n");
builder.AppendFormat ("<!--\r\n{0}\r\n-->\r\n",
HttpUtility.HtmlEncode (this.ToString ()));
+#if TARGET_J2EE //Required, because toString of Java doesn't print stackTrace
+ builder.AppendFormat ("<!--\r\n{0}\r\n-->\r\n",
HttpUtility.HtmlEncode (this.StackTrace));
+#endif
return builder.ToString ();
}
@@ -150,7 +158,44 @@
string res = HttpUtility.HtmlEncode (s);
return res.Replace ("\r\n", "<br />");
}
+#if TARGET_J2EE
+ string GetHtmlizedErrorMessage ()
+ {
+ StringBuilder builder = new StringBuilder
("<html>\r\n<title>");
+ HtmlizedException exc = (HtmlizedException)
this.InnerException;
+ builder.Append (exc.Title);
+ builder.AppendFormat ("</title><body
bgcolor=\"white\">" +
+ "<h1><font color=\"red\">Server
Error in '{0}' " +
+ "Application</font></h1><hr>\r\n",
+
HttpRuntime.AppDomainAppVirtualPath);
+ builder.AppendFormat ("<h2><font
color=\"maroon\"><i>{0}</i></font></h2>\r\n", exc.Title);
+ builder.AppendFormat ("<b>Description:
</b>{0}\r\n<p>\r\n", HtmlEncode (exc.Description));
+ builder.AppendFormat ("<b>Error message:
</b>{0}\r\n<p>\r\n", HtmlEncode (exc.ErrorMessage));
+
+ if (exc.FileName != null)
+ builder.AppendFormat ("<b>File name: </b> {0}",
HtmlEncode (exc.FileName));
+
+ if (exc.FileText != null) {
+ if (exc.SourceFile != exc.FileName)
+ builder.AppendFormat ("<p><b>Source
File: </b>{0}", exc.SourceFile);
+
+ builder.Append ("\r\n<p>\r\n");
+
+ builder.Append ("<table summary=\"Source file\"
width=\"100%\" " +
+
"bgcolor=\"#ffffc\">\r\n<tr><td>");
+ WriteSource (builder, exc);
+ builder.Append
("</td></tr>\r\n</table>\r\n<p>\r\n");
+ }
+
+ builder.Append ("<hr>\r\n</body>\r\n</html>\r\n");
+ builder.AppendFormat ("<!--\r\n{0}\r\n-->\r\n",
HtmlEncode (exc.ToString ()));
+ builder.AppendFormat ("<!--\r\n{0}\r\n-->\r\n",
HtmlEncode (exc.StackTrace));
+ return builder.ToString ();
+ }
+#endif
+
+#if !TARGET_J2EE
string GetHtmlizedErrorMessage ()
{
StringBuilder builder = new StringBuilder
("<html>\r\n<title>");
@@ -197,7 +242,7 @@
builder.AppendFormat ("<!--\r\n{0}\r\n-->\r\n",
HtmlEncode (exc.ToString ()));
return builder.ToString ();
}
-
+#endif
static void WriteTextAsCode (StringBuilder builder, string text)
{
builder.Append ("<code><pre>\r\n");
@@ -205,9 +250,20 @@
builder.Append ("</pre></code>\r\n");
}
+#if TARGET_J2EE
static void WriteSource (StringBuilder builder,
HtmlizedException e)
{
builder.Append ("<code><pre>");
+ WritePageSource (builder, e);
+ builder.Append ("</pre></code>\r\n");
+ }
+
+#endif
+
+#if !TARGET_J2EE
+ static void WriteSource (StringBuilder builder,
HtmlizedException e)
+ {
+ builder.Append ("<code><pre>");
if (e is CompilationException)
WriteCompilationSource (builder, e);
else
@@ -215,6 +271,7 @@
builder.Append ("</pre></code>\r\n");
}
+#endif
static void WriteCompilationSource (StringBuilder builder,
HtmlizedException e)
{
Modified: trunk/mcs/class/System.Web/System.Web/HttpRequest.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web/HttpRequest.cs 2005-06-19
09:09:48 UTC (rev 46204)
+++ trunk/mcs/class/System.Web/System.Web/HttpRequest.cs 2005-06-19
09:19:18 UTC (rev 46205)
@@ -38,6 +38,10 @@
using System.Web.Configuration;
using System.Web.Util;
+#if TARGET_J2EE
+using vmw.common;
+#endif
+
namespace System.Web {
[MonoTODO("Review security in all path access function")]
public sealed class HttpRequest {
@@ -98,6 +102,9 @@
bool checkedQueryString;
#endif
+#if TARGET_J2EE
+ private string _sGhFilePath;
+#endif
public HttpRequest(string Filename, string Url, string
Querystring) {
_iContentLength = -1;
_iTotalBytes = -1;
@@ -578,6 +585,25 @@
}
}
+#if TARGET_J2EE
+ internal string GhFilePath {
+ get {
+ if (null == _sGhFilePath) {
+ _sGhFilePath = FilePath;
+ if (_sGhFilePath == null)
+ return null;
+
+ if
(_sGhFilePath.StartsWith(IAppDomainConfig.WAR_ROOT_SYMBOL))
+ _sGhFilePath =
_sGhFilePath.Substring(IAppDomainConfig.WAR_ROOT_SYMBOL.Length);
+ if
(_sGhFilePath.StartsWith(HttpRuntime.AppDomainAppVirtualPath))
+ _sGhFilePath =
_sGhFilePath.Substring(HttpRuntime.AppDomainAppVirtualPath.Length);
+ }
+
+ return _sGhFilePath;
+ }
+ }
+#endif
+
HttpFileCollection files;
public HttpFileCollection Files {
get {
@@ -1120,6 +1146,15 @@
if (_WorkerRequest == null)
throw new HttpException ("No
HttpWorkerRequest!!!");
+#if TARGET_J2EE
+ if (baseVirtualDir.Equals(BaseVirtualDir))
+ {
+ string val =
System.Web.GH.PageMapper.GetFromMapPathCache(virtualPath);
+ if (val != null)
+ return val;
+ }
+#endif
+
if (virtualPath == null || virtualPath.Length == 0)
virtualPath = ".";
else
@@ -1127,7 +1162,10 @@
if (virtualPath.IndexOf (':') != -1)
throw new ArgumentException ("Invalid path -> "
+ virtualPath);
-
+#if TARGET_J2EE
+ if
(virtualPath.StartsWith(IAppDomainConfig.WAR_ROOT_SYMBOL))
+ return virtualPath;
+#endif
if (System.IO.Path.DirectorySeparatorChar != '/')
virtualPath = virtualPath.Replace
(System.IO.Path.DirectorySeparatorChar, '/');
Modified: trunk/mcs/class/System.Web/System.Web/HttpResponse.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web/HttpResponse.cs 2005-06-19
09:09:48 UTC (rev 46204)
+++ trunk/mcs/class/System.Web/System.Web/HttpResponse.cs 2005-06-19
09:19:18 UTC (rev 46205)
@@ -113,6 +113,12 @@
_WorkerRequest = WorkerRequest;
}
+#if TARGET_J2EE
+ public HttpWorkerRequest WorkerRequest{
+ get{ return _WorkerRequest; }
+ }
+#endif
+
internal void InitializeWriter ()
{
// We cannot do this in the .ctor because HttpWriter
uses configuration and
@@ -156,6 +162,8 @@
ArrayList oHeaders = new ArrayList (_Headers);
oHeaders.Add (new HttpResponseHeader ("X-Powered-By",
"Mono"));
+
+#if !TARGET_J2EE
string date = DateTime.UtcNow.ToString ("ddd, d MMM
yyyy HH:mm:ss ", CultureInfo.InvariantCulture);
HttpResponseHeader date_header = new HttpResponseHeader
("Date", date + "GMT");
oHeaders.Add (date_header);
@@ -167,6 +175,7 @@
oHeaders.Add (new HttpResponseHeader
(HttpWorkerRequest.HeaderContentLength,
_lContentLength.ToString ()));
}
+#endif
// Apache2 only auto-adds 'charset=blah' for text/plain
and text/html
if (_sContentType != null) {
@@ -229,7 +238,11 @@
foreach (HttpResponseHeader oHeader in oHeaders)
oHeader.SendContent (_WorkerRequest);
+#if !TARGET_J2EE //in J2EE env. we are setting headers into
+ //HttpServletResponse instance -> headers are
+ //still not sent
_bHeadersSent = true;
+#endif
}
public string Status
@@ -737,7 +750,11 @@
return;
if (_Context.TimeoutPossible)
+#if !TARGET_J2EE
Thread.CurrentThread.Abort (new
StepCompleteRequest ());
+#else
+ throw new [EMAIL PROTECTED]();
+#endif
Flush ();
_bEnded = true;
@@ -981,6 +998,11 @@
public void WriteFile (string filename, bool readIntoMemory)
{
+#if TARGET_J2EE
+ if ((this.Request != null) && ((filename.Length <= 2)
+ || ((filename[0] != '\\') &&
(filename[1] != ':'))))
+ filename = Request.MapPath(filename);
+#endif
FileStream fs = null;
try {
fs = File.OpenRead (filename);
@@ -999,6 +1021,11 @@
public void WriteFile (string filename, long offset, long size)
{
FileStream fs = null;
+#if TARGET_J2EE
+ if ((this.Request != null) && ((filename.Length <= 2)
+ || ((filename[0] != '\\') && (filename[1] !=
':'))))
+ filename = Request.MapPath(filename);
+#endif
try {
fs = File.OpenRead (filename);
WriteFromStream (fs, offset, size, 30702);
@@ -1023,6 +1050,9 @@
[MonoTODO()]
internal void OnCookieAdd (HttpCookie cookie)
{
+#if TARGET_J2EE //naive implementation
+ Request.Cookies.Add(cookie);
+#endif
}
[MonoTODO("Do we need this?")]
Modified: trunk/mcs/class/System.Web/System.Web/HttpRuntime.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web/HttpRuntime.cs 2005-06-19
09:09:48 UTC (rev 46204)
+++ trunk/mcs/class/System.Web/System.Web/HttpRuntime.cs 2005-06-19
09:19:18 UTC (rev 46205)
@@ -51,11 +51,30 @@
private static IStackWalk unrestrictedStackWalk;
private static IStackWalk reflectionStackWalk;
+#if !TARGET_JVM
private static HttpRuntime _runtime;
private static string appDomainAppId;
private static string appDomainId;
private static string appDomainAppPath;
private static string appDomainAppVirtualPath;
+#else
+ private static object _ghLock = new object();
+ static private HttpRuntime _runtime {
+ get {
+ HttpRuntime runtime =
(HttpRuntime)AppDomain.CurrentDomain.GetData("HttpRuntime");
+ if (runtime == null)
+ lock (_ghLock) {
+ runtime =
(HttpRuntime)AppDomain.CurrentDomain.GetData("HttpRuntime");
+ if (runtime == null) {
+ runtime = new
HttpRuntime();
+ runtime.Init();
+
AppDomain.CurrentDomain.SetData("HttpRuntime", runtime);
+ }
+ }
+ return runtime;
+ }
+ }
+#endif
private Cache _cache;
private int _activeRequests;
@@ -73,11 +92,13 @@
private WaitCallback doRequestCallback;
private int pendingCallbacks;
+#if !TARGET_JVM
static HttpRuntime ()
{
_runtime = new HttpRuntime ();
_runtime.Init();
}
+#endif
public HttpRuntime ()
{
@@ -253,9 +274,8 @@
WaitForRequests (2000);
queueManager.Dispose (); // Send a 503 to all queued
requests
queueManager = null;
-
_cache = null;
- HttpApplicationFactory.EndApplication ();
+ HttpApplicationFactory.EndApplication();
}
void OnDomainUnload (object o, EventArgs args)
@@ -372,7 +392,24 @@
}
}
+#if TARGET_JVM
public static string AppDomainAppId {
+ get { return (string) AppDomain.CurrentDomain.GetData
(".appId"); }
+ }
+
+ public static string AppDomainAppPath {
+ get { return (string) AppDomain.CurrentDomain.GetData
(".appPath"); }
+ }
+
+ public static string AppDomainAppVirtualPath {
+ get { return (string) AppDomain.CurrentDomain.GetData
(".appVPath"); }
+ }
+
+ public static string AppDomainId {
+ get { return (string) AppDomain.CurrentDomain.GetData
(".domainId"); }
+ }
+#else
+ public static string AppDomainAppId {
get {
if (appDomainAppId == null)
appDomainAppId = (string)
AppDomain.CurrentDomain.GetData (".appId");
@@ -407,6 +444,7 @@
return appDomainId;
}
}
+#endif
public static string AspInstallDirectory {
get {
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches