1 18 19 package org.apache.jmeter.protocol.http.proxy; 20 21 26 public final class HttpReplyHdr 27 { 28 29 private static final String CR = "\r\n"; 30 31 32 private static final String HTTP_PROTOCOL = "HTTP/1.0"; 33 34 35 private static final String HTTP_SERVER = "Java Proxy Server"; 36 37 38 41 private HttpReplyHdr() 42 { 43 } 44 45 52 public static String formOk(String contentType, long contentLength) 53 { 54 StringBuffer out = new StringBuffer (); 55 56 out.append(HTTP_PROTOCOL).append(" 200 Ok").append(CR); 57 out.append("Server: ").append(HTTP_SERVER).append(CR); 58 out.append("MIME-version: 1.0").append(CR); 59 60 if (0 < contentType.length()) 61 { 62 out.append("Content-Type: ").append(contentType).append(CR); 63 } 64 else 65 { 66 out.append("Content-Type: text/html").append(CR); 67 } 68 69 if (0 != contentLength) 70 { 71 out.append("Content-Length: ").append(contentLength).append(CR); 72 } 73 74 out.append(CR); 75 76 return out.toString(); 77 } 78 79 86 private static String formErrorBody(String error, String description) 87 { 88 StringBuffer out = new StringBuffer (); 89 out.append("<HTML><HEAD><TITLE>"); 91 out.append(error); 92 out.append("</TITLE></HEAD>"); 93 out.append("<BODY><H2>").append(error).append("</H2>\n"); 94 out.append("</P></H3>"); 95 out.append(description); 96 out.append("</BODY></HTML>"); 97 return out.toString(); 98 } 99 100 107 private static String formError(String error, String description) 108 { 109 120 121 String body = formErrorBody(error, description); 122 StringBuffer header = new StringBuffer (); 123 124 header.append(HTTP_PROTOCOL).append(" ").append(error).append(CR); 125 header.append("Server: ").append(HTTP_SERVER).append(CR); 126 header.append("MIME-version: 1.0").append(CR); 127 header.append("Content-Type: text/html").append(CR); 128 129 header.append("Content-Length: ").append(body.length()).append(CR); 130 131 header.append(CR); 132 header.append(body); 133 134 return header.toString(); 135 } 136 137 142 public static String formCreated() 143 { 144 return formError("201 Created", "Object was created"); 145 } 146 147 152 public static String formAccepted() 153 { 154 return formError("202 Accepted", "Object checked in"); 155 } 156 157 162 public static String formPartial() 163 { 164 return formError("203 Partial", "Only partail document available"); 165 } 166 167 172 public static String formMoved() 173 { 174 return formError("301 Moved", "File has moved"); 176 } 177 178 183 public static String formFound() 184 { 185 return formError("302 Found", "Object was found"); 186 } 187 188 193 public static String formMethod() 194 { 195 return formError("303 Method unseported", "Method unseported"); 196 } 197 198 203 public static String formNotModified() 204 { 205 return formError("304 Not modified", "Use local copy"); 206 } 207 208 213 public static String formUnautorized() 214 { 215 return formError("401 Unathorized", "Unathorized use of this service"); 216 } 217 218 223 public static String formPaymentNeeded() 224 { 225 return formError("402 Payment required", "Payment is required"); 226 } 227 228 233 public static String formForbidden() 234 { 235 return formError( 236 "403 Forbidden", 237 "You need permission for this service"); 238 } 239 240 245 public static String formNotFound() 246 { 247 return formError("404 Not_found", "Requested object was not found"); 248 } 249 250 255 public static String formInternalError() 256 { 257 return formError("500 Internal server error", "Server broke"); 258 } 259 260 265 public static String formNotImplemented() 266 { 267 return formError( 268 "501 Method not implemented", 269 "Service not implemented, programer was lazy"); 270 } 271 272 277 public static String formOverloaded() 278 { 279 return formError("502 Server overloaded", "Try again latter"); 280 } 281 282 287 public static String formTimeout() 288 { 289 return formError("503 Gateway timeout", "The connection timed out"); 290 } 291 292 297 public static String formServerNotFound() 298 { 299 return formError( 300 "503 Gateway timeout", 301 "The requested server was not found"); 302 } 303 304 309 public static String formNotAllowed() 310 { 311 return formError("403 Access Denied", "Access is not allowed"); 312 } 313 } 314 | Popular Tags |