From dafa486b9a0775e948d746044f264ef41ab60f16 Mon Sep 17 00:00:00 2001 From: Eyal Alalouf Date: Sun, 14 Jan 2007 17:20:40 +0000 Subject: [PATCH] Added J2EE Portal support. svn path=/trunk/mcs/; revision=70990 --- .../Mainsoft.Web.Hosting/BaseHttpServlet.cs | 43 ++++--- .../BaseStaticHttpServlet.cs | 84 +++++++++++-- .../IncludeHelperServlet.cs | 119 ++++++++++++++++++ .../ServletWorkerRequest.jvm.cs | 43 +++++-- .../J2EEAuthenticationModule.cs | 84 +++++++++++++ .../ObjectInputStream.cs | 50 ++++---- .../ObjectOutputStream.cs | 50 ++++---- .../ServletSessionIDManager.cs | 2 +- .../ServletSessionStateItemCollection.cs | 11 +- .../Mainsoft.Web/Mainsoft.Web/J2EEUtils.cs | 21 +++- 10 files changed, 408 insertions(+), 99 deletions(-) create mode 100644 mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/IncludeHelperServlet.cs create mode 100644 mcs/class/Mainsoft.Web/Mainsoft.Web.Security/J2EEAuthenticationModule.cs diff --git a/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/BaseHttpServlet.cs b/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/BaseHttpServlet.cs index b2d13abd453..d4ca4cc7fe4 100644 --- a/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/BaseHttpServlet.cs +++ b/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/BaseHttpServlet.cs @@ -42,9 +42,11 @@ namespace Mainsoft.Web.Hosting public class BaseHttpServlet : HttpServlet { //private AppDomain _servletDomain; - static LocalDataStoreSlot _servletRequestSlot = Thread.GetNamedDataSlot(J2EEConsts.SERVLET_REQUEST); - static LocalDataStoreSlot _servletResponseSlot = Thread.GetNamedDataSlot(J2EEConsts.SERVLET_RESPONSE); - static LocalDataStoreSlot _servletSlot = Thread.GetNamedDataSlot(J2EEConsts.CURRENT_SERVLET); + static readonly LocalDataStoreSlot _servletRequestSlot = Thread.GetNamedDataSlot(J2EEConsts.SERVLET_REQUEST); + static readonly LocalDataStoreSlot _servletResponseSlot = Thread.GetNamedDataSlot(J2EEConsts.SERVLET_RESPONSE); + static readonly LocalDataStoreSlot _servletSlot = Thread.GetNamedDataSlot(J2EEConsts.CURRENT_SERVLET); + + bool _performedInit = false; public BaseHttpServlet() { @@ -59,6 +61,9 @@ namespace Mainsoft.Web.Hosting protected virtual void InitServlet(ServletConfig config) { + if (config.getServletContext().getAttribute(J2EEConsts.APP_DOMAIN) != null) + return; + try { AppDomain servletDomain = createServletDomain(config); @@ -76,6 +81,7 @@ namespace Mainsoft.Web.Hosting servletDomain.SetData(J2EEConsts.RESOURCE_LOADER, new vmw.@internal.j2ee.ServletResourceLoader(config.getServletContext())); config.getServletContext().setAttribute(J2EEConsts.APP_DOMAIN, servletDomain); + _performedInit = true; } finally { @@ -84,7 +90,13 @@ namespace Mainsoft.Web.Hosting } } - override protected void service (HttpServletRequest req, HttpServletResponse resp) + protected override void service (HttpServletRequest req, HttpServletResponse resp) + { + resp.setContentType("text/html"); + service(req, resp, resp.getOutputStream()); + } + + public virtual void service(HttpServletRequest req, HttpServletResponse resp, java.io.OutputStream output) { try { @@ -96,22 +108,17 @@ namespace Mainsoft.Web.Hosting // Put to the TLS current AppDomain of the servlet, so anyone can use it. vmw.@internal.EnvironmentUtils.setAppDomain(servletDomain); - //put request to the TLS + // put request to the TLS Thread.SetData(_servletRequestSlot, req); - //put response to the TLS + // put response to the TLS Thread.SetData(_servletResponseSlot, resp); - //put the servlet object to the TLS + // put the servlet object to the TLS Thread.SetData(_servletSlot, this); - - resp.setHeader("X-Powered-By", "ASP.NET"); resp.setHeader("X-AspNet-Version", "1.1.4322"); - //PageMapper.LoadFileList(); - - resp.setContentType("text/html"); - HttpWorkerRequest gwr = new ServletWorkerRequest(this, req, resp); + HttpWorkerRequest gwr = new ServletWorkerRequest(this, req, resp, output); HttpRuntime.ProcessRequest(gwr); } finally @@ -121,14 +128,15 @@ namespace Mainsoft.Web.Hosting Thread.SetData(_servletResponseSlot, null); Thread.SetData(_servletSlot, null); vmw.@internal.EnvironmentUtils.clearAppDomain(); - //cleaning - //vmw.Utils.cleanTLS(); //clean up all TLS entries for current Thread. - //java.lang.Thread.currentThread().setContextClassLoader(null); } } override public void destroy() { + base.destroy(); + if (!_performedInit) + return; + try { AppDomain servletDomain = (AppDomain)this.getServletContext().getAttribute(J2EEConsts.APP_DOMAIN); @@ -136,7 +144,6 @@ namespace Mainsoft.Web.Hosting #if DEBUG Console.WriteLine("Destroy of GhHttpServlet"); #endif - base.destroy(); HttpRuntime.Close(); vmw.@internal.EnvironmentUtils.cleanAllBeforeServletDestroy(this); this.getServletContext().removeAttribute(J2EEConsts.APP_DOMAIN); @@ -179,7 +186,7 @@ namespace Mainsoft.Web.Hosting servletDomain.SetData(IAppDomainConfig.WEB_APP_DIR, rootPath); //Set DataDirectory substitution string (http://blogs.msdn.com/dataaccess/archive/2005/10/28/486273.aspx) - string dataDirectory = config.getServletContext().getInitParameter ("DataDirectory"); + string dataDirectory = J2EEUtils.GetInitParameterByHierarchy(config, "DataDirectory"); if (dataDirectory == null) dataDirectory = "APP_DATA"; diff --git a/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/BaseStaticHttpServlet.cs b/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/BaseStaticHttpServlet.cs index 112bdc62e18..c5ecc9f2d93 100644 --- a/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/BaseStaticHttpServlet.cs +++ b/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/BaseStaticHttpServlet.cs @@ -26,14 +26,14 @@ using System; using System.IO; using System.Configuration; -using System.Web.Configuration; +using System.Web; using System.Threading; using javax.servlet; using javax.servlet.http; using vmw.common; -namespace System.Web.J2EE +namespace Mainsoft.Web.Hosting { public class BaseStaticHttpServlet : HttpServlet { @@ -44,8 +44,7 @@ namespace System.Web.J2EE override public void init(ServletConfig config) { base.init(config); - ServletContext context = config.getServletContext(); - AppDir = config.getInitParameter(IAppDomainConfig.APP_DIR_NAME); + AppDir = J2EEUtils.GetInitParameterByHierarchy(config, IAppDomainConfig.APP_DIR_NAME); if (AppDir != null) { AppDir = AppDir.Replace('\\', '/'); if (AppDir[AppDir.Length - 1] != '/') @@ -55,18 +54,32 @@ namespace System.Web.J2EE override protected void service(HttpServletRequest req, HttpServletResponse resp) { - String pathInfo = req.getRequestURI(); - String contextPath = req.getContextPath(); - - pathInfo = getServletContext().getRealPath(req.getServletPath()); resp.setHeader("X-Powered-By", "ASP.NET"); resp.setHeader("X-AspNet-Version", "1.1.4322"); - ServletOutputStream hos = resp.getOutputStream(); - String filename = pathInfo; + String filename = getServletContext().getRealPath(req.getServletPath()); + ServletOutputStream hos; + try { + hos = resp.getOutputStream(); + } + catch (java.lang.IllegalStateException e) + { + string mimeType = getServletContext().getMimeType(filename); + if (mimeType == null || mimeType.StartsWith("text")) { + sendFileUsingWriter(resp, filename); + return; + } + else + throw e; + } try { - resp.setContentType(this.getServletContext().getMimeType(filename)); + string mimeType = this.getServletContext().getMimeType(filename); + if (mimeType == null) + mimeType = "text/plain"; + + resp.setContentType(mimeType); + FileStream fis = null; try { fis = new FileStream(filename,FileMode.Open,FileAccess.Read); @@ -98,6 +111,43 @@ namespace System.Web.J2EE } } + void sendFileUsingWriter(HttpServletResponse resp, string filename) + { + java.io.PrintWriter writer = resp.getWriter(); + try + { + resp.setContentType(this.getServletContext().getMimeType(filename)); + StreamReader fis = null; + char[] buf = new char[4 * 1024]; // 4K buffer + try { + fis = new StreamReader(filename); + int charsRead; + while ((charsRead = fis.Read(buf,0,buf.Length)) != -1 && + charsRead != 0) { + writer.write(buf, 0, charsRead); + } + } + finally { + if (fis != null) fis.Close(); + } + } + catch (System.IO.FileNotFoundException e) + { + resp.setStatus(404,"Object Not Found."); + HttpException myExp = new HttpException (404, "File '" + filename + "' not found."); + writer.print(((HttpException) myExp).GetHtmlErrorMessage ()); + writer.flush(); + } + catch(Exception e) + { + Console.WriteLine("ERROR in Static File Reading {0},{1}",e.GetType(), e.Message); + resp.setStatus(500); + HttpException myExp = new HttpException ("Exception in Reading static file", e); + writer.print(((HttpException) myExp).GetHtmlErrorMessage ()); + writer.flush(); + } + } + override public void destroy() { base.destroy(); @@ -107,10 +157,20 @@ namespace System.Web.J2EE } } +namespace System.Web.J2EE +{ + public class BaseStaticHttpServlet : Mainsoft.Web.Hosting.BaseStaticHttpServlet + { + } + +} + + namespace System.Web.GH { - public class BaseStaticHttpServlet : System.Web.J2EE.BaseStaticHttpServlet + public class BaseStaticHttpServlet : Mainsoft.Web.Hosting.BaseStaticHttpServlet { } } + diff --git a/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/IncludeHelperServlet.cs b/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/IncludeHelperServlet.cs new file mode 100644 index 00000000000..ac52036a09b --- /dev/null +++ b/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/IncludeHelperServlet.cs @@ -0,0 +1,119 @@ +// +// Mainsoft.Web.Hosting.IncludeHelperServlet +// +// Authors: +// Eyal Alaluf (eyala@mainsoft.com) +// +// (C) 2006 Mainsoft Co. (http://www.mainsoft.com) +// + +// +// 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.IO; +using System.Web.UI; +using java.io; +using javax.servlet; +using javax.servlet.http; +using vmw.@internal.j2ee; + +namespace Mainsoft.Web.Hosting +{ + public class IncludeHelperServlet : HttpServlet + { + public IncludeHelperServlet() + { + } + + override public void init(ServletConfig config) + { + base.init(config); + } + + override protected void service(HttpServletRequest req, HttpServletResponse resp) + { + string servletPath = ServletIncludeUtils.getServletPath(req); + TextWriter writer = (TextWriter)ServletIncludeUtils.getTextWriter(req); + RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(servletPath); + HttpServletResponseWrapper wrapper = new AspxResponseWrapper(resp, writer); + dispatcher.include(req, wrapper); + } + + override public void destroy() + { + base.destroy(); + } + + class AspxResponseWrapper : HttpServletResponseWrapper + { + public AspxResponseWrapper(HttpServletResponse resp, TextWriter writer) : base (resp) + { + jwriter = new PrintWriter(new JavaWriterFromTextWriter(writer)); + } + + public override PrintWriter getWriter() + { + return jwriter; + } + + PrintWriter jwriter; + } + + public class JavaWriterFromTextWriter : Writer + { + public JavaWriterFromTextWriter(TextWriter writer) + { + this.writer = writer; + } + + public override void flush() + { + writer.Flush (); + } + + public override void write(char[] buffer, int offset, int count) + { + writer.Write(buffer, offset, count); + } + + public override void write(String s) + { + writer.Write(s); + } + + public override void write(string s, int start, int count) + { + if (start == 0 && count == s.Length) + writer.Write(s); + else + writer.Write(s.Substring(start, count)); + } + + public override void close() + { + // Ignore close as we don't own here the writer. + } + + TextWriter writer; + } + } +} diff --git a/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ServletWorkerRequest.jvm.cs b/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ServletWorkerRequest.jvm.cs index 469e44ae5b5..0fb1d323697 100644 --- a/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ServletWorkerRequest.jvm.cs +++ b/mcs/class/Mainsoft.Web/Mainsoft.Web.Hosting/ServletWorkerRequest.jvm.cs @@ -27,7 +27,6 @@ using System.IO; using System.Text; using System.Runtime.InteropServices; using System.Web.Util; -using vmw.common; using System.Web.J2EE; using System.Collections; using System.Web; @@ -36,14 +35,17 @@ using javax.servlet.http; using System.Collections.Specialized; using System.Globalization; using System.Web.Hosting; +using vmw.common; +using vmw.@internal.j2ee; namespace Mainsoft.Web.Hosting { [MonoTODO("Implement security demands on the path usage functions (and review)")] [ComVisible (false)] - internal sealed class ServletWorkerRequest : HttpWorkerRequest { + internal sealed class ServletWorkerRequest : HttpWorkerRequest, IServiceProvider { readonly HttpServlet _HttpServlet; readonly HttpServletRequest _HttpServletRequest; readonly HttpServletResponse _HttpServletResponse; + java.io.OutputStream _OutputStream; readonly string _requestUri; readonly string _pathInfo; @@ -93,10 +95,11 @@ namespace Mainsoft.Web.Hosting { KnownServerVariableMap[knownServerVariableNames[i]] = (KnownServerVariable)i; } - public ServletWorkerRequest (HttpServlet servlet, HttpServletRequest req, HttpServletResponse resp) { + public ServletWorkerRequest (HttpServlet servlet, HttpServletRequest req, HttpServletResponse resp, java.io.OutputStream outputStream) { _HttpServlet = servlet; _HttpServletRequest = req; _HttpServletResponse = resp; + _OutputStream = outputStream; string contextPath = req.getContextPath(); string requestURI = req.getRequestURI(); @@ -119,6 +122,17 @@ namespace Mainsoft.Web.Hosting { } } + public object GetService (Type serviceType) + { + if (serviceType == typeof(HttpServlet)) + return Servlet; + if (serviceType == typeof(HttpServletRequest)) + return ServletRequest; + if (serviceType == typeof(HttpServletResponse)) + return ServletResponse; + return null; + } + public HttpServlet Servlet { get { return _HttpServlet; @@ -151,13 +165,17 @@ namespace Mainsoft.Web.Hosting { public override void EndOfRequest () { if (_endOfSendCallback != null) _endOfSendCallback(this, _endOfSendArgs); + _OutputStream = null; } public override void FlushResponse (bool finalFlush) { - ServletOutputStream servletOutputStream = _HttpServletResponse.getOutputStream(); - servletOutputStream.flush(); + IPortletActionResponse resp =_HttpServletResponse as IPortletActionResponse; + if (_OutputStream == null || resp != null && resp.isRedirected()) + return; + + _OutputStream.flush(); if (finalFlush) - servletOutputStream.close(); + _OutputStream.close(); } public override string GetAppPath () { @@ -243,10 +261,9 @@ namespace Mainsoft.Web.Hosting { try { return _HttpServletRequest.getRemotePort(); } - catch(Exception e) { //should catch also java.lang.Throwable - //if servlet API is 2.3 and below - there is no - //method getRemotePort in ServletRequest interface... - //should be described as limitation. + catch(Exception e) { + // if servlet API is 2.3 and below - there is no method getRemotePort + // in ServletRequest interface... should be described as limitation. return 0; } } @@ -351,8 +368,12 @@ namespace Mainsoft.Web.Hosting { } public override void SendResponseFromMemory (byte [] data, int length) { + IPortletActionResponse resp =_HttpServletResponse as IPortletActionResponse; + if (_OutputStream == null || resp != null && resp.isRedirected()) + return; + sbyte [] sdata = vmw.common.TypeUtils.ToSByteArray(data); - _HttpServletResponse.getOutputStream().write(sdata, 0 , length); + _OutputStream.write(sdata, 0 , length); } public override void SendStatus(int statusCode, string statusDescription) { diff --git a/mcs/class/Mainsoft.Web/Mainsoft.Web.Security/J2EEAuthenticationModule.cs b/mcs/class/Mainsoft.Web/Mainsoft.Web.Security/J2EEAuthenticationModule.cs new file mode 100644 index 00000000000..0e840e6aabd --- /dev/null +++ b/mcs/class/Mainsoft.Web/Mainsoft.Web.Security/J2EEAuthenticationModule.cs @@ -0,0 +1,84 @@ +// +// Mainsoft.Web.Security.J2EEAuthenticationModule +// +// Authors: +// Eyal Alaluf (eyala@mainsoft.com) +// +// (C) 2006 Mainsoft Co. (http://www.mainsoft.com) +// + +// +// 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.Security.Principal; +using System.Text; +using System.Web; +using System.Web.Configuration; +using System.Web.Util; +using javax.servlet; +using javax.servlet.http; + +namespace Mainsoft.Web.Security +{ + public sealed class J2EEAuthenticationModule : IHttpModule + { + public void Dispose () + { + } + + public void Init (HttpApplication app) + { + app.AuthenticateRequest += new EventHandler (OnAuthenticateRequest); + } + + void OnAuthenticateRequest (object sender, EventArgs args) + { + HttpApplication app = (HttpApplication) sender; + HttpServletRequest req = app.Context.Request.ServletWorkerRequest.ServletRequest; + if (req.getRemoteUser() != null) + app.Context.User = new J2EEPrincipal(req); + } + } + + internal class J2EEPrincipal : IPrincipal + { + HttpServletRequest _request; + IIdentity _identity; + + public J2EEPrincipal(HttpServletRequest req) + { + _request = req; + string authType = req.getAuthType(); + if (authType == null) + authType = ""; + _identity = new GenericIdentity(req.getRemoteUser(), authType); + } + + public bool IsInRole(string role) + { + return _request.isUserInRole(role); + } + + public IIdentity Identity { get { return _identity; } } + } +} + diff --git a/mcs/class/Mainsoft.Web/Mainsoft.Web.SessionState/ObjectInputStream.cs b/mcs/class/Mainsoft.Web/Mainsoft.Web.SessionState/ObjectInputStream.cs index caea7f3a7a1..2a25b48910e 100644 --- a/mcs/class/Mainsoft.Web/Mainsoft.Web.SessionState/ObjectInputStream.cs +++ b/mcs/class/Mainsoft.Web/Mainsoft.Web.SessionState/ObjectInputStream.cs @@ -1,28 +1,28 @@ -// -// (C) 2005 Mainsoft Corporation (http://www.mainsoft.com) -// -// Authors: -// Vladimir Krasnov -// Konstantin Triger -// -// 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. +// +// (C) 2005 Mainsoft Corporation (http://www.mainsoft.com) +// +// Authors: +// Vladimir Krasnov +// Konstantin Triger +// +// 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; diff --git a/mcs/class/Mainsoft.Web/Mainsoft.Web.SessionState/ObjectOutputStream.cs b/mcs/class/Mainsoft.Web/Mainsoft.Web.SessionState/ObjectOutputStream.cs index be8c5c06864..b0e08ea9548 100644 --- a/mcs/class/Mainsoft.Web/Mainsoft.Web.SessionState/ObjectOutputStream.cs +++ b/mcs/class/Mainsoft.Web/Mainsoft.Web.SessionState/ObjectOutputStream.cs @@ -1,28 +1,28 @@ -// -// (C) 2005 Mainsoft Corporation (http://www.mainsoft.com) -// -// Authors: -// Vladimir Krasnov -// Konstantin Triger -// -// 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. +// +// (C) 2005 Mainsoft Corporation (http://www.mainsoft.com) +// +// Authors: +// Vladimir Krasnov +// Konstantin Triger +// +// 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; diff --git a/mcs/class/Mainsoft.Web/Mainsoft.Web.SessionState/ServletSessionIDManager.cs b/mcs/class/Mainsoft.Web/Mainsoft.Web.SessionState/ServletSessionIDManager.cs index bc83aef96fe..e73a0ea3304 100755 --- a/mcs/class/Mainsoft.Web/Mainsoft.Web.SessionState/ServletSessionIDManager.cs +++ b/mcs/class/Mainsoft.Web/Mainsoft.Web.SessionState/ServletSessionIDManager.cs @@ -55,7 +55,7 @@ namespace Mainsoft.Web.SessionState } public void RemoveSessionID (HttpContext context) { - ServletSessionStateStoreProvider.GetWorkerRequest (context).ServletRequest.getSession (false).invalidate (); + ServletSessionStateStoreProvider.GetSession (context, false).invalidate (); } public void SaveSessionID (HttpContext context, string id, out bool redirected, out bool cookieAdded) { diff --git a/mcs/class/Mainsoft.Web/Mainsoft.Web.SessionState/ServletSessionStateItemCollection.cs b/mcs/class/Mainsoft.Web/Mainsoft.Web.SessionState/ServletSessionStateItemCollection.cs index 13ebe2f29d2..2ff80d5199e 100755 --- a/mcs/class/Mainsoft.Web/Mainsoft.Web.SessionState/ServletSessionStateItemCollection.cs +++ b/mcs/class/Mainsoft.Web/Mainsoft.Web.SessionState/ServletSessionStateItemCollection.cs @@ -45,7 +45,7 @@ namespace Mainsoft.Web.SessionState HttpStaticObjectsCollection _staticObjects; bool _needSessionPersistence; - public ServletSessionStateItemCollection () { } //for deserialization + public ServletSessionStateItemCollection () {} // For Java deserialization public ServletSessionStateItemCollection (HttpContext context) : this () { @@ -55,7 +55,7 @@ namespace Mainsoft.Web.SessionState if (context != null) { ServletConfig config = ServletSessionStateStoreProvider.GetWorkerRequest (context).Servlet.getServletConfig (); - string sessionPersistance = config.getInitParameter (J2EEConsts.Enable_Session_Persistency); + string sessionPersistance = J2EEUtils.GetInitParameterByHierarchy(config, J2EEConsts.Enable_Session_Persistency); if (sessionPersistance == null) sessionPersistance = config.getServletContext().getInitParameter (J2EEConsts.Enable_Session_Persistency); if (sessionPersistance != null) { @@ -155,8 +155,13 @@ namespace Mainsoft.Web.SessionState public void readExternal (java.io.ObjectInput input) { lock (this) { _needSessionPersistence = input.readBoolean (); - if (!_needSessionPersistence) //noting has been written + if (!_needSessionPersistence) { //nothing has been written + if (_items == null) + _items = new SessionStateItemCollection (); + if (_staticObjects == null) + _staticObjects = new HttpStaticObjectsCollection (); return; + } ObjectInputStream ms = new ObjectInputStream (input); System.IO.BinaryReader br = new System.IO.BinaryReader (ms); diff --git a/mcs/class/Mainsoft.Web/Mainsoft.Web/J2EEUtils.cs b/mcs/class/Mainsoft.Web/Mainsoft.Web/J2EEUtils.cs index ed93d742642..aa6e109196a 100755 --- a/mcs/class/Mainsoft.Web/Mainsoft.Web/J2EEUtils.cs +++ b/mcs/class/Mainsoft.Web/Mainsoft.Web/J2EEUtils.cs @@ -35,8 +35,21 @@ namespace Mainsoft.Web { internal static class J2EEUtils { - public static string GetApplicationRealPath (ServletConfig config) { - string realFs = config.getInitParameter (J2EEConsts.FILESYSTEM_ACCESS); + public static string GetInitParameterByHierarchy(ServletConfig config, string name) + { + if (config == null) + throw new ArgumentNullException("config"); + + string value = config.getInitParameter(name); + if (value != null) + return value; + + return config.getServletContext().getInitParameter(name); + } + + public static string GetApplicationRealPath (ServletConfig config) + { + string realFs = GetInitParameterByHierarchy (config, J2EEConsts.FILESYSTEM_ACCESS); if (realFs == null || realFs == J2EEConsts.ACCESS_FULL) { try { if (Path.IsPathRooted (config.getServletContext ().getRealPath (""))) @@ -55,7 +68,7 @@ namespace Mainsoft.Web public static string GetApplicationPhysicalPath (ServletConfig config) { string path = ""; ServletContext context = config.getServletContext (); - string appDir = config.getInitParameter (IAppDomainConfig.APP_DIR_NAME); + string appDir = GetInitParameterByHierarchy (config, IAppDomainConfig.APP_DIR_NAME); // Console.WriteLine("appdir = {0}", appDir); if (appDir != null) { try { @@ -81,4 +94,4 @@ namespace Mainsoft.Web return path; } } -} \ No newline at end of file +} -- 2.25.1