📄 debugservlet.java
字号:
out.println( "</td></tr>" ); } protected void showDebugRow(String c1, Object c2) { if (c2==null) showDebugRow(c1,null); else showDebugRow(c1,""+c2); } protected void showDebugSearchOnServerLink() { // Make a link to the Python search page if (server instanceof UltraseekServer) { UltraseekServer us = (UltraseekServer) server; StringBuffer sb = new StringBuffer(256); sb.append( makeAbsoluteUltraseekURL( us ) ); if (getPageDisplayMode()==MODE_INDEX_PAGE) sb.append( "/index.html?charset=utf-8" ); else sb.append( "/query.html?charset=utf-8" ); // Duplicate every parameter for sending to the Python interface Iterator ep = sortEnumeration(req.getParameterNames()); while (ep.hasNext()) { String name = (String)ep.next(); if (name.equals("charset")) continue; name = decodeParameterString(name); String values[] = req.getParameterValues(name); for (int i = 0; i < values.length; i++) { String value = values[i]; value = decodeParameterString(value); sb.append( "&" ); sb.append( encode_URL(name) ); // charset=utf-8 sb.append( "=" ); sb.append( encode_URL(value) ); // charset=utf-8 } } StringBuffer sb2 = new StringBuffer(); sb2.append( "<a href=\"" ); sb2.append( HTMLEncoded(sb.toString()) ); sb2.append( "\">" ); sb2.append( HTMLEncoded("Python search") ); sb2.append( "</a>" ); out.println( sb2 ); } } protected String makeVisibleCookie(Cookie cookie) { StringBuffer sb = new StringBuffer(256); sb.append( cookie.getName() ); sb.append( " Domain=" + cookie.getDomain() ); sb.append( " Path=" + cookie.getPath() ); sb.append( " Comment=" + cookie.getComment() ); sb.append( " MaxAge=" + cookie.getMaxAge() ); sb.append( " Secure=" + cookie.getSecure() ); sb.append( " Version=" + cookie.getVersion() ); sb.append( " " ); sb.append( cookie.getValue() ); return sb.toString(); } protected void showDebugHTTPRequest() { out.print("<p><a NAME=\"showDebugHTTPRequest\">"); out.print( "<b>HTTP Request</b>" ); out.println("</a>"); out.println( "<table border=1 width=\"100%\">" ); showDebugRow( "getAuthType()", req.getAuthType() ); showDebugRow( "getContextPath", req.getContextPath() ); showDebugRow( "getMethod", req.getMethod() ); showDebugRow( "getPathInfo", req.getPathInfo() ); showDebugRow( "getPathTranslated", req.getPathTranslated() ); showDebugRow( "getQueryString", req.getQueryString() ); showDebugRow( "getRemoteUser", req.getRemoteUser() ); showDebugRow( "getRequestedSessionId", req.getRequestedSessionId() ); showDebugRow( "getRequestURI", req.getRequestURI() ); // Servlet 2.3 only // showDebugRow( "getRequestURL", req.getRequestURL() ); // showDebugRow( "getRequest", req.getRequest() ); showDebugRow( "getServletPath", req.getServletPath() ); showDebugRow( "getSession(false)", req.getSession(false) ); showDebugRow( "getUserPrincipal", req.getUserPrincipal() ); showDebugRow( "isRequestedSessionIdFromCookie", "" + req.isRequestedSessionIdFromCookie() ); showDebugRow( "isRequestedSessionIdFromURL", "" + req.isRequestedSessionIdFromURL() ); showDebugRow( "isRequestedSessionIdValid", "" + req.isRequestedSessionIdValid() ); Cookie[] cookies = req.getCookies(); if (cookies!=null) for (int i = 0; i < cookies.length; i++) showDebugRow( "Cookie["+i+"]", makeVisibleCookie(cookies[i]) ); Iterator e = sortEnumeration(req.getAttributeNames()); while (e.hasNext()) { String name = (String)e.next(); Object value = req.getAttribute(name); showDebugRow( "Attribute:" + name, value ); } e = sortEnumeration(req.getParameterNames()); while (e.hasNext()) { // Note: Do not decode for display during debugging String name = (String)e.next(); Object values[] = req.getParameterValues(name); for (int i = 0; i < values.length; i++) { Object value = values[i]; showDebugRow( " &" + name + "=", value ); } } showDebugRow( "getCharacterEncoding()", req.getCharacterEncoding() ); showDebugRow( "getLocale()", req.getLocale() ); e = sortEnumeration(req.getLocales()); while (e.hasNext()) { Object name = e.next(); showDebugRow( "Locale choice", name ); } showDebugRow( "getContentLength()", "" + req.getContentLength() ); showDebugRow( "getContentType()", req.getContentType() ); showDebugRow( "getProtocol()", req.getProtocol() ); showDebugRow( "getRemoteAddr()", req.getRemoteAddr() ); showDebugRow( "getRemoteHost()", req.getRemoteHost() ); showDebugRow( "getScheme()", req.getScheme() ); showDebugRow( "getServerName()", req.getServerName() ); showDebugRow( "getServerPort()", "" + req.getServerPort() ); showDebugRow( "isSecure()", "" + req.isSecure() ); out.println( "</table>" ); } protected void showDebugHTTPRequestHeaders() { out.print("<p><a name=\"showDebugHTTPRequestHeaders\">"); out.print( "<b>HTTP Request Headers</b>" ); out.println("</a>"); Iterator e = sortEnumeration(req.getHeaderNames()); out.println( "<table border=1 width=\"100%\">" ); while (e.hasNext()) { String name = (String)e.next(); String value = req.getHeader(name); showDebugRow( name, value ); } out.println( "</table>" ); } protected void showDebugHTTPSession() { out.print( "<p><a name=\"showDebugHTTPSession\">"); out.print( "<b>Session Parameters</b>" ); out.println("</a>"); HttpSession session = req.getSession(false); if (session==null) { out.println( "<br>No session established." ); return; } out.println( "<table border=1 width=\"100%\">"); showDebugRow("getId()",session.getId()); showDebugRow("getCreationTime()",""+session.getCreationTime()); showDebugRow("getLastAccessedTime()",""+session.getLastAccessedTime()); showDebugRow("getMaxInactiveInterval()",""+session.getMaxInactiveInterval()); showDebugRow("isNew()",""+session.isNew()); Iterator e = sortEnumeration(session.getAttributeNames()); while (e.hasNext()) { String attribute = (String) e.next(); showDebugRow( attribute, session.getAttribute(attribute) ); } out.println( "</table>" ); } protected void showDebugLoggingEnvironment() { out.print( "<p><a name=\"showDebugLoggingEnvironment\">"); out.print( "<b>Logging environment</b>" ); out.println("</a>"); LogFactory factory = LogFactory.getFactory(); out.println( "<table border=1 width=\"100%\">"); showDebugRow( "factory", factory ); showDebugRow( "FACTORY_DEFAULT", LogFactory.FACTORY_DEFAULT ); showDebugRow( "FACTORY_PROPERTIES", LogFactory.FACTORY_PROPERTIES ); showDebugRow( "FACTORY_PROPERTY", LogFactory.FACTORY_PROPERTY ); String attributes[] = factory.getAttributeNames(); for (int i = 0; i < attributes.length; i++) { String attribute = attributes[i]; showDebugRow( attribute, factory.getAttribute(attribute) ); } out.println( "</table>" ); } protected void showDebugPackageInfo(Class klass) { if (klass==null) throw new IllegalArgumentException("klass is null"); Package p = klass.getPackage(); ClassLoader cl = klass.getClassLoader(); // get url for the source location of the class URL url = null; if (cl != null) url = cl.getResource(klass.getName().replace('.','/') + ".class"); out.println( "<br>Class " + klass.getName() + "<blockquote>"); if (url != null) out.println( "Loaded from: " + url + " " ); else out.println( "Loaded from unknown location. "); if (p==null) { out.println( "<br>No package info obtained via getPackage()." ); } else { out.print( "<br>Package: " + p.getName() ); out.println( " isSealed=" + p.isSealed() ); out.print( "<br>Specification: " ); out.print( p.getSpecificationTitle() + ", " ); out.print( p.getSpecificationVendor()+ ", " ); out.println( "Version " + p.getSpecificationVersion() ); out.print( "<br>Implementation: " ); out.print( p.getImplementationTitle() + ", " ); out.print( p.getImplementationVendor()+ ", " ); out.println( "Version " + p.getImplementationVersion() ); } out.println( "</blockquote>"); } protected void showDebugServletContainer() { out.print("<p><a name=\"showDebugServletContainer\">"); out.print( "<b>Servlet Container Parameters</b>" ); out.println("</a>"); showDebugPackageInfo( String.class ); // JDK version showDebugPackageInfo( req.getClass() ); // Servlet version showDebugPackageInfo( UltraseekServer.class ); // XPA version showDebugPackageInfo( org.apache.commons.logging.LogFactory.class ); // Jakarta Commons Logging showDebugPackageInfo( DebugServlet.class ); // SearchServlet location showDebugLoggingEnvironment(); } /** * Ensures that a SAX2 Parser can be found. * QuickLinksSearchable requires an XML SAX2 parser be available to parse * the XML files provided by the Ultraseek Server. * As this is a common problem when developing XPA applications with * QuickLinksSearchable, this function checks your Servlet environmental * settings to ensure one can be found. */ protected void showDebugFindSAXParser() { out.println( "<p>Looking for XML parser for Quicklinks" ); out.println( "<br>org.xml.sax.driver=" + System.getProperty("org.xml.sax.driver") ); out.println( "<br>java.class.path=" + System.getProperty("java.class.path")); try { org.xml.sax.XMLReader x = org.xml.sax.helpers.XMLReaderFactory.createXMLReader(); out.println( "<br>XML Files will be parsed with: " + x.getClass().getName() ); out.println( "<br>from Class location: " + x.getClass().getResource("") ); } catch (Exception e) { out.println( "<font color=red>" ); out.println( "<pre>"); out.println( "Unable to find XML SAX2 parser: (eg: xercesImpl.jar)\n" + e); out.println( "JDK 1.4:" ); out.println( " Ensure your parser implementation jar files\n" + " are installed in $JAVA_HOME/jre/lib/endorsed/" ); out.println( "OR Ensure they are installed in <Web Server>/common/endorsed/" ); out.println( "OR check your webserver documentation to see where\n" + " dynamically loaded classes must be installed." ); out.println( "" ); out.println( "JDK 1.*:" ); out.println( " - Ensure your parser implementation jar files\n" + " are included in your CLASSPATH." ); out.println( " - Ensure that System property org.xml.sax.driver is\n" + " set to the name of the Class to use for parsing XML." ); out.println( " (java -Dorg.xml.sax.driver=org.apache.xerces.parsers.SAXParser ...)" ); out.println( "\n" ); out.println( "Exception while trying to find SAX2 parser: " + e ); out.println( "</pre>" ); out.println( "</font>" ); } } protected void showDebugServletConfig() { ServletConfig sconfig = getServletConfig(); out.print("<p><a name=\"showDebugServletConfig\">"); out.print("<b>ServletConfig</b>" ); out.println("</a>"); out.println( "<table border=1 width=\"100%\">" ); showDebugRow( "getServletName()", sconfig.getServletName() ); showDebugRow( "getServletContext()", sconfig.getServletContext() ); Iterator e = sortEnumeration(sconfig.getInitParameterNames()); while (e.hasNext()) { String parm = (String) e.next(); String val = sconfig.getInitParameter(parm); showDebugRow( parm, val ); } out.println( "</table>" ); } protected void showDebugServletContext() { ServletConfig sconfig = getServletConfig(); ServletContext scontext = sconfig.getServletContext(); out.print("<p><a name=\"showDebugServletContext\">"); out.print("<b>ServletContext</b>" ); out.println("</a>"); out.println( "<table border=1 width=\"100%\">" ); showDebugRow( "getServerInfo()", scontext.getServerInfo() ); showDebugRow( "getMajorVersion()", "" + scontext.getMajorVersion() ); showDebugRow( "getMinorVersion()", "" + scontext.getMinorVersion() ); Iterator e = sortEnumeration(scontext.getAttributeNames()); while (e.hasNext()) { String parm = (String) e.next(); Object val = scontext.getAttribute(parm); showDebugRow( "(attribute) " + parm, val ); } e = sortEnumeration(scontext.getInitParameterNames()); while (e.hasNext()) { String parm = (String) e.next(); Object val = scontext.getInitParameter(parm); showDebugRow( "(init) " + parm, val ); } out.println( "</table>" ); } protected void showDebugHTTPResponse() { out.print("<p><a name=\"showDebugHTTPResponse\">"); out.print("<b>HTTPResponse settings</b>" ); out.println("</a>"); out.println( "<table border=1 width=\"100%\">" ); showDebugRow("getBufferSize()", ""+resp.getBufferSize() ); showDebugRow("getLocale()", resp.getLocale() ); showDebugRow("getCharacterEncoding()", resp.getCharacterEncoding() );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -