1 16 17 package org.apache.tester; 18 19 20 import java.io.*; 21 import javax.servlet.*; 22 import javax.servlet.http.*; 23 import org.apache.tester.shared.SharedSessionBean; 24 import org.apache.tester.unshared.UnsharedSessionBean; 25 26 27 38 39 public class Context02 extends HttpServlet { 40 41 public void doGet(HttpServletRequest request, HttpServletResponse response) 42 throws IOException, ServletException { 43 44 response.setContentType("text/plain"); 45 boolean ok = true; 46 PrintWriter writer = response.getWriter(); 47 ServletContext context = getServletContext(); 48 49 if (ok) { 51 Object bean = context.getAttribute("context01"); 52 if (bean != null) { 53 writer.println("Context02 FAILED - context01 value " + 54 bean); 55 ok = false; 56 context.removeAttribute("context01"); 57 } 58 } 59 60 if (ok) { 62 Object bean = context.getAttribute("context00"); 63 if (bean == null) { 64 writer.println("Context02 FAILED - context00 missing"); 65 ok = false; 66 } else if (!(bean instanceof ContextBean)) { 67 writer.println("Context02 FAILED - context00 class " + 68 bean.getClass().getName()); 69 ok = false; 70 } else { 71 String value = ((ContextBean) bean).getStringProperty(); 72 if (!"Context00".equals(value)) { 73 writer.println("Context02 FAILED - context00 value " + 74 value); 75 ok = false; 76 } else { 77 String lifecycle = ((ContextBean) bean).getLifecycle(); 78 if (!"/add".equals(lifecycle)) { 79 writer.println("Context02 FAILED -" + 80 " context00 lifecycle " + 81 lifecycle); 82 ok = false; 83 } 84 } 85 } 86 } 87 88 if (ok) { 90 Object bean = context.getAttribute("contextListener01"); 91 if (bean == null) { 92 writer.println("Context02 FAILED - contextListener01 missing"); 93 ok = false; 94 } else if (!(bean instanceof ContextBean)) { 95 writer.println("Context02 FAILED - contextListener01 class " + 96 bean.getClass().getName()); 97 ok = false; 98 } else { 99 String value = ((ContextBean) bean).getStringProperty(); 100 if (!"ContextListener01".equals(value)) { 101 writer.println("Context02 FAILED - contextListener01 " + 102 "value " + value); 103 ok = false; 104 } else { 105 String lifecycle = ((ContextBean) bean).getLifecycle(); 106 if (!"/add".equals(lifecycle)) { 107 writer.println("Context02 FAILED -" + 108 " contextListener01 lifecycle " + 109 lifecycle); 110 ok = false; 111 } 112 } 113 } 114 } 115 116 if (ok) 118 writer.println("Context02 PASSED"); 119 while (true) { 120 String message = StaticLogger.read(); 121 if (message == null) 122 break; 123 writer.println(message); 124 } 125 StaticLogger.reset(); 126 127 } 128 129 } 130 | Popular Tags |