예제 #1
0
        private void printFile(String fileName,
                               HttpServletRequest req,
                               HttpServletResponse res)

        {
            string mimeType = getServletContext().getMimeType(fileName);

            if (fileName.endsWith(".php") ||
                fileName.endsWith(".inc") ||
                fileName.endsWith(".js") ||
                fileName.endsWith(".html") ||
                fileName.endsWith(".xsl") ||
                fileName.endsWith(".css"))
            {
                res.setContentType("text/plain");
            }
            else if (mimeType != null)
            {
                res.setContentType(mimeType);
            }

            OutputStream os = res.getOutputStream();

            string path = _path.lookup(fileName);

            path.writeToStream(os);
        }
        // http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html#site-control
        // http://board.flashkit.com/board/showthread.php?t=782484
        protected override void doGet(HttpServletRequest req, HttpServletResponse resp)
        {
            try
            {
                var p = req.GetPathAndQuery();

                if (p.Length > UrlPattern.Length + 1)
                    p = p.Substring(UrlPattern.Length + 1);
                else
                    p = "";

                if ("zip" == p)
                {
                    resp.setContentType(ZIPFile.ContentType);
                    resp.getOutputStream().write((sbyte[])(object)GetContent());
                    resp.getOutputStream().flush();
                }
                else
                {
                    resp.setContentType("text/html");
                    resp.getWriter().println(Launch(p));
                    resp.getWriter().flush();
                }
            }
            catch (csharp.ThrowableException ex)
            {
                // either swallow of throw a runtime exception

                ((java.lang.Throwable)(object)ex).printStackTrace();

            }
        }
예제 #3
0
        protected override void doGet(HttpServletRequest req, HttpServletResponse resp)
        {
            try
            {
                var PathAndQuery = req.GetPathAndQuery().Substring(UrlPattern.Length);

                // not allowed to do so:
                // http://groups.google.com/group/google-appengine/browse_thread/thread/68a480cb7bec869e
                // http://www.ozelwebtasarim.com/index.php/google/10004-google-app-engine-java-utf-8-character-encoding-problem
                //resp.setHeader("Content-Encoding", "utf-8");

                if (PathAndQuery.Length > 1)
                {
                    resp.setContentType("text/html; charset=utf-8");
                    resp.getWriter().println(Launch(PathAndQuery.Substring(1)));
                }
                else
                {
                    resp.setContentType("text/html; charset=utf-8");
                    resp.getWriter().println(Launch(null));
                }
            }
            catch
            {
                // either swallow of throw a runtime exception
            }
        }
        // http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html#site-control
        // http://board.flashkit.com/board/showthread.php?t=782484

        protected override void doGet(HttpServletRequest req, HttpServletResponse resp)
        {
            try
            {
                var p = req.GetPathAndQuery();

                if (p.Length > UrlPattern.Length + 1)
                {
                    p = p.Substring(UrlPattern.Length + 1);
                }
                else
                {
                    p = "";
                }

                if ("zip" == p)
                {
                    resp.setContentType(ZIPFile.ContentType);
                    resp.getOutputStream().write((sbyte[])(object)GetContent());
                    resp.getOutputStream().flush();
                }
                else
                {
                    resp.setContentType("text/html");
                    resp.getWriter().println(Launch(p));
                    resp.getWriter().flush();
                }
            }
            catch (csharp.ThrowableException ex)
            {
                // either swallow of throw a runtime exception

                ((java.lang.Throwable)(object) ex).printStackTrace();
            }
        }
예제 #5
0
        protected override void doGet(HttpServletRequest req, HttpServletResponse resp)
        {
            try
            {
                var PathAndQuery = req.GetPathAndQuery().Substring(UrlPattern.Length);

                // not allowed to do so:
                // http://groups.google.com/group/google-appengine/browse_thread/thread/68a480cb7bec869e
                // http://www.ozelwebtasarim.com/index.php/google/10004-google-app-engine-java-utf-8-character-encoding-problem
                //resp.setHeader("Content-Encoding", "utf-8");

                if (PathAndQuery.Length > 1)
                {
                    resp.setContentType("text/html; charset=utf-8");
                    resp.getWriter().println(Launch(PathAndQuery.Substring(1)));
                }
                else
                {
                    resp.setContentType("text/html; charset=utf-8");
                    resp.getWriter().println(Launch(null));
                }
            }
            catch
            {
                // either swallow of throw a runtime exception
            }
        }
