Author: svetlana
Date: 2005-11-06 05:47:25 -0500 (Sun, 06 Nov 2005)
New Revision: 52620

Added:
   
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/HttpRemotingHandlerFactory.jvm.cs
Modified:
   
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/ChangeLog
   
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/HttpRemotingHandler.cs
   
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/HttpRemotingHandlerFactory.cs
   
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/HttpServerChannel.cs
Log:
Fix HttpHandler, HttpHandlerFactory and HttpServerChannel to work properly with 
a web server hosted applications; Add HttpHandlerFactory.jvm.cs

Modified: 
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/ChangeLog
===================================================================
--- 
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/ChangeLog
     2005-11-06 09:39:13 UTC (rev 52619)
+++ 
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/ChangeLog
     2005-11-06 10:47:25 UTC (rev 52620)
@@ -1,3 +1,14 @@
+2005-11-06  Svetlana Zholkovsky  <[EMAIL PROTECTED]>
+
+    * Add HttpHandlerFactory.jvm.cs
+       * HttpHandlerFactory.cs: Create and register HttpChannel in case it 
+       was not registered before.
+       * HttpHandler.cs: Send response headers.
+       * HttpServerChannel.cs:
+         - Change default port to -1.
+         - Don't start a listener if the port == -1
+         - Send response to the client also in case of DispatchRequest fails
+
 2005-10-10  Lluis Sanchez Gual  <[EMAIL PROTECTED]>
 
        * HttpServer.cs: Removed all non-sense regular expressions for

Modified: 
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/HttpRemotingHandler.cs
===================================================================
--- 
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/HttpRemotingHandler.cs
        2005-11-06 09:39:13 UTC (rev 52619)
+++ 
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/HttpRemotingHandler.cs
        2005-11-06 10:47:25 UTC (rev 52620)
@@ -32,6 +32,7 @@
 using System;
 using System.IO;
 using System.Web;
