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 35 36 public class Lifecycle02 extends HttpServlet { 37 38 private boolean doubled = false; 39 40 private boolean initialized = false; 41 42 public void init() throws ServletException { 43 if (initialized) 44 doubled = true; 45 else 46 initialized = true; 47 } 48 49 public void destroy() { 50 initialized = false; 51 } 52 53 public void doGet(HttpServletRequest request, HttpServletResponse response) 54 throws IOException, ServletException { 55 56 response.setContentType("text/plain"); 57 PrintWriter writer = response.getWriter(); 58 if (doubled) { 59 writer.println("Lifecycle02 FAILED - GET and double initialization"); 60 } else if (initialized) { 61 writer.println("Lifecycle02 FAILED - GET called"); 62 } else { 63 writer.println("Lifecycle02 FAILED - GET and not initialized"); 64 } 65 66 while (true) { 67 String message = StaticLogger.read(); 68 if (message == null) 69 break; 70 writer.println(message); 71 } 72 StaticLogger.reset(); 73 74 } 75 76 public void doPost(HttpServletRequest request, HttpServletResponse response) 77 throws IOException, ServletException { 78 79 response.setContentType("text/plain"); 80 PrintWriter writer = response.getWriter(); 81 if (doubled) { 82 writer.println("Lifecycle02 FAILED - Double initialization"); 83 } else if (initialized) { 84 writer.println("Lifecycle02 PASSED"); 85 } else { 86 writer.println("Lifecycle02 FAILED - POST but not initialized"); 87 } 88 89 while (true) { 90 String message = StaticLogger.read(); 91 if (message == null) 92 break; 93 writer.println(message); 94 } 95 StaticLogger.reset(); 96 97 } 98 99 100 } 101 | Popular Tags |