예제 #6
0
        public override void service(ServletRequest request, ServletResponse response)

        {
            HttpServletRequest  req = (HttpServletRequest)request;
            HttpServletResponse res = (HttpServletResponse)response;

            res.setContentType("text/html");

            if (_path == null)
            {
                res.sendError(HttpServletResponse.SC_FORBIDDEN);
                return;
            }

            string fileName = req.getParameter("file");

            if (fileName != null)
            {
                printFile(fileName, req, res);
                return;
            }

            PrintWriter @out = res.getWriter();

            @out.println("<pre>");

            printPath(@out, _path, 0);

            @out.println("</pre>");
        }
        protected override void doGet(HttpServletRequest req, HttpServletResponse resp)
        {
            try
            {
                var Path = req.getServletPath();
                var Query = req.getQueryString();
                var PathAndQuery = Path;
                if (Query != null)
                    PathAndQuery += "?" + Query;

                if (PathAndQuery != "/")
                {
                    //resp.setContentType("text/html");
                    //resp.getWriter().println(
                    resp.sendRedirect(
                        GetTinEyeVersion(GetPosterLink(PathAndQuery))
                        //.ToImage()
                    );
                }
                else
                {
                    resp.setContentType("text/html");
                    resp.getWriter().println(Launch(PathAndQuery));
                }
            }
            catch
            {
                // either swallow of throw a runtime exception
            }
        }
예제 #8
0
        protected override void doGet(HttpServletRequest request, HttpServletResponse response)
        {
            response.setContentType("text/html; charset=UTF-8");
            StreamWriter output = response.getWriter();

            output.WriteLine("<html>");
            output.WriteLine("<head>");
            output.WriteLine("<title>テスト掲示板</title>");
            output.WriteLine("<head>");
            output.WriteLine("<body>");
            output.WriteLine("<h1>テスト掲示板</h1>");
            output.WriteLine("<form action='/testbbs/PostBBS' method='post'>");
            output.WriteLine("タイトル:<input type='text' name='title' size='60'>"
                             + "<br/>");
            output.WriteLine("ハンドル名:<input type='text' name='handle'><br/>");
            output.WriteLine("<textarea name='message' rows='4' cols='60'>"
                             + "</textarea><br/>");
            output.WriteLine("<input type='submit'/>");
            output.WriteLine("</form>");
            output.WriteLine("<hr/>");

            foreach (Message.Message message in Message.Message.messageList)
            {
                output.WriteLine("<p>『" + escapeHtml(message.title) + "』&nbsp;&nbsp;"
                                 + escapeHtml(message.handle) + " さん&nbsp;&nbsp;"
                                 + escapeHtml(message.date.ToString()) + "</p>");
                output.WriteLine("<p>");
                output.WriteLine(escapeHtml(message.message).Replace("\r\n", "<br/>"));
                output.WriteLine("</p><hr/>");
            }

            output.WriteLine("</body>");
            output.WriteLine("</html>");
        }
예제 #9
0
        // http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html#site-control
        // http://board.flashkit.com/board/showthread.php?t=782484
        // http://www.adobe.com/devnet/flashplayer/articles/fplayer9_security_02.html

        protected override void doGet(HttpServletRequest req, HttpServletResponse resp)
        {
            try
            {
                resp.setContentType("text/x-cross-domain-policy");

                Console.WriteLine(UrlPattern);
                resp.getWriter().print(@"
<?xml version=""1.0""?>
<!DOCTYPE cross-domain-policy SYSTEM ""http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"">
<cross-domain-policy>
	<site-control permitted-cross-domain-policies=""all""/>
	<allow-access-from domain=""*"" secure=""false""/>
	<allow-http-request-headers-from domain=""*"" headers=""*"" secure=""false""/>
</cross-domain-policy>
".Trim());

                resp.getWriter().flush();
            }
            catch (csharp.ThrowableException ex)
            {
                // either swallow of throw a runtime exception

                ((java.lang.Throwable)(object) ex).printStackTrace();
            }
        }
        // http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html#site-control
        // http://board.flashkit.com/board/showthread.php?t=782484
        // http://www.adobe.com/devnet/flashplayer/articles/fplayer9_security_02.html
        protected override void doGet(HttpServletRequest req, HttpServletResponse resp)
        {
            try
            {
                resp.setContentType("text/x-cross-domain-policy");

                Console.WriteLine(UrlPattern);
                resp.getWriter().print(@"
            <?xml version=""1.0""?>
            <!DOCTYPE cross-domain-policy SYSTEM ""http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"">
            <cross-domain-policy>
            <site-control permitted-cross-domain-policies=""all""/>
            <allow-access-from domain=""*"" secure=""false""/>
            <allow-http-request-headers-from domain=""*"" headers=""*"" secure=""false""/>
            </cross-domain-policy>
            ".Trim());

                resp.getWriter().flush();
            }
            catch (csharp.ThrowableException ex)
            {
                // either swallow of throw a runtime exception

                ((java.lang.Throwable)(object)ex).printStackTrace();

            }
        }
예제 #11
0
        protected override void doPost(HttpServletRequest request, HttpServletResponse response)
        {
            request.setCharacterEncoding("Shift_JIS");
            response.setContentType("text/plain; charset=Shift_JIS");
            StreamWriter output = response.getWriter();

            foreach (Part part in request.getParts())
            {
                output.WriteLine("name.." + part.getName());
                foreach (String headerName in part.getHeaderNames())
                {
                    output.WriteLine(headerName + "=" + part.getHeader(headerName));
                }
                output.WriteLine("Content-Type.." + part.getContentType());
                output.WriteLine("Name.." + part.getName() + "/size.." + part.getSize());
                StreamReader reader = new StreamReader(part.getInputStream(), Encoding.GetEncoding("Shift_JIS"));
                int          ch;
                while ((ch = reader.Read()) >= 0)
                {
                    output.Write((char)(ch & 0xffff));
                }
                reader.Close();
                output.WriteLine("\n==================================");
            }
            output.WriteLine("text_name=" + request.getParameter("text_name"));
        }
        protected override void doGet(HttpServletRequest req, HttpServletResponse resp)
        {
            try
            {
                var Path         = req.getServletPath();
                var Query        = req.getQueryString();
                var PathAndQuery = Path;
                if (Query != null)
                {
                    PathAndQuery += "?" + Query;
                }

                if (PathAndQuery != "/")
                {
                    //resp.setContentType("text/html");
                    //resp.getWriter().println(
                    resp.sendRedirect(
                        GetTinEyeVersion(GetPosterLink(PathAndQuery))
                        //.ToImage()
                        );
                }
                else
                {
                    resp.setContentType("text/html");
                    resp.getWriter().println(Launch(PathAndQuery));
                }
            }
            catch
            {
                // either swallow of throw a runtime exception
            }
        }
예제 #13
0
		override protected void service(HttpServletRequest req, HttpServletResponse resp)
		{
			resp.setHeader("X-Powered-By", "ASP.NET");
			resp.setHeader("X-AspNet-Version", "1.1.4322");

			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 
			{
				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);
					byte[] buf = new byte[4 * 1024];  // 4K buffer
					int bytesRead;
					while ((bytesRead = fis.Read(buf,0,buf.Length)) != -1 &&
						   bytesRead != 0) {
						hos.write(TypeUtils.ToSByteArray(buf), 0, bytesRead);
					}
				}
				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.");
				hos.print(((HttpException) myExp).GetHtmlErrorMessage ());
				hos.flush();
			}
			catch(Exception e) 
			{
				Trace.WriteLine (String.Format ("ERROR in Static File Reading {0},{1}", e.GetType (), e.Message));
				resp.setStatus(500);
				HttpException myExp = new HttpException ("Exception in Reading static file", e);
				hos.print(((HttpException) myExp).GetHtmlErrorMessage ());
				hos.flush();
			}
		}
        // http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html#site-control
        // http://board.flashkit.com/board/showthread.php?t=782484

        protected override void doGet(HttpServletRequest req, HttpServletResponse resp)
        {
            try
            {
                resp.setContentType("text/html");
                resp.getWriter().println(Launch(req.GetPathAndQuery()));
                resp.getWriter().flush();
            }
            catch (csharp.ThrowableException ex)
            {
                // either swallow of throw a runtime exception

                ((java.lang.Throwable)(object) ex).printStackTrace();
            }
        }
        // http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html#site-control
        // http://board.flashkit.com/board/showthread.php?t=782484
        protected override void doGet(HttpServletRequest req, HttpServletResponse resp)
        {
            try
            {
                resp.setContentType("text/html");
                resp.getWriter().println(Launch(req.GetPathAndQuery()));
                resp.getWriter().flush();
            }
            catch (csharp.ThrowableException ex)
            {
                // either swallow of throw a runtime exception

                ((java.lang.Throwable)(object)ex).printStackTrace();

            }
        }
        // http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html#site-control
        // http://board.flashkit.com/board/showthread.php?t=782484

        protected override void doGet(HttpServletRequest req, HttpServletResponse resp)
        {
            try
            {
                resp.setContentType("application/rss+xml");

                resp.getWriter().print(GetContent());

                resp.getWriter().flush();
            }
            catch (csharp.ThrowableException ex)
            {
                // either swallow of throw a runtime exception

                ((java.lang.Throwable)(object) ex).printStackTrace();
            }
        }
        // http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html#site-control
        // http://board.flashkit.com/board/showthread.php?t=782484

        protected override void doGet(HttpServletRequest req, HttpServletResponse resp)
        {
            try
            {
                resp.setContentType(YAMLDocument.ContentType);

                resp.getWriter().print(GameReferenceExtensions.Default.ToYAML());

                resp.getWriter().flush();
            }
            catch (csharp.ThrowableException ex)
            {
                // either swallow of throw a runtime exception

                ((java.lang.Throwable)(object) ex).printStackTrace();
            }
        }
        // http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html#site-control
        // http://board.flashkit.com/board/showthread.php?t=782484

        protected override void doGet(HttpServletRequest req, HttpServletResponse resp)
        {
            try
            {
                resp.setContentType(ZIPFile.ContentType);

                resp.getOutputStream().write((sbyte[])(object)GetContent());

                resp.getOutputStream().flush();
            }
            catch (csharp.ThrowableException ex)
            {
                // either swallow of throw a runtime exception

                ((java.lang.Throwable)(object) ex).printStackTrace();
            }
        }
        // http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html#site-control
        // http://board.flashkit.com/board/showthread.php?t=782484
        protected override void doGet(HttpServletRequest req, HttpServletResponse resp)
        {
            try
            {
                resp.setContentType(ZIPFile.ContentType);

                resp.getOutputStream().write((sbyte[])(object)GetContent());

                resp.getOutputStream().flush();
            }
            catch (csharp.ThrowableException ex)
            {
                // either swallow of throw a runtime exception

                ((java.lang.Throwable)(object)ex).printStackTrace();

            }
        }
        // http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html#site-control
        // http://board.flashkit.com/board/showthread.php?t=782484
        protected override void doGet(HttpServletRequest req, HttpServletResponse resp)
        {
            try
            {
                resp.setContentType(YAMLDocument.ContentType);

                resp.getWriter().print(GameReferenceExtensions.Default.ToYAML());

                resp.getWriter().flush();
            }
            catch (csharp.ThrowableException ex)
            {
                // either swallow of throw a runtime exception

                ((java.lang.Throwable)(object)ex).printStackTrace();

            }
        }
        // http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html#site-control
        // http://board.flashkit.com/board/showthread.php?t=782484
        protected override void doGet(HttpServletRequest req, HttpServletResponse resp)
        {
            try
            {
                resp.setContentType("application/rss+xml");

                resp.getWriter().print(GetContent());

                resp.getWriter().flush();
            }
            catch (csharp.ThrowableException ex)
            {
                // either swallow of throw a runtime exception

                ((java.lang.Throwable)(object)ex).printStackTrace();

            }
        }
