/// <exception cref="System.Exception"/> private void TestGetToken(string renewer, Text expectedTokenKind) { DelegationTokenAuthenticator.DelegationTokenOperation op = DelegationTokenAuthenticator.DelegationTokenOperation .Getdelegationtoken; HttpServletRequest request = Org.Mockito.Mockito.Mock <HttpServletRequest>(); HttpServletResponse response = Org.Mockito.Mockito.Mock <HttpServletResponse>(); Org.Mockito.Mockito.When(request.GetQueryString()).ThenReturn(DelegationTokenAuthenticator .OpParam + "=" + op.ToString()); Org.Mockito.Mockito.When(request.GetMethod()).ThenReturn(op.GetHttpMethod()); AuthenticationToken token = Org.Mockito.Mockito.Mock <AuthenticationToken>(); Org.Mockito.Mockito.When(token.GetUserName()).ThenReturn("user"); Org.Mockito.Mockito.When(response.GetWriter()).ThenReturn(new PrintWriter(new StringWriter ())); NUnit.Framework.Assert.IsFalse(handler.ManagementOperation(token, request, response )); Org.Mockito.Mockito.When(request.GetQueryString()).ThenReturn(DelegationTokenAuthenticator .OpParam + "=" + op.ToString() + "&" + DelegationTokenAuthenticator.RenewerParam + "=" + renewer); Org.Mockito.Mockito.Reset(response); Org.Mockito.Mockito.Reset(token); Org.Mockito.Mockito.When(token.GetUserName()).ThenReturn("user"); StringWriter writer = new StringWriter(); PrintWriter pwriter = new PrintWriter(writer); Org.Mockito.Mockito.When(response.GetWriter()).ThenReturn(pwriter); NUnit.Framework.Assert.IsFalse(handler.ManagementOperation(token, request, response )); if (renewer == null) { Org.Mockito.Mockito.Verify(token).GetUserName(); } else { Org.Mockito.Mockito.Verify(token).GetUserName(); } Org.Mockito.Mockito.Verify(response).SetStatus(HttpServletResponse.ScOk); Org.Mockito.Mockito.Verify(response).SetContentType(MediaType.ApplicationJson); pwriter.Close(); string responseOutput = writer.ToString(); string tokenLabel = DelegationTokenAuthenticator.DelegationTokenJson; Assert.True(responseOutput.Contains(tokenLabel)); Assert.True(responseOutput.Contains(DelegationTokenAuthenticator .DelegationTokenUrlStringJson)); ObjectMapper jsonMapper = new ObjectMapper(); IDictionary json = jsonMapper.ReadValue <IDictionary>(responseOutput); json = (IDictionary)json[tokenLabel]; string tokenStr; tokenStr = (string)json[DelegationTokenAuthenticator.DelegationTokenUrlStringJson ]; Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> dt = new Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier>(); dt.DecodeFromUrlString(tokenStr); handler.GetTokenManager().VerifyToken(dt); Assert.Equal(expectedTokenKind, dt.GetKind()); }
/// <summary>Output 404 with appropriate message.</summary> /// <param name="resp">the http response.</param> /// <param name="message">the message to include on the page.</param> /// <exception cref="System.IO.IOException">on any error.</exception> public static void NotFound(HttpServletResponse resp, string message) { resp.SetStatus(HttpServletResponse.ScNotFound); resp.SetContentType(MimeType.Html); ProxyUtils.Page p = new ProxyUtils.Page(resp.GetWriter()); p.Html().H1(message).(); }
public virtual void TestCreateServletException() { StringWriter writer = new StringWriter(); PrintWriter printWriter = new PrintWriter(writer); HttpServletResponse response = Org.Mockito.Mockito.Mock <HttpServletResponse>(); Org.Mockito.Mockito.When(response.GetWriter()).ThenReturn(printWriter); int status = HttpServletResponse.ScInternalServerError; Exception ex = new IOException("Hello IOEX"); HttpExceptionUtils.CreateServletExceptionResponse(response, status, ex); Org.Mockito.Mockito.Verify(response).SetStatus(status); Org.Mockito.Mockito.Verify(response).SetContentType(Org.Mockito.Mockito.Eq("application/json" )); ObjectMapper mapper = new ObjectMapper(); IDictionary json = mapper.ReadValue <IDictionary>(writer.ToString()); json = (IDictionary)json[HttpExceptionUtils.ErrorJson]; Assert.Equal(typeof(IOException).FullName, json[HttpExceptionUtils .ErrorClassnameJson]); Assert.Equal(typeof(IOException).Name, json[HttpExceptionUtils .ErrorExceptionJson]); Assert.Equal("Hello IOEX", json[HttpExceptionUtils.ErrorMessageJson ]); }
/// <exception cref="Javax.Servlet.ServletException"/> /// <exception cref="System.IO.IOException"/> protected override void DoGet(HttpServletRequest request, HttpServletResponse response ) { PrintWriter @out = response.GetWriter(); string path = ServletUtil.GetDecodedPath(request, "/getFileChecksum"); XMLOutputter xml = new XMLOutputter(@out, "UTF-8"); xml.Declaration(); ServletContext context = GetServletContext(); DataNode datanode = (DataNode)context.GetAttribute("datanode"); Configuration conf = new HdfsConfiguration(datanode.GetConf()); try { DFSClient dfs = DatanodeJspHelper.GetDFSClient(request, datanode, conf, GetUGI(request , conf)); MD5MD5CRC32FileChecksum checksum = dfs.GetFileChecksum(path, long.MaxValue); MD5MD5CRC32FileChecksum.Write(xml, checksum); } catch (IOException ioe) { WriteXml(ioe, path, xml); } catch (Exception e) { WriteXml(e, path, xml); } xml.EndDocument(); }
/// <exception cref="Javax.Servlet.ServletException"/> /// <exception cref="System.IO.IOException"/> protected override void DoGet(HttpServletRequest request, HttpServletResponse response ) { PrintWriter @out = response.GetWriter(); IDictionary <string, string[]> @params = request.GetParameterMap(); ICollection <string> keys = new TreeSet <string>(@params.Keys); foreach (string key in keys) { @out.Write(key); @out.Write(':'); string[] values = @params[key]; if (values.Length > 0) { @out.Write(values[0]); for (int i = 1; i < values.Length; ++i) { @out.Write(','); @out.Write(values[i]); } } @out.Write('\n'); } @out.Close(); }
/// <exception cref="Javax.Servlet.ServletException"/> /// <exception cref="System.IO.IOException"/> protected override void DoPost(HttpServletRequest req, HttpServletResponse resp) { TextWriter writer = resp.GetWriter(); writer.Write("ping: "); IOUtils.Copy(req.GetReader(), writer); resp.SetStatus(HttpServletResponse.ScOk); }
/// <exception cref="Javax.Servlet.ServletException"/> /// <exception cref="System.IO.IOException"/> protected override void DoGet(HttpServletRequest request, HttpServletResponse response ) { response.SetContentType("text/html"); PrintWriter @out = response.GetWriter(); @out.Write("hello world"); @out.Close(); }
/// <exception cref="Javax.Servlet.ServletException"/> /// <exception cref="System.IO.IOException"/> protected override void DoGet(HttpServletRequest req, HttpServletResponse resp) { Log.Info("GET"); resp.SetContentType("text/html"); PrintWriter @out = resp.GetWriter(); Reconfigurable reconf = GetReconfigurable(req); string nodeName = reconf.GetType().GetCanonicalName(); PrintHeader(@out, nodeName); PrintConf(@out, reconf); PrintFooter(@out); }
/// <exception cref="System.IO.IOException"/> protected override void DoGet(HttpServletRequest req, HttpServletResponse resp) { resp.SetContentType("application/json; charset=UTF-8"); StartupProgress prog = NameNodeHttpServer.GetStartupProgressFromContext(GetServletContext ()); StartupProgressView view = prog.CreateView(); JsonGenerator json = new JsonFactory().CreateJsonGenerator(resp.GetWriter()); try { json.WriteStartObject(); json.WriteNumberField(ElapsedTime, view.GetElapsedTime()); json.WriteNumberField(PercentComplete, view.GetPercentComplete()); json.WriteArrayFieldStart(Phases); foreach (Phase phase in view.GetPhases()) { json.WriteStartObject(); json.WriteStringField(Name, phase.GetName()); json.WriteStringField(Desc, phase.GetDescription()); json.WriteStringField(Status, view.GetStatus(phase).ToString()); json.WriteNumberField(PercentComplete, view.GetPercentComplete(phase)); json.WriteNumberField(ElapsedTime, view.GetElapsedTime(phase)); WriteStringFieldIfNotNull(json, File, view.GetFile(phase)); WriteNumberFieldIfDefined(json, Size, view.GetSize(phase)); json.WriteArrayFieldStart(Steps); foreach (Step step in view.GetSteps(phase)) { json.WriteStartObject(); StepType type = step.GetType(); if (type != null) { json.WriteStringField(Name, type.GetName()); json.WriteStringField(Desc, type.GetDescription()); } json.WriteNumberField(Count, view.GetCount(phase, step)); WriteStringFieldIfNotNull(json, File, step.GetFile()); WriteNumberFieldIfDefined(json, Size, step.GetSize()); json.WriteNumberField(Total, view.GetTotal(phase, step)); json.WriteNumberField(PercentComplete, view.GetPercentComplete(phase, step)); json.WriteNumberField(ElapsedTime, view.GetElapsedTime(phase, step)); json.WriteEndObject(); } json.WriteEndArray(); json.WriteEndObject(); } json.WriteEndArray(); json.WriteEndObject(); } finally { IOUtils.Cleanup(Log, json); } }
/// <exception cref="Javax.Servlet.ServletException"/> /// <exception cref="System.IO.IOException"/> protected override void DoGet(HttpServletRequest req, HttpServletResponse resp) { resp.SetContentType("text/plain"); resp.SetStatus(HttpServletResponse.ScOk); string user = req.GetRemoteUser(); string principal = (req.GetUserPrincipal() != null) ? req.GetUserPrincipal().GetName () : null; TextWriter writer = resp.GetWriter(); writer.Write(MessageFormat.Format("You are: user[{0}] principal[{1}]\n", user, principal )); }
/// <summary>Warn the user that the link may not be safe!</summary> /// <param name="resp">the http response</param> /// <param name="link">the link to point to</param> /// <param name="user">the user that owns the link.</param> /// <exception cref="System.IO.IOException">on any error.</exception> private static void WarnUserPage(HttpServletResponse resp, string link, string user , ApplicationId id) { //Set the cookie when we warn which overrides the query parameter //This is so that if a user passes in the approved query parameter without //having first visited this page then this page will still be displayed resp.AddCookie(MakeCheckCookie(id, false)); resp.SetContentType(MimeType.Html); WebAppProxyServlet.Page p = new WebAppProxyServlet.Page(resp.GetWriter()); p.Html().H1("WARNING: The following page may not be safe!").H3().("click ").A(link , "here").(" to continue to an Application Master web interface owned by ", user ).().(); }
/// <exception cref="Javax.Servlet.ServletException"/> /// <exception cref="System.IO.IOException"/> protected override void DoGet(HttpServletRequest request, HttpServletResponse response ) { if (!HttpServer2.IsInstrumentationAccessAllowed(GetServletContext(), request, response )) { return; } string format = request.GetParameter("format"); ICollection <MetricsContext> allContexts = ContextFactory.GetFactory().GetAllContexts (); if ("json".Equals(format)) { response.SetContentType("application/json; charset=utf-8"); PrintWriter @out = response.GetWriter(); try { // Uses Jetty's built-in JSON support to convert the map into JSON. @out.Write(new JSON().ToJSON(MakeMap(allContexts))); } finally { @out.Close(); } } else { PrintWriter @out = response.GetWriter(); try { PrintMap(@out, MakeMap(allContexts)); } finally { @out.Close(); } } }
public static void FlushOutput(Injector injector) { HttpServletResponse res = injector.GetInstance <HttpServletResponse>(); try { res.GetWriter().Flush(); } catch (Exception e) { throw new RuntimeException(e); } }
internal HttpServletResponse CreateResponse() { try { HttpServletResponse res = Org.Mockito.Mockito.Mock <HttpServletResponse>(); Org.Mockito.Mockito.When(res.GetWriter()).ThenReturn(this.writer); return(res); } catch (Exception e) { throw new WebAppException(e); } }
public override HttpServletResponse Response() { HttpServletResponse result = Org.Mockito.Mockito.Mock <HttpServletResponse>(); try { Org.Mockito.Mockito.When(result.GetWriter()).ThenReturn(new PrintWriter(data)); } catch (IOException) { } return(result); }
/// <exception cref="Javax.Servlet.ServletException"/> /// <exception cref="System.IO.IOException"/> protected override void DoGet(HttpServletRequest req, HttpServletResponse resp) { resp.SetStatus(HttpServletResponse.ScOk); resp.GetWriter().Write("ping"); if (req.GetHeader(DelegationTokenAuthenticator.DelegationTokenHeader) != null) { resp.SetHeader("UsingHeader", "true"); } if (req.GetQueryString() != null && req.GetQueryString().Contains(DelegationTokenAuthenticator .DelegationParam + "=")) { resp.SetHeader("UsingQueryString", "true"); } }
/// <exception cref="System.Exception"/> private void TestInvalidDelegationTokenHeader() { HttpServletRequest request = Org.Mockito.Mockito.Mock <HttpServletRequest>(); HttpServletResponse response = Org.Mockito.Mockito.Mock <HttpServletResponse>(); Org.Mockito.Mockito.When(request.GetHeader(Org.Mockito.Mockito.Eq(DelegationTokenAuthenticator .DelegationTokenHeader))).ThenReturn("invalid"); StringWriter writer = new StringWriter(); Org.Mockito.Mockito.When(response.GetWriter()).ThenReturn(new PrintWriter(writer) ); NUnit.Framework.Assert.IsNull(handler.Authenticate(request, response)); Assert.True(writer.ToString().Contains("AuthenticationException" )); }
/// <exception cref="System.Exception"/> private void TestInvalidDelegationTokenQueryString() { HttpServletRequest request = Org.Mockito.Mockito.Mock <HttpServletRequest>(); HttpServletResponse response = Org.Mockito.Mockito.Mock <HttpServletResponse>(); Org.Mockito.Mockito.When(request.GetQueryString()).ThenReturn(DelegationTokenAuthenticator .DelegationParam + "=invalid"); StringWriter writer = new StringWriter(); Org.Mockito.Mockito.When(response.GetWriter()).ThenReturn(new PrintWriter(writer) ); NUnit.Framework.Assert.IsNull(handler.Authenticate(request, response)); Org.Mockito.Mockito.Verify(response).SetStatus(HttpServletResponse.ScForbidden); Assert.True(writer.ToString().Contains("AuthenticationException" )); }
public virtual void TestInstances() { Injector injector = WebAppTests.CreateMockInjector(this); HttpServletRequest req = injector.GetInstance <HttpServletRequest>(); HttpServletResponse res = injector.GetInstance <HttpServletResponse>(); string val = req.GetParameter("foo"); PrintWriter @out = res.GetWriter(); @out.WriteLine("Hello world!"); LogInstances(req, res, @out); NUnit.Framework.Assert.AreSame(req, injector.GetInstance <HttpServletRequest>()); NUnit.Framework.Assert.AreSame(res, injector.GetInstance <HttpServletResponse>()); NUnit.Framework.Assert.AreSame(this, injector.GetInstance <TestWebAppTests>()); Org.Mockito.Mockito.Verify(req).GetParameter("foo"); Org.Mockito.Mockito.Verify(res).GetWriter(); Org.Mockito.Mockito.Verify(@out).WriteLine("Hello world!"); }
public virtual void SetUp() { startupProgress = new StartupProgress(); ServletContext context = Org.Mockito.Mockito.Mock <ServletContext>(); Org.Mockito.Mockito.When(context.GetAttribute(NameNodeHttpServer.StartupProgressAttributeKey )).ThenReturn(startupProgress); servlet = Org.Mockito.Mockito.Mock <StartupProgressServlet>(); Org.Mockito.Mockito.When(servlet.GetServletContext()).ThenReturn(context); Org.Mockito.Mockito.DoCallRealMethod().When(servlet).DoGet(Any <HttpServletRequest >(), Any <HttpServletResponse>()); req = Org.Mockito.Mockito.Mock <HttpServletRequest>(); respOut = new ByteArrayOutputStream(); PrintWriter writer = new PrintWriter(respOut); resp = Org.Mockito.Mockito.Mock <HttpServletResponse>(); Org.Mockito.Mockito.When(resp.GetWriter()).ThenReturn(writer); }
/// <summary>Creates a HTTP servlet response serializing the exception in it as JSON. /// </summary> /// <param name="response">the servlet response</param> /// <param name="status">the error code to set in the response</param> /// <param name="ex">the exception to serialize in the response</param> /// <exception cref="System.IO.IOException"> /// thrown if there was an error while creating the /// response /// </exception> public static void CreateServletExceptionResponse(HttpServletResponse response, int status, Exception ex) { response.SetStatus(status); response.SetContentType(ApplicationJsonMime); IDictionary <string, object> json = new LinkedHashMap <string, object>(); json[ErrorMessageJson] = GetOneLineMessage(ex); json[ErrorExceptionJson] = ex.GetType().Name; json[ErrorClassnameJson] = ex.GetType().FullName; IDictionary <string, object> jsonResponse = new LinkedHashMap <string, object>(); jsonResponse[ErrorJson] = json; ObjectMapper jsonMapper = new ObjectMapper(); TextWriter writer = response.GetWriter(); jsonMapper.WriterWithDefaultPrettyPrinter().WriteValue(writer, jsonResponse); writer.Flush(); }
/// <exception cref="System.Exception"/> private void TestRenewToken() { DelegationTokenAuthenticator.DelegationTokenOperation op = DelegationTokenAuthenticator.DelegationTokenOperation .Renewdelegationtoken; HttpServletRequest request = Org.Mockito.Mockito.Mock <HttpServletRequest>(); HttpServletResponse response = Org.Mockito.Mockito.Mock <HttpServletResponse>(); Org.Mockito.Mockito.When(request.GetQueryString()).ThenReturn(DelegationTokenAuthenticator .OpParam + "=" + op.ToString()); Org.Mockito.Mockito.When(request.GetMethod()).ThenReturn(op.GetHttpMethod()); NUnit.Framework.Assert.IsFalse(handler.ManagementOperation(null, request, response )); Org.Mockito.Mockito.Verify(response).SetStatus(Org.Mockito.Mockito.Eq(HttpServletResponse .ScUnauthorized)); Org.Mockito.Mockito.Verify(response).SetHeader(Org.Mockito.Mockito.Eq(KerberosAuthenticator .WwwAuthenticate), Org.Mockito.Mockito.Eq("mock")); Org.Mockito.Mockito.Reset(response); AuthenticationToken token = Org.Mockito.Mockito.Mock <AuthenticationToken>(); Org.Mockito.Mockito.When(token.GetUserName()).ThenReturn("user"); NUnit.Framework.Assert.IsFalse(handler.ManagementOperation(token, request, response )); Org.Mockito.Mockito.Verify(response).SendError(Org.Mockito.Mockito.Eq(HttpServletResponse .ScBadRequest), Org.Mockito.Mockito.Contains("requires the parameter [token]")); Org.Mockito.Mockito.Reset(response); StringWriter writer = new StringWriter(); PrintWriter pwriter = new PrintWriter(writer); Org.Mockito.Mockito.When(response.GetWriter()).ThenReturn(pwriter); Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> dToken = (Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier>)handler.GetTokenManager().CreateToken(UserGroupInformation .GetCurrentUser(), "user"); Org.Mockito.Mockito.When(request.GetQueryString()).ThenReturn(DelegationTokenAuthenticator .OpParam + "=" + op.ToString() + "&" + DelegationTokenAuthenticator.TokenParam + "=" + dToken.EncodeToUrlString()); NUnit.Framework.Assert.IsFalse(handler.ManagementOperation(token, request, response )); Org.Mockito.Mockito.Verify(response).SetStatus(HttpServletResponse.ScOk); pwriter.Close(); Assert.True(writer.ToString().Contains("long")); handler.GetTokenManager().VerifyToken(dToken); }
/// <exception cref="Javax.Servlet.ServletException"/> /// <exception cref="System.IO.IOException"/> protected override void DoGet(HttpServletRequest req, HttpServletResponse resp) { UserGroupInformation ugi = HttpUserGroupInformation.Get(); if (ugi != null) { string ret = "remoteuser="******":ugi=" + ugi.GetShortUserName (); if (ugi.GetAuthenticationMethod() == UserGroupInformation.AuthenticationMethod.Proxy) { ret = "realugi=" + ugi.GetRealUser().GetShortUserName() + ":" + ret; } resp.SetStatus(HttpServletResponse.ScOk); resp.GetWriter().Write(ret); } else { resp.SetStatus(HttpServletResponse.ScInternalServerError); } }
/// <summary> /// Handle redirects with a status code that can in future support verbs other /// than GET, thus supporting full REST functionality. /// </summary> /// <remarks> /// Handle redirects with a status code that can in future support verbs other /// than GET, thus supporting full REST functionality. /// <p> /// The target URL is included in the redirect text returned /// <p> /// At the end of this method, the output stream is closed. /// </remarks> /// <param name="request"> /// request (hence: the verb and any other information /// relevant to a redirect) /// </param> /// <param name="response">the response</param> /// <param name="target">the target URL -unencoded</param> /// <exception cref="System.IO.IOException"/> public static void SendRedirect(HttpServletRequest request, HttpServletResponse response , string target) { if (Log.IsDebugEnabled()) { Log.Debug("Redirecting {} {} to {}", request.GetMethod(), request.GetRequestURI() , target); } string location = response.EncodeRedirectURL(target); response.SetStatus(HttpServletResponse.ScFound); response.SetHeader(Location, location); response.SetContentType(MimeType.Html); PrintWriter writer = response.GetWriter(); ProxyUtils.Page p = new ProxyUtils.Page(writer); p.Html().Head().Title("Moved").().Body().H1("Moved").Div().("Content has moved ") .A(location, "here").().().(); writer.Close(); }
/// <exception cref="Javax.Servlet.ServletException"/> /// <exception cref="System.IO.IOException"/> protected override void DoGet(HttpServletRequest request, HttpServletResponse response ) { PrintWriter @out = response.GetWriter(); ICollection <string> sortedKeys = new TreeSet <string>(); Enumeration <string> keys = request.GetParameterNames(); while (keys.MoveNext()) { sortedKeys.AddItem(keys.Current); } foreach (string key in sortedKeys) { @out.Write(key); @out.Write(':'); @out.Write(request.GetParameter(key)); @out.Write('\n'); } @out.Close(); }
/// <summary>Handle fsck request</summary> /// <exception cref="System.IO.IOException"/> protected override void DoGet(HttpServletRequest request, HttpServletResponse response ) { IDictionary <string, string[]> pmap = request.GetParameterMap(); PrintWriter @out = response.GetWriter(); IPAddress remoteAddress = Sharpen.Extensions.GetAddressByName(request.GetRemoteAddr ()); ServletContext context = GetServletContext(); Configuration conf = NameNodeHttpServer.GetConfFromContext(context); UserGroupInformation ugi = GetUGI(request, conf); try { ugi.DoAs(new _PrivilegedExceptionAction_58(context, conf, pmap, @out, remoteAddress )); } catch (Exception e) { response.SendError(400, e.Message); } }
/// <summary>Service a GET request as described below.</summary> /// <remarks> /// Service a GET request as described below. /// Request: /// <c>GET http://<nn>:<port>/listPaths[/<path>][<?option>[&option]*] HTTP/1.1 /// </c> /// Where <i>option</i> (default) in: /// recursive ("no") /// filter (".*") /// exclude ("\..*\.crc") /// Response: A flat list of files/directories in the following format: /// <c> /// <listing path="..." recursive="(yes|no)" filter="..." /// time="yyyy-MM-dd hh:mm:ss UTC" version="..."> /// <directory path="..." modified="yyyy-MM-dd hh:mm:ss"/> /// <file path="..." modified="yyyy-MM-dd'T'hh:mm:ssZ" accesstime="yyyy-MM-dd'T'hh:mm:ssZ" /// blocksize="..." /// replication="..." size="..."/> /// </listing> /// </c> /// </remarks> /// <exception cref="Javax.Servlet.ServletException"/> /// <exception cref="System.IO.IOException"/> protected override void DoGet(HttpServletRequest request, HttpServletResponse response ) { PrintWriter @out = response.GetWriter(); XMLOutputter doc = new XMLOutputter(@out, "UTF-8"); IDictionary <string, string> root = BuildRoot(request, doc); string path = root["path"]; string filePath = ServletUtil.GetDecodedPath(request, "/listPaths"); try { bool recur = "yes".Equals(root["recursive"]); Sharpen.Pattern filter = Sharpen.Pattern.Compile(root["filter"]); Sharpen.Pattern exclude = Sharpen.Pattern.Compile(root["exclude"]); Configuration conf = (Configuration)GetServletContext().GetAttribute(JspHelper.CurrentConf ); GetUGI(request, conf).DoAs(new _PrivilegedExceptionAction_149(this, doc, root, filePath , path, exclude, filter, recur)); } catch (IOException ioe) { WriteXml(ioe, path, doc); } catch (Exception e) { Log.Warn("ListPathServlet encountered InterruptedException", e); response.SendError(400, e.Message); } finally { if (doc != null) { doc.EndDocument(); } if (@out != null) { @out.Close(); } } }
/// <exception cref="Javax.Servlet.ServletException"/> /// <exception cref="System.IO.IOException"/> protected override void DoPost(HttpServletRequest req, HttpServletResponse resp) { Log.Info("POST"); resp.SetContentType("text/html"); PrintWriter @out = resp.GetWriter(); Reconfigurable reconf = GetReconfigurable(req); string nodeName = reconf.GetType().GetCanonicalName(); PrintHeader(@out, nodeName); try { ApplyChanges(@out, reconf, req); } catch (ReconfigurationException e) { resp.SendError(HttpServletResponse.ScInternalServerError, StringUtils.StringifyException (e)); return; } @out.WriteLine("<p><a href=\"" + req.GetServletPath() + "\">back</a></p>"); PrintFooter(@out); }
/// <exception cref="Javax.Servlet.ServletException"/> /// <exception cref="System.IO.IOException"/> protected override void DoGet(HttpServletRequest request, HttpServletResponse response ) { if (!HttpServer2.IsInstrumentationAccessAllowed(GetServletContext(), request, response )) { return; } string format = request.GetParameter(FormatParam); if (null == format) { format = FormatXml; } if (FormatXml.Equals(format)) { response.SetContentType("text/xml; charset=utf-8"); } else { if (FormatJson.Equals(format)) { response.SetContentType("application/json; charset=utf-8"); } } TextWriter @out = response.GetWriter(); try { WriteResponse(GetConfFromContext(), @out, format); } catch (ConfServlet.BadFormatException bfe) { response.SendError(HttpServletResponse.ScBadRequest, bfe.Message); } @out.Close(); }
/// <exception cref="System.IO.IOException"/> protected override void DoGet(HttpServletRequest request, HttpServletResponse response ) { response.SetContentType("text/plain"); DataNode datanode = (DataNode)GetServletContext().GetAttribute("datanode"); BlockScanner blockScanner = datanode.GetBlockScanner(); StringBuilder buffer = new StringBuilder(8 * 1024); if (!blockScanner.IsEnabled()) { Log.Warn("Periodic block scanner is not running"); buffer.Append("Periodic block scanner is not running. " + "Please check the datanode log if this is unexpected." ); } else { buffer.Append("Block Scanner Statistics\n\n"); blockScanner.PrintStats(buffer); } string resp = buffer.ToString(); Log.Trace("Returned Servlet info {}", resp); response.GetWriter().Write(resp); }