Author: krasnov
Date: 2007-06-28 07:41:26 -0400 (Thu, 28 Jun 2007)
New Revision: 80960
Added:
trunk/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/OutputStreamWrapper.cs
Modified:
trunk/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/BaseHttpServlet.cs
trunk/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ChangeLog
trunk/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ServletWorkerRequest.jvm.cs
trunk/mcs/class/Mainsoft.Web/Mainsoft.Web.J2EE.csproj
Log:
* BaseHttpServlet.cs: fixed service(), it does not creates output stream now
* ServletWorkerRequest.jvm.cs: fixed ctor, bool parameter can force using
printWriter, used OutputStreamWrapper as OutputStream
* added OutputStreamWrapper class
Modified: trunk/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/BaseHttpServlet.cs
===================================================================
--- trunk/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/BaseHttpServlet.cs
2007-06-28 11:29:08 UTC (rev 80959)
+++ trunk/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/BaseHttpServlet.cs
2007-06-28 11:41:26 UTC (rev 80960)
@@ -124,10 +124,10 @@
}
}
resp.setContentType("text/html");
- service(req, resp, resp.getOutputStream());
+ service(req, resp, false);
}
- public virtual void service(HttpServletRequest req,
HttpServletResponse resp, java.io.OutputStream output)
+ public virtual void service(HttpServletRequest req,
HttpServletResponse resp, bool alwaysUsePrintWriter)
{
try
{
@@ -152,7 +152,7 @@
resp.setHeader("X-Powered-By", "ASP.NET");
resp.setHeader("X-AspNet-Version", "1.1.4322");
- HttpWorkerRequest gwr = new
ServletWorkerRequest(this, req, resp, output);
+ HttpWorkerRequest gwr = new
ServletWorkerRequest (this, req, resp, alwaysUsePrintWriter);
CultureInfo culture = (CultureInfo) [EMAIL
PROTECTED] (req.getLocale ());
Thread currentTread = Thread.CurrentThread;
currentTread.CurrentCulture = culture;
Modified: trunk/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ChangeLog
===================================================================
--- trunk/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ChangeLog 2007-06-28
11:29:08 UTC (rev 80959)
+++ trunk/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ChangeLog 2007-06-28
11:41:26 UTC (rev 80960)
@@ -1,3 +1,11 @@
+2007-06-28 Vladimir Krasnov <[EMAIL PROTECTED]>
+
+ * BaseHttpServlet.cs: fixed service(), it does not creates output
+ stream now
+ * ServletWorkerRequest.jvm.cs: fixed ctor, bool parameter can force
using
+ printWriter, used OutputStreamWrapper as OutputStream
+ * added OutputStreamWrapper class
+
2007-05-15 Eyal Alaluf <[EMAIL PROTECTED]>
* IncludeHelperServlet.cs: Add System.Web.GH.IncludeHelperServlet for
Added: trunk/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/OutputStreamWrapper.cs
===================================================================
--- trunk/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/OutputStreamWrapper.cs
2007-06-28 11:29:08 UTC (rev 80959)
+++ trunk/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/OutputStreamWrapper.cs
2007-06-28 11:41:26 UTC (rev 80960)
@@ -0,0 +1,182 @@
+//
+// Mainsoft.Web.Hosting.OutputStreamWrapper
+//
+// Authors:
+// Vladimir Krasnov ([EMAIL PROTECTED])
+//
+// (C) 2006 Mainsoft
+//
+//
+// 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;
+using System.Web;
+using System.Collections.Generic;
+using System.Text;
+
+using java.io;
+using vmw.common;
+
+
+namespace Mainsoft.Web.Hosting
+{
+ /// <summary>
+ ///
+ /// </summary>
+ internal sealed class OutputStreamWrapper : java.io.Writer
+ {
+ enum OutputMode
+ {
+ CharWriter,
+ ByteStream,
+ }
+
+ readonly PrintWriter _printWriter;
+ readonly OutputStream _outputStream;
+ readonly OutputMode _outputMode;
+
+ private byte [] _bytebuffer = new byte [1024];
+ private char [] _charBuffer = new char [1024];
+ sbyte [] _oneByte = new sbyte [1];
+
+ Encoding _encoding = null;
+
+ /// <summary>
+ /// Ctor from writer
+ /// </summary>
+ /// <param name="writer"></param>
+ public OutputStreamWrapper (PrintWriter writer)
+ {
+ _printWriter = writer;
+ _outputMode = OutputMode.CharWriter;
+ }
+
+ /// <summary>
+ /// Ctor from stream
+ /// </summary>
+ /// <param name="outputStream"></param>
+ public OutputStreamWrapper (OutputStream outputStream)
+ {
+ _outputStream = outputStream;
+ _outputMode = OutputMode.ByteStream;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public override void close ()
+ {
+ // BUGBUG
+ // on WPS, closing the writer causes
+ // any portlets rendered after us to be not shown...
+ //_writer.close();
+ }
+
+ /// <summary>
+ /// Flushes servers stream
+ /// </summary>
+ public override void flush ()
+ {
+ if (_outputMode == OutputMode.CharWriter)
+ _printWriter.flush ();
+ else
+ _outputStream.flush();
+ }
+
+ /// <summary>
+ /// Writes char array
+ /// </summary>
+ /// <param name="chars"></param>
+ /// <param name="index"></param>
+ /// <param name="count"></param>
+ public override void write (char [] chars, int index, int count)
+ {
+ if (_outputMode == OutputMode.CharWriter) {
+ _printWriter.write (chars, index, count);
+ }
+ else {
+ int length = Encoding.GetMaxByteCount (count);
+ byte [] bytebuffer = GetByteBuffer (length);
+ int realLength = Encoding.GetBytes (chars,
index, count, bytebuffer, 0);
+
+ _outputStream.write (TypeUtils.ToSByteArray
(bytebuffer), 0, realLength);
+ }
+
+ }
+
+ /// <summary>
+ /// Writes byte array
+ /// </summary>
+ /// <param name="sbytes"></param>
+ /// <param name="index"></param>
+ /// <param name="count"></param>
+ public void write (sbyte [] sbytes, int index, int count)
+ {
+ if (_outputMode == OutputMode.ByteStream)
+ _outputStream.write (sbytes, index, count);
+ else {
+ int length = Encoding.GetMaxCharCount (count);
+ char [] charbuffer = GetCharBuffer (length);
+ int realLength = Encoding.GetChars ((byte [])
TypeUtils.ToByteArray (sbytes), index, count, charbuffer, 0);
+
+ _printWriter.write (charbuffer, 0, realLength);
+ }
+ }
+
+ private char [] GetCharBuffer (int length)
+ {
+ // We will reuse the buffer if its size is < 32K
+ if (_charBuffer.Length >= length)
+ return _charBuffer;
+
+ if (length > 32 * 1024)
+ return new char [length];
+
+ _charBuffer = new char [length];
+ return _charBuffer;
+ }
+
+ private byte [] GetByteBuffer (int length)
+ {
+ // We will reuse the buffer if its size is < 32K
+ if (_bytebuffer.Length >= length)
+ return _bytebuffer;
+
+ if (length > 32 * 1024)
+ return new byte [length];
+
+ _bytebuffer = new byte [length];
+ return _bytebuffer;
+ }
+
+ private Encoding Encoding
+ {
+ get
+ {
+ if (_encoding == null) {
+ HttpContext current =
HttpContext.Current;
+ _encoding = (current != null) ?
current.Response.ContentEncoding : Encoding.UTF8;
+ }
+ return _encoding;
+ }
+ }
+ }
+}
Modified:
trunk/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ServletWorkerRequest.jvm.cs
===================================================================
---
trunk/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ServletWorkerRequest.jvm.cs
2007-06-28 11:29:08 UTC (rev 80959)
+++
trunk/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ServletWorkerRequest.jvm.cs
2007-06-28 11:41:26 UTC (rev 80960)
@@ -46,7 +46,7 @@
readonly HttpServlet _HttpServlet;
readonly HttpServletRequest _HttpServletRequest;
readonly HttpServletResponse _HttpServletResponse;
- java.io.OutputStream _OutputStream;
+ OutputStreamWrapper _OutputStream;
readonly string _requestUri;
readonly string _pathInfo;
@@ -96,12 +96,14 @@
KnownServerVariableMap[knownServerVariableNames[i]] = (KnownServerVariable)i;
}
- public ServletWorkerRequest (HttpServlet servlet,
HttpServletRequest req, HttpServletResponse resp, java.io.OutputStream
outputStream) {
+ public ServletWorkerRequest (HttpServlet servlet,
HttpServletRequest req, HttpServletResponse resp, bool alwaysUsePrintWriter) {
_HttpServlet = servlet;
_HttpServletRequest = req;
_HttpServletResponse = resp;
- _OutputStream = outputStream;
+ if (alwaysUsePrintWriter)
+ _OutputStream = new OutputStreamWrapper
(resp.getWriter ());
+
string contextPath = req.getContextPath();
string servletPath = req.getServletPath ();
string requestURI = req.getRequestURI ();
@@ -151,6 +153,8 @@
return ServletRequest;
if (serviceType == typeof(HttpServletResponse))
return ServletResponse;
+ if (serviceType == typeof (java.io.Writer))
+ return CreateOutputStream (false);
return null;
}
@@ -388,9 +392,29 @@
}
}
+ private OutputStreamWrapper CreateOutputStream (bool binary)
+ {
+ IPortletActionResponse resp = _HttpServletResponse as
IPortletActionResponse;
+ if (resp != null)
+ return null; // no output stream while
processAction
+
+ if (_OutputStream != null)
+ return _OutputStream;
+
+ if (_HttpServletResponse != null) {
+ if (binary)
+ _OutputStream = new OutputStreamWrapper
(_HttpServletResponse.getOutputStream ());
+ else
+ _OutputStream = new OutputStreamWrapper
(_HttpServletResponse.getWriter ());
+ }
+
+ return _OutputStream;
+ }
+
public override void SendResponseFromMemory (byte [] data, int
length) {
- IPortletActionResponse resp =_HttpServletResponse as
IPortletActionResponse;
- if (_OutputStream == null || resp != null &&
resp.isRedirected())
+ _OutputStream = CreateOutputStream (true);
+
+ if (_OutputStream == null)
return;
sbyte [] sdata =
vmw.common.TypeUtils.ToSByteArray(data);
Modified: trunk/mcs/class/Mainsoft.Web/Mainsoft.Web.J2EE.csproj
===================================================================
--- trunk/mcs/class/Mainsoft.Web/Mainsoft.Web.J2EE.csproj 2007-06-28
11:29:08 UTC (rev 80959)
+++ trunk/mcs/class/Mainsoft.Web/Mainsoft.Web.J2EE.csproj 2007-06-28
11:41:26 UTC (rev 80960)
@@ -101,14 +101,10 @@
-->
<ProjectExtensions>
<VisualStudio>
- <UserProperties REFS-JarPath-JavaEE="..\lib\JavaEE.jar"
REFS-JarPath-rt="..\lib\rt.jar" REFS-JarPath-mscorlib="..\lib\mscorlib.jar"
REFS-JarPath-system="..\lib\System.jar"
REFS-JarPath-system-data="..\lib\System.Data.jar"
REFS-JarPath-system-xml="..\lib\System.Xml.jar"
REFS-JarPath-system-configuration="..\lib\System.Configuration.jar"
REFS-JarPath-system-web="..\lib\System.Web.jar"
REFS-JarPath-j2se-helpers="..\lib\J2SE.Helpers.jar"
REFS-JarPath-j2ee-helpers="..\lib\J2EE.Helpers.jar" />
+ <UserProperties REFS-RefInfo-javaee="repository:JavaEE:tomcat:1.3"
REFS-JarPath-j2ee-helpers="..\lib\J2EE.Helpers.jar"
REFS-JarPath-j2se-helpers="..\lib\J2SE.Helpers.jar"
REFS-JarPath-system-web="..\lib\System.Web.jar"
REFS-JarPath-system-configuration="..\lib\System.Configuration.jar"
REFS-JarPath-system-xml="..\lib\System.Xml.jar"
REFS-JarPath-system-data="..\lib\System.Data.jar"
REFS-JarPath-system="..\lib\System.jar"
REFS-JarPath-mscorlib="..\lib\mscorlib.jar" REFS-JarPath-rt="..\lib\rt.jar"
REFS-JarPath-JavaEE="" />
</VisualStudio>
</ProjectExtensions>
<ItemGroup>
- <Reference Include="JavaEE">
- <HintPath>..\lib\JavaEE.dll</HintPath>
- <Private>False</Private>
- </Reference>
<Reference Include="J2EE.Helpers">
<HintPath>..\lib\J2EE.Helpers.dll</HintPath>
<Private>False</Private>
@@ -117,6 +113,7 @@
<HintPath>..\lib\J2SE.Helpers.dll</HintPath>
<Private>False</Private>
</Reference>
+ <Reference Include="JavaEE, Version=0.0.0.0, Culture=neutral,
processorArchitecture=MSIL" />
<Reference Include="rt">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\lib\rt.dll</HintPath>
@@ -138,6 +135,7 @@
<Compile Include="Mainsoft.Web.Hosting\BaseHttpServlet.cs" />
<Compile Include="Mainsoft.Web.Hosting\BaseStaticHttpServlet.cs" />
<Compile Include="Mainsoft.Web.Hosting\IncludeHelperServlet.cs" />
+ <Compile Include="Mainsoft.Web.Hosting\OutputStreamWrapper.cs" />
<Compile Include="Mainsoft.Web.Hosting\ServletWorkerRequest.jvm.cs" />
<Compile Include="Mainsoft.Web.Profile\CloudscapeProfileProvider.cs" />
<Compile Include="Mainsoft.Web.Profile\DerbyProfileHelper.cs" />
@@ -161,4 +159,4 @@
<Compile Include="Mainsoft.Web\J2EEUtils.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
-</Project>
+</Project>
\ No newline at end of file
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches