1 16 17 package org.apache.tester; 18 19 20 import java.io.*; 21 import java.net.MalformedURLException ; 22 import java.net.URL ; 23 import java.util.*; 24 import javax.servlet.*; 25 import javax.servlet.http.*; 26 27 28 37 38 public class Resources06 extends HttpServlet { 39 40 String rootPaths[] = 42 { "/ErrorPage06.html", "/ErrorPage06.jsp", "/Forward01.txt", 43 "/Include01.txt", "/WEB-INF/", "/Xerces00.jsp", "/Xerces01.xml", 44 "/Xerces02.jsp", "/golden/", "/includeme.txt", "/index.shtml", 45 "/ssidir/" }; 46 47 String goldenPaths[] = 48 { "/golden/Golden01.txt", "/golden/SSIConfig01.txt", 49 "/golden/SSIConfig03.txt", "/golden/SSIFsize02.txt", 50 "/golden/SSIInclude01.txt", "/golden/SSIInclude02.txt", 51 "/golden/Session05.txt" }; 52 53 String webinfPaths[] = 54 { "/WEB-INF/classes/", "/WEB-INF/lib/", "/WEB-INF/web.xml" }; 55 56 57 public void doGet(HttpServletRequest request, HttpServletResponse response) 58 throws IOException, ServletException { 59 60 response.setContentType("text/plain"); 62 PrintWriter writer = response.getWriter(); 63 64 StringBuffer sb = new StringBuffer (); 66 String path = request.getParameter("path"); 67 if (path == null) 68 path = "/"; 69 String paths[] = null; 70 if ("/".equals(path)) 71 paths = rootPaths; 72 else if ("/golden".equals(path)) 73 paths = goldenPaths; 74 else if ("/WEB-INF".equals(path)) 75 paths = webinfPaths; 76 else { 77 sb.append(" Unknown path '"); 78 sb.append(path); 79 sb.append("'/"); 80 } 81 int counts[] = null; 82 if (paths != null) 83 counts = new int[paths.length]; 84 85 StaticLogger.write("Processing path '" + path + "'"); 87 String first = null; 88 Set set = getServletContext().getResourcePaths(path); 89 if (set == null) { 90 sb.append(" No resources returned/"); 91 set = new HashSet(); 92 } 93 94 Iterator resources = set.iterator(); 96 while (resources.hasNext()) { 97 String resource = (String ) resources.next(); 98 if (first == null) 99 first = resource; 100 StaticLogger.write("Found resource '" + resource + "'"); 101 for (int i = 0; i < paths.length; i++) { 102 if (paths[i].equals(resource)) { 103 counts[i]++; 104 break; 105 } 106 } 107 } 108 109 for (int i = 0; i < paths.length; i++) { 111 if (counts[i] < 1) { 112 sb.append(" Missing resource '"); 113 sb.append(paths[i]); 114 sb.append("'/"); 115 } else if (counts[i] > 2) { 116 sb.append(" Resource '"); 117 sb.append(paths[i]); 118 sb.append("' occurred "); 119 sb.append(counts[i]); 120 sb.append(" times/"); 121 } 122 } 123 124 try { 126 String newElement = "NEW FOO"; 127 set.add(newElement); 128 if (set.contains(newElement)) 129 sb.append(" Set allowed add()/"); 130 } catch (Throwable t) { 131 ; 132 } 133 try { 134 if (first != null) { 135 set.remove(first); 136 if (!set.contains(first)) 137 sb.append(" Set allowed remove()/"); 138 } 139 } catch (Throwable t) { 140 ; 141 } 142 try { 143 set.clear(); 144 if (set.size() == 0) 145 sb.append(" Set allowed clear()/"); 146 } catch (Throwable t) { 147 ; 148 } 149 150 151 if (sb.length() > 0) { 153 writer.print("Resources06 FAILED -"); 154 writer.println(sb.toString()); 155 } else { 156 writer.println("Resources06 PASSED"); 157 } 158 159 while (true) { 161 String message = StaticLogger.read(); 162 if (message == null) 163 break; 164 writer.println(message); 165 } 166 StaticLogger.reset(); 167 168 } 169 170 } 171 | Popular Tags |