예제 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void doFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain chain) throws java.io.IOException, javax.servlet.ServletException
        public override void DoFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
        {
            HttpServletRequest  request  = ( HttpServletRequest )servletRequest;
            HttpServletResponse response = ( HttpServletResponse )servletResponse;

            response.setHeader(ACCESS_CONTROL_ALLOW_ORIGIN, _accessControlAllowOrigin);
            if (!string.ReferenceEquals(_vary, null))
            {
                response.setHeader(VARY, _vary);
            }

            IEnumerator <string> requestMethodEnumeration = request.getHeaders(ACCESS_CONTROL_REQUEST_METHOD);

            if (requestMethodEnumeration != null)
            {
                while (requestMethodEnumeration.MoveNext())
                {
                    string requestMethod = requestMethodEnumeration.Current;
                    AddAllowedMethodIfValid(requestMethod, response);
                }
            }

            IEnumerator <string> requestHeaderEnumeration = request.getHeaders(ACCESS_CONTROL_REQUEST_HEADERS);

            if (requestHeaderEnumeration != null)
            {
                while (requestHeaderEnumeration.MoveNext())
                {
                    string requestHeader = requestHeaderEnumeration.Current;
                    AddAllowedHeaderIfValid(requestHeader, response);
                }
            }

            chain.doFilter(request, response);
        }
		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();
			}
		}
예제 #3
0
        private void echoQString(HttpServletRequest req, HttpServletResponse resp)
        {
            string qstring = req.QueryString;

            if (!string.ReferenceEquals(qstring, null))
            {
                resp.setHeader("Query-String", qstring);
            }
        }
예제 #4
0
        private void echoHeader(HttpServletRequest req, HttpServletResponse resp)
        {
            string s = req.getHeader("Echo-Header");

            if (!string.ReferenceEquals(s, null))
            {
                resp.setHeader("Echo-Header", s);
            }
        }
예제 #5
0
		/// <summary>
		/// 自定义的全局错误
		/// </summary>
		/// <param name="request"> </param>
		/// <param name="response"> </param>
		/// <param name="message"> </param>
		/// <param name="errorCode">
		/// </param>
		/// <exception cref="IOException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected void returnJsonSystemError(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String message, com.baidu.dsp.common.constant.ErrorCode errorCode) throws java.io.IOException
		protected internal virtual void returnJsonSystemError(HttpServletRequest request, HttpServletResponse response, string message, ErrorCode errorCode)
		{

			JsonObjectBase jsonObjectBase = JsonObjectUtils.buildGlobalError(message, errorCode);

			response.setHeader("Cache-Control", "no-cache");
			response.ContentType = "application/json;charset=UTF-8";
			response.CharacterEncoding = "UTF-8";

			response.Writer.write(JsonUtils.toJson(jsonObjectBase));
		}
예제 #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws java.io.IOException, ServletException
        public virtual void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final javax.servlet.http.HttpServletRequest request = (javax.servlet.http.HttpServletRequest) req;
            HttpServletRequest request = (HttpServletRequest)req;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final javax.servlet.http.HttpServletResponse response = (javax.servlet.http.HttpServletResponse) resp;
            HttpServletResponse response = (HttpServletResponse)resp;

            if ("GET".Equals(request.Method) && !request.RequestURI.EndsWith("xml"))
            {
                response.setHeader("Cache-Control", "no-cache");
            }

            chain.doFilter(req, resp);
        }
예제 #7
0
 public virtual void augmentResponseByAuthenticationChallenge(HttpServletResponse response, ProcessEngine engine)
 {
     response.setHeader(HttpHeaders.WWW_AUTHENTICATE, BASIC_AUTH_HEADER_PREFIX + "realm=\"" + engine.Name + "\"");
 }
예제 #8
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]();
			}
		}
예제 #9
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]();
            }
        }
예제 #10
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();
            }
        }