comparison src/org/eclipse/jetty/server/AbstractHttpConnection.java @ 939:8db5996c8c89

remove AsyncContinuation
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 10 Oct 2016 00:50:06 -0600
parents fe461f7cfc8e
children 1094975d013b
comparison
equal deleted inserted replaced
938:a088981f9cd4 939:8db5996c8c89
388 _uri.clear(); 388 _uri.clear();
389 _writer=null; 389 _writer=null;
390 _earlyEOF = false; 390 _earlyEOF = false;
391 } 391 }
392 392
393 /* ------------------------------------------------------------ */
394 protected void handleRequest() throws IOException 393 protected void handleRequest() throws IOException
395 { 394 {
396 boolean error = false; 395 boolean error = false;
397 396
398 String threadName=null;
399 Throwable async_exception=null;
400 try 397 try
401 { 398 {
402 if (LOG.isDebugEnabled())
403 {
404 threadName=Thread.currentThread().getName();
405 Thread.currentThread().setName(threadName+" - "+_uri);
406 }
407
408
409 // Loop here to handle async request redispatches. 399 // Loop here to handle async request redispatches.
410 // The loop is controlled by the call to async.unhandle in the 400 // The loop is controlled by the call to async.unhandle in the
411 // finally block below. If call is from a non-blocking connector, 401 // finally block below. If call is from a non-blocking connector,
412 // then the unhandle will return false only if an async dispatch has 402 // then the unhandle will return false only if an async dispatch has
413 // already happened when unhandle is called. For a blocking connector, 403 // already happened when unhandle is called. For a blocking connector,
414 // the wait for the asynchronous dispatch or timeout actually happens 404 // the wait for the asynchronous dispatch or timeout actually happens
415 // within the call to unhandle(). 405 // within the call to unhandle().
416 406
417 final Server server=_server; 407 _request.setHandled(false);
418 _request._async.handling(); 408
419 if(server!=null && server.isRunning()) 409 String info=null;
420 { 410 try
421 _request.setHandled(false); 411 {
422 412 _uri.getPort();
423 String info=null; 413 String path = null;
414
424 try 415 try
425 { 416 {
426 _uri.getPort(); 417 path = _uri.getDecodedPath();
427 String path = null; 418 }
428 419 catch (Exception e)
429 try 420 {
421 LOG.warn("Failed UTF-8 decode for request path, trying ISO-8859-1");
422 LOG.trace("",e);
423 path = _uri.getDecodedPath(StringUtil.__ISO_8859_1);
424 }
425
426 info = URIUtil.canonicalPath(path);
427 if (info==null && !_request.getMethod().equals(HttpMethods.CONNECT))
428 {
429 if (path==null && _uri.getScheme()!=null && _uri.getHost()!=null)
430 { 430 {
431 path = _uri.getDecodedPath(); 431 info="/";
432 } 432 _request.setRequestURI("");
433 catch (Exception e)
434 {
435 LOG.warn("Failed UTF-8 decode for request path, trying ISO-8859-1");
436 LOG.trace("",e);
437 path = _uri.getDecodedPath(StringUtil.__ISO_8859_1);
438 }
439
440 info=URIUtil.canonicalPath(path);
441 if (info==null && !_request.getMethod().equals(HttpMethods.CONNECT))
442 {
443 if (path==null && _uri.getScheme()!=null && _uri.getHost()!=null)
444 {
445 info="/";
446 _request.setRequestURI("");
447 }
448 else
449 throw new HttpException(400);
450 }
451 _request.setPathInfo(info);
452
453 if (_out!=null)
454 _out.reopen();
455
456 _request.setDispatcherType(DispatcherType.REQUEST);
457 _connector.customize(_endp, _request);
458 server.handle(this);
459 }
460 catch (EofException e)
461 {
462 async_exception=e;
463 LOG.debug("",e);
464 error=true;
465 _request.setHandled(true);
466 if (!_response.isCommitted())
467 _generator.sendError(500, null, null, true);
468 }
469 catch (RuntimeIOException e)
470 {
471 async_exception=e;
472 LOG.debug("",e);
473 error=true;
474 _request.setHandled(true);
475 }
476 catch (HttpException e)
477 {
478 LOG.debug("",e);
479 error=true;
480 _request.setHandled(true);
481 _response.sendError(e.getStatus(), e.getReason());
482 }
483 catch (Throwable e)
484 {
485 async_exception=e;
486 LOG.warn(String.valueOf(_uri),e);
487 error=true;
488 _request.setHandled(true);
489 _generator.sendError(info==null?400:500, null, null, true);
490
491 }
492 finally
493 {
494 _request._async.unhandle();
495 }
496 }
497 }
498 finally
499 {
500 if (threadName!=null)
501 Thread.currentThread().setName(threadName);
502
503 if (_request._async.isUncompleted())
504 {
505
506 _request._async.doComplete(async_exception);
507
508 if (_expect100Continue)
509 {
510 LOG.debug("100 continues not sent");
511 // We didn't send 100 continues, but the latest interpretation
512 // of the spec (see httpbis) is that the client will either
513 // send the body anyway, or close. So we no longer need to
514 // do anything special here other than make the connection not persistent
515 _expect100Continue = false;
516 if (!_response.isCommitted())
517 _generator.setPersistent(false);
518 }
519
520 if(_endp.isOpen())
521 {
522 if (error)
523 {
524 _endp.shutdownOutput();
525 _generator.setPersistent(false);
526 if (!_generator.isComplete())
527 _response.complete();
528 } 433 }
529 else 434 else
530 { 435 throw new HttpException(400);
531 if (!_response.isCommitted() && !_request.isHandled()) 436 }
532 _response.sendError(HttpServletResponse.SC_NOT_FOUND); 437 _request.setPathInfo(info);
438
439 if (_out!=null)
440 _out.reopen();
441
442 _request.setDispatcherType(DispatcherType.REQUEST);
443 _connector.customize(_endp, _request);
444 _server.handle(this);
445 }
446 catch (EofException e)
447 {
448 LOG.debug("",e);
449 error=true;
450 _request.setHandled(true);
451 if (!_response.isCommitted())
452 _generator.sendError(500, null, null, true);
453 }
454 catch (RuntimeIOException e)
455 {
456 LOG.debug("",e);
457 error=true;
458 _request.setHandled(true);
459 }
460 catch (HttpException e)
461 {
462 LOG.debug("",e);
463 error=true;
464 _request.setHandled(true);
465 _response.sendError(e.getStatus(), e.getReason());
466 }
467 catch (Throwable e)
468 {
469 LOG.warn(String.valueOf(_uri),e);
470 error=true;
471 _request.setHandled(true);
472 _generator.sendError(info==null?400:500, null, null, true);
473
474 }
475 }
476 finally
477 {
478 if (_expect100Continue)
479 {
480 LOG.debug("100 continues not sent");
481 // We didn't send 100 continues, but the latest interpretation
482 // of the spec (see httpbis) is that the client will either
483 // send the body anyway, or close. So we no longer need to
484 // do anything special here other than make the connection not persistent
485 _expect100Continue = false;
486 if (!_response.isCommitted())
487 _generator.setPersistent(false);
488 }
489
490 if(_endp.isOpen())
491 {
492 if (error)
493 {
494 _endp.shutdownOutput();
495 _generator.setPersistent(false);
496 if (!_generator.isComplete())
533 _response.complete(); 497 _response.complete();
534 if (_generator.isPersistent())
535 _connector.persist(_endp);
536 }
537 } 498 }
538 else 499 else
539 { 500 {
501 if (!_response.isCommitted() && !_request.isHandled())
502 _response.sendError(HttpServletResponse.SC_NOT_FOUND);
540 _response.complete(); 503 _response.complete();
541 } 504 if (_generator.isPersistent())
542 505 _connector.persist(_endp);
543 _request.setHandled(true); 506 }
544 } 507 }
508 else
509 {
510 _response.complete();
511 }
512
513 _request.setHandled(true);
545 } 514 }
546 } 515 }
547 516
548 /* ------------------------------------------------------------ */ 517 /* ------------------------------------------------------------ */
549 public abstract Connection handle() throws IOException; 518 public abstract Connection handle() throws IOException;