예제 #22
0
        protected override void doGet(HttpServletRequest request, HttpServletResponse response)
        {
            response.setContentType("text/plain");
            StreamWriter output = response.getWriter();

            HttpSession session = request.getSession(true);
            int?        counter = (int?)session.getAttribute("Counter");

            if (counter == null)
            {
                output.WriteLine("No session");
                session.setAttribute("Counter", 1);
            }
            else
            {
                output.WriteLine("Counter.." + counter);
                session.setAttribute("Counter", counter + 1);
            }
        }
예제 #23
0
 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)
     {
         Trace.WriteLine(String.Format("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();
     }
 }
예제 #24
0
        protected override void doGet(HttpServletRequest request, HttpServletResponse response)
        {
            response.setContentType("text/plain");
            StreamWriter output     = response.getWriter();
            String       counterStr = null;

            Cookie[] cookies = request.getCookies();
            if (cookies == null)
            {
                output.WriteLine("cookies == null");
            }
            else
            {
                output.WriteLine("cookies.length.." + cookies.Length);
                for (int i = 0; i < cookies.Length; i++)
                {
                    output.WriteLine("cookies[" + i + "].."
                                     + cookies[i].getName() + "/" + cookies[i].getValue());
                    if (cookies[i].getName().Equals("COUNTER"))
                    {
                        counterStr = cookies[i].getValue();
                    }
                }
            }
            int counter;

            if (counterStr == null)
            {
                counter = 1;
            }
            else
            {
                counter = Int32.Parse(counterStr) + 1;
            }
            Cookie newCookie = new Cookie("COUNTER", "" + counter);

            response.addCookie(newCookie);
        }
예제 #25
0
        protected override void doGet(HttpServletRequest request, HttpServletResponse response)
        {
            response.setContentType("text/plain; charset=UTF-8");
            StreamWriter output = response.getWriter();

            String postalCode = request.getParameter("postalCode");
            String ret;

            if (postalCode.Equals("162-0846"))
            {
                ret = "東京都新宿区市谷左内町";
            }
            else if (postalCode.Equals("100-0014"))
            {
                ret = "東京都千代田区永田町";
            }
            else
            {
                ret = "不明";
            }
            response.setStatus(HttpServletResponse.SC_OK);
            output.WriteLine(ret);
        }
예제 #26
0
        protected override void service(HttpServletRequest req, HttpServletResponse resp)
        {
            const string assemblies  = "/assemblies";
            const string getping     = "getping";
            const string setping     = "setping";
            const string version     = "2.2";
            string       servletPath = req.getServletPath();

            if (String.CompareOrdinal(assemblies, 0, servletPath, 0, assemblies.Length) == 0)
            {
                if (servletPath.Length == assemblies.Length ||
                    servletPath [assemblies.Length] == '/')
                {
                    string requestURI = req.getRequestURI();
                    bool   getp       = requestURI.EndsWith(getping, StringComparison.Ordinal);
                    if (!getp && requestURI.EndsWith(setping, StringComparison.Ordinal))
                    {
                        getServletContext().setAttribute(getping, version);
                        getp = true;
                    }

                    if (getp)
                    {
                        string ping = (string)getServletContext().getAttribute(getping);
                        if (ping == null)
                        {
                            ping = "0";
                        }
                        resp.getOutputStream().print(ping);
                        return;
                    }
                }
            }
            resp.setContentType("text/html");

            try
            {
                // Very important - to update Virtual Path!!!
                AppDomain servletDomain = (AppDomain)this.getServletContext().getAttribute(J2EEConsts.APP_DOMAIN);
                if (!_appVirDirInited)
                {
                    string appVPath = req.getContextPath();
                    if (appVPath == null || appVPath.Length == 0)
                    {
                        appVPath = "/";
                    }
                    servletDomain.SetData(IAppDomainConfig.APP_VIRT_DIR, appVPath);
                    servletDomain.SetData(".hostingVirtualPath", req.getContextPath());
                    _appVirDirInited = true;
                }

                // Put to the TLS current AppDomain of the servlet, so anyone can use it.
                [email protected](servletDomain);

                // put request to the TLS
                //Thread.SetData(_servletRequestSlot, req);
                //// put response to the TLS
                //Thread.SetData(_servletResponseSlot, resp);
                //// 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");

                HttpWorkerRequest gwr          = new ServletWorkerRequest(this, req, resp);
                CultureInfo       culture      = (CultureInfo)[email protected](req.getLocale());
                Thread            currentTread = Thread.CurrentThread;
                currentTread.CurrentCulture   = culture;
                currentTread.CurrentUICulture = culture;
                HttpRuntime.ProcessRequest(gwr);
            }
            finally
            {
                HttpContext.Current = null;
                //Thread.SetData(_servletRequestSlot, null);
                //Thread.SetData(_servletResponseSlot, null);
                //Thread.SetData(_servletSlot, null);
                [email protected]();
            }
        }
        public override void service(ServletRequest request, ServletResponse response)

        {
            QuercusHttpServletRequest req
                = new QuercusHttpServletRequestImpl((HttpServletRequest)request);
            HttpServletResponse res = (HttpServletResponse)response;

            string uri = QuercusRequestAdapter.getPageURI(req);

            CacheEntry entry = _cache.get(uri);

            if (entry == null)
            {
                string path    = getPath(req);
                string relPath = path.getUserPath();

                string mimeType = _context.getMimeType(uri);

                entry = new CacheEntry(path, relPath, mimeType);
                _cache.put(uri, entry);
            }
            else if (entry.isModified())
            {
                entry = new CacheEntry(entry.getPath(),
                                       entry.getRelPath(),
                                       entry.getMimeType());

                _cache.put(uri, entry);
            }

            string ifMatch = req.getHeader("If-None-Match");
            string etag    = entry.getEtag();

            if (ifMatch != null && ifMatch.equals(etag))
            {
                res.addHeader("ETag", etag);
                res.sendError(HttpServletResponse.SC_NOT_MODIFIED);
                return;
            }

            string lastModified = entry.getLastModifiedString();

            if (ifMatch == null)
            {
                string ifModified = req.getHeader("If-Modified-Since");

                bool isModified = true;

                if (ifModified == null)
                {
                }
                else if (ifModified.equals(lastModified))
                {
                    isModified = false;
                }
                else
                {
                    long ifModifiedTime;

                    QDate date = QDate.allocateLocalDate();

                    try {
                        ifModifiedTime = date.parseDate(ifModified);
                    } catch (Exception e) {
                        log.log(Level.FINER, e.ToString(), e);

                        ifModifiedTime = 0;
                    }

                    QDate.freeLocalDate(date);

                    isModified = ifModifiedTime == 0 ||
                                 ifModifiedTime != entry.getLastModified();
                }

                if (!isModified)
                {
                    if (etag != null)
                    {
                        res.addHeader("ETag", etag);
                    }

                    res.sendError(HttpServletResponse.SC_NOT_MODIFIED);
                    return;
                }
            }

            res.addHeader("ETag", etag);
            res.addHeader("Last-Modified", lastModified);

            string mime = entry.getMimeType();

            if (mime != null)
            {
                res.setContentType(mime);
            }

            res.setContentLength((int)entry.getLength());

            string method = req.getMethod();

            if (method.equalsIgnoreCase("HEAD"))
            {
                return;
            }

            string path = entry.getPath();

            if (path.isDirectory())
            {
                res.sendError(HttpServletResponse.SC_NOT_FOUND);

                return;
            }
            else if (!path.canRead())
            {
                res.sendError(HttpServletResponse.SC_NOT_FOUND);

                return;
            }

            OutputStream os = response.getOutputStream();

            path.writeToStream(os);
        }
예제 #28
0
        override protected void service(HttpServletRequest req, HttpServletResponse resp)
        {
            resp.setHeader("X-Powered-By", "ASP.NET");
            resp.setHeader("X-AspNet-Version", "1.1.4322");

            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
            {
                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);
                    byte[] buf = new byte[4 * 1024];                      // 4K buffer
                    int    bytesRead;
                    while ((bytesRead = fis.Read(buf, 0, buf.Length)) != -1 &&
                           bytesRead != 0)
                    {
                        hos.write(TypeUtils.ToSByteArray(buf), 0, bytesRead);
                    }
                }
                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.");
                hos.print(((HttpException)myExp).GetHtmlErrorMessage());
                hos.flush();
            }
            catch (Exception e)
            {
                Trace.WriteLine(String.Format("ERROR in Static File Reading {0},{1}", e.GetType(), e.Message));
                resp.setStatus(500);
                HttpException myExp = new HttpException("Exception in Reading static file", e);
                hos.print(((HttpException)myExp).GetHtmlErrorMessage());
                hos.flush();
            }
        }
