1 16 17 package org.apache.tester; 18 19 20 import java.io.*; 21 import javax.servlet.*; 22 import javax.servlet.http.*; 23 24 31 32 public class ErrorPage04 extends HttpServlet { 33 34 35 public void doGet(HttpServletRequest request, HttpServletResponse response) 36 throws IOException, ServletException { 37 38 response.reset(); 39 response.setContentType("text/plain"); 40 PrintWriter writer = response.getWriter(); 41 42 ServletException exception = null; 44 StringBuffer sb = new StringBuffer (); 45 Object value = null; 46 47 value = request.getAttribute("javax.servlet.error.exception"); 48 if (value == null) 49 sb.append(" exception is missing/"); 50 else if (!(value instanceof org.apache.tester.TesterException)) { 51 sb.append(" exception class is "); 52 sb.append(value.getClass().getName()); 53 sb.append("/"); 54 } else { 55 TesterException te = (TesterException) value; 56 if (!"ErrorPage03 Threw Exception".equals(te.getMessage())) { 57 sb.append(" exception message is "); 58 sb.append(te.getMessage()); 59 sb.append("/"); 60 } 61 } 62 63 value = request.getAttribute("javax.servlet.error.exception_type"); 64 if (value == null) 65 sb.append(" exception_type is missing/"); 66 else if (!(value instanceof Class )) { 67 sb.append(" exception_type class is "); 68 sb.append(value.getClass().getName()); 69 sb.append("/"); 70 } else { 71 Class clazz = (Class ) value; 72 if (!"org.apache.tester.TesterException".equals(clazz.getName())) { 73 sb.append(" exception_type class is "); 74 sb.append(clazz.getName()); 75 sb.append("/"); 76 } 77 } 78 79 value = request.getAttribute("javax.servlet.error.message"); 80 if (value == null) 81 sb.append(" message is missing/"); 82 else if (!(value instanceof String )) { 83 sb.append(" message class is "); 84 sb.append(value.getClass().getName()); 85 sb.append("/"); 86 } else { 87 String message = (String ) value; 88 if (!"ErrorPage03 Threw Exception".equals(message)) { 89 sb.append(" message is "); 90 sb.append(message); 91 sb.append("/"); 92 } 93 } 94 95 value = request.getAttribute("javax.servlet.error.request_uri"); 96 if (value == null) 97 sb.append(" request_uri is missing/"); 98 else if (!(value instanceof String )) { 99 sb.append(" request_uri class is "); 100 sb.append(value.getClass().getName()); 101 sb.append("/"); 102 } else { 103 String request_uri = (String ) value; 104 String test1 = request.getContextPath() + "/ErrorPage03"; 105 String test2 = request.getContextPath() + "/WrappedErrorPage03"; 106 if (!request_uri.equals(test1) && !request_uri.equals(test2)) { 107 sb.append(" request_uri is "); 108 sb.append(request_uri); 109 sb.append("/"); 110 } 111 } 112 113 value = request.getAttribute("javax.servlet.error.servlet_name"); 114 if (value == null) 115 sb.append(" servlet_name is missing/"); 116 else if (!(value instanceof String )) { 117 sb.append(" servlet_name class is "); 118 sb.append(value.getClass().getName()); 119 sb.append("/"); 120 } else { 121 String servlet_name = (String ) value; 122 if (!"ErrorPage03".equals(servlet_name)) { 123 sb.append(" servlet_name is "); 124 sb.append(servlet_name); 125 sb.append("/"); 126 } 127 } 128 129 if (sb.length() < 1) 131 writer.println("ErrorPage04 PASSED"); 132 else 133 writer.println("ErrorPage04 FAILED -" + sb.toString()); 134 135 while (true) { 136 String message = StaticLogger.read(); 137 if (message == null) 138 break; 139 writer.println(message); 140 } 141 StaticLogger.reset(); 142 143 } 144 145 146 } 147 | Popular Tags |