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.unpshared.UnpSharedSessionBean; 25 import org.apache.tester.unshared.UnsharedSessionBean; 26 27 28 36 37 public class Session03 extends HttpServlet { 38 39 public void doGet(HttpServletRequest request, HttpServletResponse response) 40 throws IOException, ServletException { 41 42 response.setContentType("text/plain"); 43 PrintWriter writer = response.getWriter(); 44 45 boolean ok = true; 47 HttpSession session = request.getSession(false); 48 if (session == null) { 49 writer.println("Session03 FAILED - No existing session " + 50 request.getRequestedSessionId()); 51 ok = false; 52 } 53 54 SessionBean bean = null; 56 if (ok) { 57 Object object = session.getAttribute("sessionBean"); 58 if (object == null) { 59 writer.println("Session03 FAILED - Cannot retrieve attribute"); 60 ok = false; 61 } else if (!(object instanceof SessionBean)) { 62 writer.println("Session03 FAILED - Attribute instance of " + 63 object.getClass().getName()); 64 ok = false; 65 } else { 66 bean = (SessionBean) object; 67 String value = bean.getStringProperty(); 68 if (!"Session01".equals(value)) { 69 writer.println("Session03 FAILED - Property = " + value); 70 ok = false; 71 } 72 } 73 } 74 75 if (ok) { 77 session.removeAttribute("sessionBean"); 78 if (session.getAttribute("sessionBean") != null) { 79 writer.println("Session03 FAILED - Removal failed"); 80 ok = false; 81 } 82 } 83 84 if (ok) { 86 String lifecycle = bean.getLifecycle(); 87 if (!"/vb/swp/sda/vu".equals(lifecycle)) { 88 writer.println("Session03 FAILED - Invalid bean lifecycle '" + 89 lifecycle + "'"); 90 ok = false; 91 } 92 } 93 94 SharedSessionBean ssb = null; 96 if (ok) { 97 Object object = session.getAttribute("sharedSessionBean"); 98 if (object == null) { 99 writer.println("Session03 FAILED - Cannot retrieve ssb"); 100 ok = false; 101 } else if (!(object instanceof SharedSessionBean)) { 102 writer.println("Session03 FAILED - Shared attribute class " 103 + object.getClass().getName()); 104 ok = false; 105 } else { 106 ssb = (SharedSessionBean) object; 107 String value = ssb.getStringProperty(); 108 if (!"Session01".equals(value)) { 109 writer.println("Session03 FAILED - Shared property =" 110 + value); 111 ok = false; 112 } else { 113 session.removeAttribute("sharedSessionBean"); 114 String lifecycle = ssb.getLifecycle(); 115 if (!"/vb/swp/sda/vu".equals(lifecycle)) { 116 writer.println("Session03 FAILED - Shared lifecycle =" 117 + lifecycle); 118 ok = false; 119 } 120 } 121 } 122 } 123 124 UnpSharedSessionBean ussb = null; 126 if (ok) { 127 Object object = session.getAttribute("unpSharedSessionBean"); 128 if (object == null) { 129 writer.println("Session03 FAILED - Cannot retrieve ussb"); 130 ok = false; 131 } else if (!(object instanceof UnpSharedSessionBean)) { 132 writer.println("Session03 FAILED - unpShared attribute class " 133 + object.getClass().getName()); 134 ok = false; 135 } else { 136 ussb = (UnpSharedSessionBean) object; 137 String value = ussb.getStringProperty(); 138 if (!"Session01".equals(value)) { 139 writer.println("Session03 FAILED - unpShared property =" 140 + value); 141 ok = false; 142 } else { 143 session.removeAttribute("unpSharedSessionBean"); 144 String lifecycle = ssb.getLifecycle(); 145 if (!"/vb/swp/sda/vu".equals(lifecycle)) { 146 writer.println("Session03 FAILED - unpShared lifecycle =" 147 + lifecycle); 148 ok = false; 149 } 150 } 151 } 152 } 153 154 UnsharedSessionBean usb = null; 156 if (ok) { 157 Object object = session.getAttribute("unsharedSessionBean"); 158 if (object == null) { 159 writer.println("Session03 FAILED - Cannot retrieve usb"); 160 ok = false; 161 } else if (!(object instanceof UnsharedSessionBean)) { 162 writer.println("Session03 FAILED - Unshared attribute class " 163 + object.getClass().getName()); 164 ok = false; 165 } else { 166 usb = (UnsharedSessionBean) object; 167 String value = usb.getStringProperty(); 168 if (!"Session01".equals(value)) { 169 writer.println("Session03 FAILED - Unshared property = " 170 + value); 171 ok = false; 172 } else { 173 session.removeAttribute("unsharedSessionBean"); 174 String lifecycle = usb.getLifecycle(); 175 if (!"/vb/swp/sda/vu".equals(lifecycle)) { 176 writer.println("Session03 FAILED - Unshared lifecycle" 177 + " = " + lifecycle); 178 ok = false; 179 } 180 } 181 } 182 } 183 184 185 if (ok) 187 writer.println("Session03 PASSED"); 188 while (true) { 189 String message = StaticLogger.read(); 190 if (message == null) 191 break; 192 writer.println(message); 193 } 194 StaticLogger.reset(); 195 196 } 197 198 } 199 | Popular Tags |