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 ErrorPage06 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 StringBuffer sb = new StringBuffer (); 44 Object value = null; 45 46 value = request.getAttribute("javax.servlet.error.exception"); 47 StaticLogger.write("exception is '" + value + "'"); 48 if (value == null) { 49 sb.append(" exception is missing/"); 50 } else if (!(value instanceof java.lang.ArithmeticException )) { 51 sb.append(" exception class is "); 52 sb.append(value.getClass().getName()); 53 sb.append("/"); 54 } 55 56 value = request.getAttribute("javax.servlet.error.exception_type"); 57 StaticLogger.write("exception_type is '" + value + "'"); 58 if (value != null) 59 StaticLogger.write("exception_type class is '" + 60 value.getClass().getName() + "'"); 61 if (value == null) 62 sb.append(" exception_type is missing/"); 63 else if (!(value instanceof Class )) { 64 sb.append(" exception_type class is "); 65 sb.append(value.getClass().getName()); 66 sb.append("/"); 67 } else { 68 Class clazz = (Class ) value; 69 String name = clazz.getName(); 70 if (!"java.lang.ArithmeticException".equals(name)) { 71 sb.append(" exception_type is "); 72 sb.append(name); 73 sb.append("/"); 74 } 75 } 76 77 value = request.getAttribute("javax.servlet.error.message"); 78 StaticLogger.write("message is '" + value + "'"); 79 if (value == null) 80 sb.append(" message is missing/"); 81 else if (!(value instanceof String )) { 82 sb.append(" message class is "); 83 sb.append(value.getClass().getName()); 84 sb.append("/"); 85 } else if (!"ErrorPage05 Threw ArithmeticException".equals(value) && 86 !"ErrorPage08 Threw ArithmeticException".equals(value)) { 87 sb.append(" message is not correct"); 88 } 89 90 value = request.getAttribute("javax.servlet.error.request_uri"); 91 StaticLogger.write("request_uri is '" + value + "'"); 92 if (value == null) 93 sb.append(" request_uri is missing/"); 94 else if (!(value instanceof String )) { 95 sb.append(" request_uri class is "); 96 sb.append(value.getClass().getName()); 97 sb.append("/"); 98 } else { 99 String request_uri = (String ) value; 100 String test1 = request.getContextPath() + "/ErrorPage05"; 101 String test2 = request.getContextPath() + "/WrappedErrorPage05"; 102 String test3 = request.getContextPath() + "/ErrorPage08"; 103 String test4 = request.getContextPath() + "/WrappedErrorPage08"; 104 if (!request_uri.equals(test1) && !request_uri.equals(test2) && 105 !request_uri.equals(test3) && !request_uri.equals(test4)) { 106 sb.append(" request_uri is "); 107 sb.append(request_uri); 108 sb.append("/"); 109 } 110 } 111 112 value = request.getAttribute("javax.servlet.error.servlet_name"); 113 StaticLogger.write("servlet_name is '" + value + "'"); 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 (!"ErrorPage05".equals(servlet_name) && 123 !"ErrorPage08".equals(servlet_name)) { 124 sb.append(" servlet_name is "); 125 sb.append(servlet_name); 126 sb.append("/"); 127 } 128 } 129 130 if (sb.length() < 1) 132 writer.println("ErrorPage06 PASSED - SERVLET"); 133 else 134 writer.println("ErrorPage06 FAILED -" + sb.toString()); 135 136 while (true) { 137 String message = StaticLogger.read(); 138 if (message == null) 139 break; 140 writer.println(message); 141 } 142 StaticLogger.reset(); 143 144 } 145 146 147 } 148 | Popular Tags |