예제 #29
0
		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) 
			{
				Trace.WriteLine (String.Format ("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();
			}
		}
예제 #30
0
		protected override void service (HttpServletRequest req, HttpServletResponse resp)
		{
			const string assemblies = "/assemblies";
			const string getping = "getping";
			const string setping = "setping";
            const string version = "2.2";
			string servletPath = req.getServletPath ();

			if (String.CompareOrdinal (assemblies, 0, servletPath, 0, assemblies.Length) == 0) {
				if (servletPath.Length == assemblies.Length ||
						servletPath [assemblies.Length] == '/') {
					string requestURI = req.getRequestURI ();
					bool getp = requestURI.EndsWith (getping, StringComparison.Ordinal);
					if (!getp && requestURI.EndsWith (setping, StringComparison.Ordinal)) {
                        getServletContext().setAttribute(getping, version);
						getp = true;
					}

					if (getp) {
						string ping = (string) getServletContext ().getAttribute (getping);
						if (ping == null)
							ping = "0";
						resp.getOutputStream ().print (ping);
						return;
					}
				}
			}
			resp.setContentType ("text/html");

			try 
			{
				// Very important - to update Virtual Path!!!
				AppDomain servletDomain = (AppDomain)this.getServletContext().getAttribute(J2EEConsts.APP_DOMAIN);
				if (!_appVirDirInited) {
					string appVPath = req.getContextPath ();
					if (appVPath == null || appVPath.Length == 0)
						appVPath = "/";
					servletDomain.SetData (IAppDomainConfig.APP_VIRT_DIR, appVPath);
					servletDomain.SetData (".hostingVirtualPath", req.getContextPath ());
					_appVirDirInited = true;
				}

				// Put to the TLS current AppDomain of the servlet, so anyone can use it.
				[email protected](servletDomain);

				// put request to the TLS
				//Thread.SetData(_servletRequestSlot, req);
				//// put response to the TLS
				//Thread.SetData(_servletResponseSlot, resp);
				//// 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");

				HttpWorkerRequest gwr = new ServletWorkerRequest (this, req, resp);
				CultureInfo culture = (CultureInfo) [email protected] (req.getLocale ());
				Thread currentTread = Thread.CurrentThread;
				currentTread.CurrentCulture = culture;
				currentTread.CurrentUICulture = culture;
				HttpRuntime.ProcessRequest(gwr);
			}
			finally 
			{
				HttpContext.Current = null;
				//Thread.SetData(_servletRequestSlot, null);
				//Thread.SetData(_servletResponseSlot, null);
				//Thread.SetData(_servletSlot, null);
				[email protected]();
			}
		}