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 ErrorPage02 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.status_code"); 47 if (value == null) 48 sb.append(" status_code is missing/"); 49 else if (!(value instanceof Integer )) { 50 sb.append(" status_code class is "); 51 sb.append(value.getClass().getName()); 52 sb.append("/"); 53 } else { 54 int intValue = ((Integer ) value).intValue(); 55 if (intValue != HttpServletResponse.SC_PRECONDITION_FAILED) { 56 sb.append(" status_code is "); 57 sb.append(value); 58 sb.append("/"); 59 } 60 } 61 62 value = request.getAttribute("javax.servlet.error.message"); 63 if (value == null) 64 sb.append(" message is missing/"); 65 else if (!(value instanceof String )) { 66 sb.append(" message class is "); 67 sb.append(value.getClass().getName()); 68 sb.append("/"); 69 } else { 70 String message = (String ) value; 71 if (!"ErrorPage01 Returned Status Code 412".equals(message)) { 72 sb.append(" message is "); 73 sb.append(message); 74 sb.append("/"); 75 } 76 } 77 78 value = request.getAttribute("javax.servlet.error.request_uri"); 79 if (value == null) 80 sb.append(" request_uri is missing/"); 81 else if (!(value instanceof String )) { 82 sb.append(" request_uri class is "); 83 sb.append(value.getClass().getName()); 84 sb.append("/"); 85 } else { 86 String request_uri = (String ) value; 87 String test1 = request.getContextPath() + "/ErrorPage01"; 88 String test2 = request.getContextPath() + "/WrappedErrorPage01"; 89 if (!request_uri.equals(test1) && !request_uri.equals(test2)) { 90 sb.append(" request_uri is "); 91 sb.append(request_uri); 92 sb.append("/"); 93 } 94 } 95 96 value = request.getAttribute("javax.servlet.error.servlet_name"); 97 if (value == null) 98 sb.append(" servlet_name is missing/"); 99 else if (!(value instanceof String )) { 100 sb.append(" servlet_name class is "); 101 sb.append(value.getClass().getName()); 102 sb.append("/"); 103 } else { 104 String servlet_name = (String ) value; 105 if (!"ErrorPage01".equals(servlet_name)) { 106 sb.append(" servlet_name is "); 107 sb.append(servlet_name); 108 sb.append("/"); 109 } 110 } 111 112 if (sb.length() < 1) 114 writer.println("ErrorPage02 PASSED"); 115 else 116 writer.println("ErrorPage02 FAILED -" + sb.toString()); 117 118 while (true) { 119 String message = StaticLogger.read(); 120 if (message == null) 121 break; 122 writer.println(message); 123 } 124 StaticLogger.reset(); 125 126 } 127 128 129 } 130 | Popular Tags |