1 16 17 package org.apache.tester; 18 19 20 import java.io.*; 21 import javax.servlet.*; 22 import javax.servlet.http.*; 23 24 25 33 34 public class Request01 extends HttpServlet { 35 36 public void doGet(HttpServletRequest request, HttpServletResponse response) 37 throws IOException, ServletException { 38 39 response.setContentType("text/plain"); 40 boolean ok = true; 41 PrintWriter writer = response.getWriter(); 42 ServletContext context = getServletContext(); 43 44 if (ok) { 46 if (request.getAttribute("request01") != null) { 47 writer.println("Request01 FAILED - Attribute already exists"); 48 ok = false; 49 } 50 } 51 52 if (ok) { 54 ContextBean bean = new ContextBean(); 55 bean.setStringProperty("Request01"); 56 request.setAttribute("request01", bean); 57 } 58 59 if (ok) { 61 Object bean = request.getAttribute("request01"); 62 if (bean == null) { 63 writer.println("Request01 FAILED - Cannot retrieve attribute"); 64 ok = false; 65 } 66 if (ok) { 67 if (!(bean instanceof ContextBean)) { 68 writer.println("Request01 FAILED - Bean instance of " + 69 bean.getClass().getName()); 70 ok = false; 71 } 72 } 73 if (ok) { 74 String value = ((ContextBean) bean).getStringProperty(); 75 if (!"Request01".equals(value)) { 76 writer.println("Request01 FAILED - Value = " + value); 77 ok = false; 78 } 79 } 80 if (ok) { 81 String lifecycle = ((ContextBean) bean).getLifecycle(); 82 if (!"/add".equals(lifecycle)) { 83 writer.println("Request01 FAILED - Bean lifecycle is " + 84 lifecycle); 85 ok = false; 86 } 87 } 88 } 89 90 if (ok) { 92 ContextBean bean = (ContextBean) request.getAttribute("request01"); 93 request.setAttribute("request01", bean); 94 String lifecycle = bean.getLifecycle(); 95 if (!"/add/rep".equals(lifecycle)) { 96 writer.println("Request01 FAILED - Bean lifecycle is " + 97 lifecycle); 98 ok = false; 99 } 100 } 101 102 if (ok) { 104 ContextBean bean = (ContextBean) request.getAttribute("request01"); 105 request.removeAttribute("request01"); 106 String lifecycle = bean.getLifecycle(); 107 if (!"/add/rep/rem".equals(lifecycle)) { 108 writer.println("Request01 FAILED - Bean lifecycle is " + 109 lifecycle); 110 ok = false; 111 } 112 } 113 114 request.setAttribute("request01", new ContextBean()); 116 117 if (ok) { 119 request.setAttribute("FOO", "BAR"); 120 request.setAttribute("FOO", null); 121 if (request.getAttribute("FOO") != null) { 122 writer.println("Request01 FAILED - setAttribute(name,null)"); 123 ok = false; 124 } 125 } 126 127 if (ok) 129 writer.println("Request01 PASSED"); 130 while (true) { 131 String message = StaticLogger.read(); 132 if (message == null) 133 break; 134 writer.println(message); 135 } 136 StaticLogger.reset(); 137 138 } 139 140 } 141 | Popular Tags |