1 16 package org.mortbay.http.handler; 17 18 import java.io.IOException ; 19 20 import org.apache.commons.logging.Log; 21 import org.mortbay.log.LogFactory; 22 import org.mortbay.http.HttpException; 23 import org.mortbay.http.HttpFields; 24 import org.mortbay.http.HttpRequest; 25 import org.mortbay.http.HttpResponse; 26 27 28 34 public class NotFoundHandler extends AbstractHttpHandler 35 { 36 private static Log log = LogFactory.getLog(NotFoundHandler.class); 37 38 39 public void handle(String pathInContext, 40 String pathParams, 41 HttpRequest request, 42 HttpResponse response) 43 throws HttpException, IOException 44 { 45 log.debug("Not Found"); 46 String method=request.getMethod(); 47 48 if (method.equals(HttpRequest.__GET) || 50 method.equals(HttpRequest.__HEAD) || 51 method.equals(HttpRequest.__POST) || 52 method.equals(HttpRequest.__PUT) || 53 method.equals(HttpRequest.__DELETE) || 54 method.equals(HttpRequest.__MOVE) ) 55 { 56 response.sendError(HttpResponse.__404_Not_Found, 57 request.getPath()+" Not Found"); 58 } 59 60 else if (method.equals(HttpRequest.__OPTIONS)) 61 { 62 if ("*".equals(request.getPath())) 64 { 65 response.setIntField(HttpFields.__ContentLength,0); 67 response.setField(HttpFields.__Allow, 68 "GET, HEAD, POST, PUT, DELETE, MOVE, OPTIONS, TRACE"); 69 response.commit(); 70 } 71 else 72 response.sendError(HttpResponse.__404_Not_Found); 73 } 74 else if (method.equals(HttpRequest.__TRACE)) 75 { 76 handleTrace(request,response); 77 } 78 else 79 { 80 response.setField(HttpFields.__Allow, 82 "GET, HEAD, POST, PUT, DELETE, MOVE, OPTIONS, TRACE"); 83 response.sendError(HttpResponse.__405_Method_Not_Allowed); 84 } 85 } 86 } 87 | Popular Tags |