+using System.Collections;
 
 namespace System.Runtime.Remoting.Channels.Http 
 {
@@ -69,7 +70,12 @@
 
                        string objectUri = request.RawUrl;
                        objectUri = objectUri.Substring 
(request.ApplicationPath.Length);       // application path is not part of the 
uri
-                       
+                       if (request.ApplicationPath.Length > 0 && 
+                          (objectUri.StartsWith("/") || 
objectUri.StartsWith(@"\")) )
+                       {
+                               objectUri = objectUri.Substring(1);
+                       }
+
                        theaders ["__RequestUri"] = objectUri;
                        theaders ["Content-Type"] = request.ContentType;
                        theaders ["__RequestVerb"]= request.HttpMethod;
@@ -93,6 +99,16 @@
                                response.StatusDescription = (string) 
responseHeaders["__HttpReasonPhrase"];
                        }
                        
+                       if (responseHeaders != null)
+                       {
+                               foreach (DictionaryEntry entry in 
responseHeaders)
+                               {
+                                       string key = entry.Key.ToString();
+                                       if (key != 
CommonTransportKeys.HttpStatusCode && key != 
CommonTransportKeys.HttpReasonPhrase)
+                                               response.AppendHeader(key, 
entry.Value.ToString());
+                               }
+                       }
+
                        byte[] bodyBuffer = bodyBuffer = new byte 
[responseStream.Length];
                        responseStream.Seek (0, SeekOrigin.Begin);
                        

Modified: 
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/HttpRemotingHandlerFactory.cs
===================================================================
--- 
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/HttpRemotingHandlerFactory.cs
 2005-11-06 09:39:13 UTC (rev 52619)
+++ 
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/HttpRemotingHandlerFactory.cs
 2005-11-06 10:47:25 UTC (rev 52620)
@@ -61,28 +61,42 @@
                        lock (GetType())
                        {
                                if (webConfigLoaded) return;
-                               
+                                                       
                                // Look for a channel that wants to receive 
http request
-                               
+                               IChannelReceiverHook chook = null;
                                foreach (IChannel channel in 
ChannelServices.RegisteredChannels)
                                {
-                                       IChannelReceiverHook chook = channel as 
IChannelReceiverHook;
+                                       chook = channel as IChannelReceiverHook;
                                        if (chook == null) continue;
                                        
                                        if (chook.ChannelScheme != "http")
                                                throw new RemotingException 
("Only http channels are allowed when hosting remoting objects in a web 
server");
                                        
-                                       if (!chook.WantsToListen) continue;
+                                       if (!chook.WantsToListen) 
+                                       {
+                                               chook = null;
+                                               continue;
+                                       }
                                        
-                                       // Register the uri for the channel. 
The channel uri includes the scheme, the
-                                       // host and the application path
+                                       //found chook
+                                       break;
+                               }
+
+                               if (chook == null)
+                               {
+                                       HttpChannel chan = new HttpChannel();
+                                       ChannelServices.RegisterChannel(chan);
+                                       chook = chan;
+                               }
                                        
-                                       string channelUrl = 
context.Request.Url.GetLeftPart(UriPartial.Authority);
-                                       channelUrl += 
context.Request.ApplicationPath;
-                                       chook.AddHookChannelUri (channelUrl);
+                               // Register the uri for the channel. The 
channel uri includes the scheme, the
+                               // host and the application path
                                        
-                                       transportSink = new 
HttpServerTransportSink (chook.ChannelSinkChain, null);
-                               }
+                               string channelUrl = 
context.Request.Url.GetLeftPart(UriPartial.Authority);
+                               channelUrl += context.Request.ApplicationPath;
+                               chook.AddHookChannelUri (channelUrl);
+                                       
+                               transportSink = new HttpServerTransportSink 
(chook.ChannelSinkChain, null);
                                webConfigLoaded = true;
                        }
                }

Added: 
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/HttpRemotingHandlerFactory.jvm.cs
===================================================================
--- 
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/HttpRemotingHandlerFactory.jvm.cs
     2005-11-06 09:39:13 UTC (rev 52619)
+++ 
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/HttpRemotingHandlerFactory.jvm.cs
     2005-11-06 10:47:25 UTC (rev 52620)
@@ -0,0 +1,128 @@
+//
+// System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory
+//
+// Authors:
+//      Martin Willemoes Hansen ([EMAIL PROTECTED])
+//      Lluis Sanchez Gual ([EMAIL PROTECTED])
+//
+// (C) 2003 Martin Willemoes Hansen
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System.Web;
+using System.IO;
+using System.Runtime.Remoting;
+using System.Runtime.Remoting.Channels;
+
+namespace System.Runtime.Remoting.Channels.Http 
+{
+       public class HttpRemotingHandlerFactory : IHttpHandlerFactory
+       {
+               public HttpRemotingHandlerFactory ()
+               {
+               }
+
+               private static HttpRemotingHandlerFactoryData 
CurrentHttpRemotingHandlerFactoryData
+               {
+                       get
+                       {
+                               HttpRemotingHandlerFactoryData res = 
(HttpRemotingHandlerFactoryData)AppDomain.CurrentDomain.GetData("HttpRemotingHandlerFactory");
+                               if (res == null) 
+                               {
+                                       res = new 
HttpRemotingHandlerFactoryData();
+                                       
AppDomain.CurrentDomain.SetData("HttpRemotingHandlerFactory", res);
+                               }
+                               return res;
+                       }
+               }
+               
+               public IHttpHandler GetHandler (HttpContext context,
+                                               string verb,
+                                               string url,
+                                               string filePath)
+               {
+                       if 
(!CurrentHttpRemotingHandlerFactoryData.webConfigLoaded)
+                               ConfigureHttpChannel (context);
+                       
+                       return new HttpRemotingHandler 
(CurrentHttpRemotingHandlerFactoryData.transportSink);
+               }
+               
+               void ConfigureHttpChannel (HttpContext context)
+               {
+                       lock (GetType())
+                       {
+                               if 
(CurrentHttpRemotingHandlerFactoryData.webConfigLoaded) return;
+                               
+                               // Look for a channel that wants to receive 
http request                                
+                               IChannelReceiverHook chook = null;
+                               foreach (IChannel channel in 
ChannelServices.RegisteredChannels)
+                               {
+                                       chook = channel as IChannelReceiverHook;
+                                       if (chook == null) continue;
+                                       
+                                       if (chook.ChannelScheme != "http")
+                                               throw new RemotingException 
("Only http channels are allowed when hosting remoting objects in a web 
server");
+                                       
+                                       if (!chook.WantsToListen) 
+                                       {
+                                               chook = null;
+                                               continue;
+                                       }
+
+                                       //found chook
+                                       break;
+                               }
+
+                               if (chook == null)
+                               {
+                                       HttpChannel chan = new HttpChannel();
+                                       ChannelServices.RegisterChannel(chan);
+                                       chook = chan;
+                               }
+                                       
+                               // Register the uri for the channel. The 
channel uri includes the scheme, the
+                               // host and the application path
+                                       
+                               string channelUrl = 
context.Request.Url.GetLeftPart(UriPartial.Authority);
+                               channelUrl += context.Request.ApplicationPath;
+                               chook.AddHookChannelUri (channelUrl);
+
+                               
CurrentHttpRemotingHandlerFactoryData.transportSink = new 
HttpServerTransportSink (chook.ChannelSinkChain, null);
+
+                               
CurrentHttpRemotingHandlerFactoryData.webConfigLoaded = true;
+                       }
+               }
+
+               public void ReleaseHandler (IHttpHandler handler)
+               {
+               }
+       }
+
+       internal class HttpRemotingHandlerFactoryData 
+       {
+
+               internal bool webConfigLoaded = false;
+               internal HttpServerTransportSink transportSink = null;
+               
+       }       
+}


Property changes on: 
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/HttpRemotingHandlerFactory.jvm.cs
___________________________________________________________________
Name: svn:executable
   + *

Modified: 
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/HttpServerChannel.cs
===================================================================
--- 
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/HttpServerChannel.cs
  2005-11-06 09:39:13 UTC (rev 52619)
+++ 
trunk/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Http/HttpServerChannel.cs
  2005-11-06 10:47:25 UTC (rev 52620)
@@ -58,7 +58,7 @@
                private int               _channelPriority = 1;  // priority of 
channel (default=1)
                private String            _channelName = "http"; // channel name
                private String            _machineName = null;   // machine name
-               private int               _port = 0;            // port to 
listen on
+               private int               _port = -1;            // port to 
listen on
                private ChannelDataStore  _channelData = null;   // channel data
                
                private bool _bUseIpAddress = true; // by default, we'll use 
the ip address.
@@ -77,6 +77,10 @@
 
                RemotingThreadPool threadPool;
 
+#if TARGET_JVM
+               private volatile bool stopped = false;
+#endif
+
                public HttpServerChannel() : base()
                {
                        SetupChannel(null,null);
@@ -182,7 +186,11 @@
                internal void Listen()
                {
                        try {
+       #if !TARGET_JVM
                                while(true)
+       #else
+                               while(!stopped)
+       #endif
                                {
                                        Socket socket = 
_tcpListener.AcceptSocket();
                                        RequestArguments request = new 
RequestArguments (socket, _transportSink);
@@ -194,8 +202,11 @@
 
                public void StartListening (Object data)
                {
-                       if (_bListening) return;
+                       if (_bListening || _port < 0) return;
                        
+#if TARGET_JVM
+                       stopped = false;
+#endif 
                        threadPool = RemotingThreadPool.GetSharedPool ();
                        
                        _tcpListener = new TcpListener (_bindToAddr, _port);
@@ -222,9 +233,16 @@
 
                public void StopListening(Object data)
                {
+#if TARGET_JVM
+                       stopped = true;
+#endif 
                        if( _bListening)
                        {
+#if !TARGET_JVM
                                _listenerThread.Abort ();
+#else
+                               _listenerThread.Interrupt ();
+#endif 
                                _tcpListener.Stop();
                                threadPool.Free ();
                                _listenerThread.Join ();
@@ -350,10 +368,12 @@
                        ITransportHeaders responseHeaders;
                        Stream responseStream;
 
+                       bool requestDispatched = false;
                        ServerProcessing processing;
                        try
                        {
                                processing = DispatchRequest (requestStream, 
headers, out responseStream, out responseHeaders);
+                               requestDispatched = true;
 
                                switch (processing)
                                {                    
@@ -371,6 +391,22 @@
                        }
                        catch (Exception ex)
                        {
+#if DEBUG
+                               Console.WriteLine("The exception was caught 
during HttpServerChannel.ServiceRequest: {0}, {1}", ex.GetType(), ex.Message);
+#endif
+                               if (!requestDispatched)
+                               {
+                                       try 
+                                       {
+                                               HttpServer.SendResponse 
(reqArg, 400, null, null);
+                                       }
+                                       catch (Exception e)
+                                       {
+#if DEBUG
+                                               Console.WriteLine("Fail to send 
response in HttpServerChannels.ServiceRequest: {0}, {1}", e.GetType(), 
e.Message);
+#endif
+                                       }
+                               }
                        }
                }
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to