📄 debugservlet.java
字号:
showDebugRow("isCommitted()", ""+resp.isCommitted() ); out.println( "</table>" ); } /** * Emit debugging information for all fields of an Object. */ protected void showDebugAllInstanceFields(Object o, Class c) { if (c == null) c = o.getClass(); out.println( "<p>Field values for (" + c.getName() + ") " + o.toString() ); out.println( "<table border=1 width=\"100%\">" ); java.lang.reflect.Field locals[] = c.getDeclaredFields(); // Sort the fields alphabetically Arrays.sort(locals, new Comparator() { public int compare(Object x, Object y) { if (x==y) return 0; if (x==null) return 1; if (y==null) return -1; if (x.getClass() != y.getClass()) return 0; if (!(x instanceof java.lang.reflect.Field)) return 0; java.lang.reflect.Field f1, f2; f1 = (java.lang.reflect.Field) x; f2 = (java.lang.reflect.Field) y; return f1.getName().compareTo(f2.getName()); } } ); for (int i = 0; i < locals.length; i++) { String name = locals[i].getName(); try { Object field = locals[i].get(o); showDebugRow( name, field ); } catch (IllegalAccessException e) { // Ignore inaccessible private fields } catch (Exception e) { showDebugRow( name, "" + e ); } } out.println( "</table>" ); // Show fields from superclass, // but don't recurse above SearchServlet or show Object if (c.getSuperclass()!=null) { if (c!=SearchServlet.class && c.getSuperclass()!=Object.class) showDebugAllInstanceFields(o, c.getSuperclass()); } // "this$0" is the magic field name Java uses to refer to the enclosing class try { if (c.getDeclaringClass() != null && c.getDeclaredField("this$0") != null) showDebugAllInstanceFields(c.getDeclaredField("this$0").get(o),null); } catch (NoSuchFieldException e) { } catch (IllegalAccessException e) { } catch (SecurityException e) { }; } protected void showDebugSearchStatus() { // Show status of this search request out.println( "<p><b>SearchRequest Status</b>" ); out.println( "server=" + server ); if (server != null && server instanceof UltraseekServer) try { out.println( " remote version " + ((UltraseekServer) server).getVersionString()); } catch (IOException e) { out.println( " exception fetching remote version " + e ); } showDebugAllInstanceFields(this, null); } protected void showDebugJRESettings() { out.print("<p><a name=\"showDebugJRESettings\">"); out.print("<b>JRE Properties</b>" ); out.println("</a>"); out.println( "<table border=1 width=\"100%\">" ); showDebugRow( "System.err", System.err ); showDebugRow( "System.in", System.in ); showDebugRow( "System.out", System.out ); showDebugRow( "System.getSecurityManager()", System.getSecurityManager() ); try { Properties sysp = System.getProperties(); Iterator e = sortEnumeration(sysp.propertyNames()); while (e.hasNext()) { String parm = (String) e.next(); String val = sysp.getProperty(parm); showDebugRow( parm, val ); } } catch (SecurityException e) { out.println( "Security Exception while getting properties:\n" + e ); } Runtime rt = java.lang.Runtime.getRuntime(); showDebugRow( "Runtime.freeMemory()", "" + rt.freeMemory() ); showDebugRow( "Runtime.totalMemory()", "" + rt.totalMemory() ); // JDK 1.4 required //showDebugRow( "Runtime.availableProcessors()", "" + rt.availableProcessors() ); //showDebugRow( "Runtime.maxMemory()", "" + rt.maxMemory() ); out.println( "</table>" ); } protected void showServerSelector() { String serverString = "null"; String remoteVersion = ""; if (ultraseek!=null) { try { URL url = new URL(ultraseek.getProtocol(),ultraseek.getHost(),ultraseek.getPort(),""); serverString = url.toString(); remoteVersion = ultraseek.getVersionString(); } catch (IOException e) { out.print( "<br>Exception: " + e ); } } out.print("<form name=\"ServerSelector\" method=GET accept-charset=\""); out.print(page_output_charset); out.print("\" action=\""); printHTMLEncoded(out,makeURLRetrySearch()); out.println("\">"); out.print(" server: "); out.print("<input type=text size=40 name=\"server\" value=\""); out.print( serverString ); out.print("\">"); if (!isEmpty(remoteVersion)) out.print( " (" + remoteVersion + ")" ); out.println("</form>"); } protected String makeStyleURL(String style) { return makeRelativeURL( Arrays.asList(new String[] {"style=" + style}), // new Arrays.asList(new String[] {"style"}), // Delete null ); // preserve all } protected void showStyleSelector() { try { Collection styles = ultraseek.getStyles(); if (!styles.isEmpty()) { String currentStyle = req.getParameter("style"); if (currentStyle==null) currentStyle = ultraseek.getDefaultStyle(); Iterator it = styles.iterator(); while (it.hasNext()) { String style = (String) it.next(); out.print(" "); if (style.equals(currentStyle)) { out.print( style ); } else { showHREF( makeStyleURL(style), style ); }; out.println(" "); } } } catch (IOException e) { out.print( "<br>Exception: " + e ); }; } /** * Show a debugging toolbar above the search result display. */ protected void showBodyHeader() throws ServletException { // Regardless of style setting - always show debugging output as black on white if (!(debug || "YES".equals(getParameterString("debug")))) return; out.println("<style type=\"text/css\">"); out.println("DIV.DebugServlet {"); out.println(" background-color: white;"); out.println(" foreground-color: black;"); out.println("}"); out.println("</style>"); out.print("<div class=DebugServlet>"); out.print("<font size=\"-1\">"); out.print("<table width=\"100%\"><tr valign=\"top\"><td align=\"left\">"); showServerSelector(); out.print("</td><td align=\"center\">"); showStyleSelector(); out.print("</td><td align=\"right\">"); showDebugSearchOnServerLink(); // link to Python interface out.print("</td></tr></table>"); out.println("</font>"); out.print("<hr>"); out.print("</div>"); // class=DebugServlet request_start_time = System.currentTimeMillis(); super.showBodyHeader(); } /** * Extends the servlet's HTTP query parameter parsing to include * debugging parameters. * <ul> * <li>The "debug=YES/NO" parameter will toggle debugging output on/off * for this Servlet. * <li>The "server=" parameter will change the Ultraseek server being used. * </ul> */ protected void parseQueryParameters() throws IOException, ServletException { super.parseQueryParameters(); if (req.getParameter("debug")!=null) debug = req.getParameter("debug").equals("YES"); String urlString = req.getParameter("server"); if (urlString!=null) { try { // REMIND: server should not be a sticky parameter if ("".equals(urlString)) ultraseekURL = null; else ultraseekURL = new URL(urlString); configuration.update(); } catch (MalformedURLException e) { out.println( "<br>Failed to change server to " + urlString + " due to: " + e ); } catch (ServletException e) { out.println( "<br>Problem changing server to " + urlString + " due to: " + e ); } } } } protected SearchServlet.SearchRequest makeSearchRequest(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { return new SearchRequest(req,resp); } /** * Set debug to <code>true</code> to emit debug comments in HTML output */ protected boolean debug = true; protected boolean debug_flush = false; // flush HTML output every debug statement /** * Utilities for emitting debug messages into the page output. */ protected void DEBUG(PrintWriter out, String msg) { if (debug) { try { out.print( "\n"); out.print( "<!-- " ); printHTMLEncoded(out,msg); out.print( " -->" ); out.print( "\n"); if (debug_flush) out.flush(); } catch (Exception e) {}; } } protected void DEBUG(HttpServletResponse resp, String msg) { if (debug) { try { DEBUG(resp.getWriter(),msg); } catch (IOException e) {}; } } protected void DEBUG(HttpServletResponse resp, Exception e) { if (debug) { try { PrintWriter out = resp.getWriter(); //out.print( "\n<!-- "); out.print("\n<pre>\n"); e.printStackTrace(out); // this should be HTML quoted out.print("\n</pre>\n"); //out.print( " -->" ); } catch (Exception e2) {}; } } /** * Convert an <code>Enumeration</code> into a sorted <code>Iterator</code>. * <p> * Many of the older Java and Servlet API's return an <code>Enumeration</code>, * when a sorted <code>Iterator</code> would be more appropriate for the * display of output. * @param e the <code>Enumeration</code> to sort. * @return an <code>Iterator</code> over the sorted <code>Set</code> of elements * from the <code>Enumeration</code>. * @see TreeSet */ protected static Iterator sortEnumeration(Enumeration e) { TreeSet ts = new TreeSet(); while (e.hasMoreElements()) { Object o = e.nextElement(); ts.add(o); } return ts.iterator(); } /** * An implementation of the Jakarta commons logging SimpleLogger * that forwards all output streams to the Servlet log. * @serial exclude */ public class SimpleLogServletLogAdaptor extends org.apache.commons.logging.impl.SimpleLog { public SimpleLogServletLogAdaptor(String name) { super(name); } protected void write(StringBuffer buffer) { doLog(buffer.toString()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -