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 javax.servlet.*; 24 import javax.servlet.http.*; 25 26 27 41 42 public class Resources04 extends HttpServlet { 43 44 public void doGet(HttpServletRequest request, HttpServletResponse response) 45 throws IOException, ServletException { 46 47 String mode = request.getParameter("mode"); 49 if (mode == null) 50 mode = "context"; 51 String path = request.getParameter("path"); 52 if (path == null) 53 path = "/WEB-INF/web.xml"; 54 55 response.setContentType("text/plain"); 57 PrintWriter writer = response.getWriter(); 58 InputStream is = null; 59 URL url = null; 60 try { 61 if ("context".equals(mode)) { 62 is = getServletContext().getResourceAsStream(path); 63 url = getServletContext().getResource(path); 64 } else { 65 is = this.getClass().getResourceAsStream(path); 66 url = this.getClass().getResource(path); 67 } 68 if (is == null) { 69 if (url == null) 70 writer.println("Resources04 PASSED"); 71 else 72 writer.println("Resources04 FAILED - Stream is null but URL is " + url); 73 } else { 74 if (url != null) 75 writer.println("Resources04 FAILED - Stream is not null and URL is " + url); 76 else 77 writer.println("Resources04 FAILED - Stream is not null and URL is null"); 78 } 79 } catch (MalformedURLException e) { 80 writer.println("Resources04 FAILED - MalformedURLException: " 81 + e); 82 } 83 84 while (true) { 86 String message = StaticLogger.read(); 87 if (message == null) 88 break; 89 writer.println(message); 90 } 91 StaticLogger.reset(); 92 93 } 94 95 } 96 | Popular Tags |