comparison src/org/eclipse/jetty/server/handler/ResourceHandler.java @ 1000:32d4b569567c

simplify handle()
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 19 Oct 2016 04:22:51 -0600
parents 7d28be82ab75
children 6939226e0ac4
comparison
equal deleted inserted replaced
999:74b9daf2826c 1000:32d4b569567c
21 import java.io.IOException; 21 import java.io.IOException;
22 import java.io.OutputStream; 22 import java.io.OutputStream;
23 import java.net.MalformedURLException; 23 import java.net.MalformedURLException;
24 24
25 import javax.servlet.ServletException; 25 import javax.servlet.ServletException;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse; 26 import javax.servlet.http.HttpServletResponse;
28 27
29 import org.eclipse.jetty.http.HttpFields; 28 import org.eclipse.jetty.http.HttpFields;
30 import org.eclipse.jetty.http.HttpHeaders; 29 import org.eclipse.jetty.http.HttpHeaders;
31 import org.eclipse.jetty.http.HttpMethods; 30 import org.eclipse.jetty.http.HttpMethods;
306 } 305 }
307 306
308 return null; 307 return null;
309 } 308 }
310 309
311 /* ------------------------------------------------------------ */ 310 @Override
312 /* 311 public void handle(String target, Request request, HttpServletResponse response) throws IOException, ServletException
313 * @see org.eclipse.jetty.server.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int) 312 {
314 */ 313 if (request.isHandled())
315 public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
316 {
317 if (baseRequest.isHandled())
318 return; 314 return;
319 315
320 boolean skipContentBody = false; 316 boolean skipContentBody = false;
321 317
322 if(!HttpMethods.GET.equals(request.getMethod())) 318 if(!HttpMethods.GET.equals(request.getMethod()))
323 { 319 {
324 if(!HttpMethods.HEAD.equals(request.getMethod())) 320 if(!HttpMethods.HEAD.equals(request.getMethod()))
325 { 321 {
326 //try another handler 322 //try another handler
327 super.handle(target, baseRequest, request, response); 323 super.handle(target, request, response);
328 return; 324 return;
329 } 325 }
330 skipContentBody = true; 326 skipContentBody = true;
331 } 327 }
332 328
333 Resource resource = getResource(baseRequest); 329 Resource resource = getResource(request);
334 330
335 if (resource==null || !resource.exists()) 331 if (resource==null || !resource.exists())
336 { 332 {
337 if (target.endsWith("/jetty-dir.css")) 333 if (target.endsWith("/jetty-dir.css"))
338 { 334 {
342 response.setContentType("text/css"); 338 response.setContentType("text/css");
343 } 339 }
344 else 340 else
345 { 341 {
346 //no resource - try other handlers 342 //no resource - try other handlers
347 super.handle(target, baseRequest, request, response); 343 super.handle(target, request, response);
348 return; 344 return;
349 } 345 }
350 } 346 }
351 347
352 if (!_aliases && resource.getAlias()!=null) 348 if (!_aliases && resource.getAlias()!=null)
354 LOG.info(resource+" aliased to "+resource.getAlias()); 350 LOG.info(resource+" aliased to "+resource.getAlias());
355 return; 351 return;
356 } 352 }
357 353
358 // We are going to serve something 354 // We are going to serve something
359 baseRequest.setHandled(true); 355 request.setHandled(true);
360 356
361 if (resource.isDirectory()) 357 if (resource.isDirectory())
362 { 358 {
363 if (!request.getPathInfo().endsWith(URIUtil.SLASH)) 359 if (!request.getPathInfo().endsWith(URIUtil.SLASH))
364 { 360 {
370 if (welcome!=null && welcome.exists()) 366 if (welcome!=null && welcome.exists())
371 resource=welcome; 367 resource=welcome;
372 else 368 else
373 { 369 {
374 doDirectory(request,response,resource); 370 doDirectory(request,response,resource);
375 baseRequest.setHandled(true); 371 request.setHandled(true);
376 return; 372 return;
377 } 373 }
378 } 374 }
379 375
380 // set some headers 376 // set some headers
416 resource.writeTo(out,0,resource.length()); 412 resource.writeTo(out,0,resource.length());
417 } 413 }
418 } 414 }
419 415
420 /* ------------------------------------------------------------ */ 416 /* ------------------------------------------------------------ */
421 protected void doDirectory(HttpServletRequest request,HttpServletResponse response, Resource resource) 417 protected void doDirectory(Request request,HttpServletResponse response, Resource resource)
422 throws IOException 418 throws IOException
423 { 419 {
424 if (_directory) 420 if (_directory)
425 { 421 {
426 String listing = resource.getListHTML(request.getRequestURI(),request.getPathInfo().lastIndexOf("/") > 0); 422 String listing = resource.getListHTML(request.getRequestURI(),request.getPathInfo().lastIndexOf("/") > 0);