public override string MapPath(string virtualPath)
        {
            if (virtualPath == null)
            {
                throw new ArgumentNullException("virtualPath");
            }

            ServletContext context = GetContext();

            string contextPath = GetAppPath();

            if ((virtualPath.Length > contextPath.Length && virtualPath [contextPath.Length] != '/') ||
                string.Compare(contextPath, 0, virtualPath, 0, contextPath.Length, StringComparison.OrdinalIgnoreCase) != 0)
            {
                for (int appVirtualPathIndex = 0; appVirtualPathIndex > 0 && virtualPath.Length > appVirtualPathIndex;)
                {
                    appVirtualPathIndex = virtualPath.IndexOf('/', appVirtualPathIndex + 1);
                    string crossContextPath = appVirtualPathIndex > 0 ?
                                              virtualPath.Remove(appVirtualPathIndex) : virtualPath;
                    ServletContext other = context.getContext(crossContextPath);
                    if (other != null)
                    {
                        string appVirtualPath = appVirtualPathIndex > 0 ?
                                                virtualPath.Substring(appVirtualPathIndex) : String.Empty;
                        return(other.getRealPath(appVirtualPath));
                    }
                }

                throw new HttpException(
                          String.Format("MapPath: Mapping across applications is not allowed. ApplicationPath is '{0}', VirtualPath is '{1}'.",
                                        contextPath, virtualPath));
            }

            string thisAppVirtualPath = virtualPath.Length > contextPath.Length ? virtualPath.Substring(contextPath.Length) : String.Empty;

            return(J2EEUtils.GetApplicationRealPath(context, thisAppVirtualPath));
        }
示例#2
0
        private static AppDomain createServletDomain(ServletConfig config)
        {
            string         rootPath    = J2EEUtils.GetApplicationRealPath(config.getServletContext());
            AppDomainSetup domainSetup = new AppDomainSetup();
            string         name        = config.getServletName();     //.getServletContextName();

            if (name == null)
            {
                name = "GH Application";
            }
            domainSetup.ApplicationName   = name;
            domainSetup.ConfigurationFile = Path.Combine(rootPath, "Web.config");
            domainSetup.PrivateBinPath    = Path.Combine(rootPath, "WEB-INF/lib");

            AppDomain servletDomain = AppDomain.CreateDomain(name, null, domainSetup);



            //servletDomain.SetData(IAppDomainConfig.APP_PHYS_DIR, J2EEUtils.GetApplicationPhysicalPath(config));
            //servletDomain.SetData(IAppDomainConfig.WEB_APP_DIR, rootPath);

            servletDomain.SetData(IAppDomainConfig.APP_PHYS_DIR, J2EEUtils.GetApplicationPhysicalPath(config.getServletContext()));
            servletDomain.SetData(IAppDomainConfig.WEB_APP_DIR, rootPath);
            servletDomain.SetData(IAppDomainConfig.SERVLET_CONFIG, config);

            //Set DataDirectory substitution string (http://blogs.msdn.com/dataaccess/archive/2005/10/28/486273.aspx)
            string dataDirectory = config.getServletContext().getInitParameter("DataDirectory");

            if (dataDirectory == null)
            {
                dataDirectory = "App_Data";
            }

            if (!Path.IsPathRooted(dataDirectory))
            {
                java.io.InputStream inputStream = config.getServletContext().getResourceAsStream("/WEB-INF/classes/appData.properties");
                string root;
                if (inputStream != null)
                {
                    try {
                        Properties props = new Properties();
                        props.load(inputStream);
                        root = props.getProperty("root.folder");
                    }
                    finally {
                        inputStream.close();
                    }
                }
                else
                {
                    root = config.getServletContext().getRealPath("/");
                }

                if (root == null)
                {
                    root = String.Empty;
                }

                dataDirectory = Path.Combine(root, dataDirectory);
            }

            if (dataDirectory [dataDirectory.Length - 1] != Path.DirectorySeparatorChar)
            {
                dataDirectory += Path.DirectorySeparatorChar;
            }

            servletDomain.SetData("DataDirectory", dataDirectory);

            if (config.getServletContext().getRealPath("/") == null)
            {
                servletDomain.SetData(".appStartTime", DateTime.UtcNow);
            }

            // The BaseDir is the full path to the physical dir of the app
            // and allows the application to modify files in the case of
            // open deployment.
            string webApp_baseDir = config.getServletContext().getRealPath("");

            if (webApp_baseDir == null || webApp_baseDir == "")
            {
                webApp_baseDir = rootPath;
            }
            servletDomain.SetData(IAppDomainConfig.APP_BASE_DIR, webApp_baseDir);
            Debug.WriteLine("Initialization of webapp " + webApp_baseDir);
            //servletDomain.SetData(".hostingVirtualPath", "/");
            //servletDomain.SetData(".hostingInstallDir", "/");
            return(servletDomain);
        }
 public override string GetAppPathTranslated()
 {
     return(J2EEUtils.GetApplicationRealPath(GetContext()));
 }