Ejemplo n.º 1
0
  /**
   * Get the inputStream from the connection.
   *
   * <p>If the associated response has the Expect header set to 100 Continue, then accessing the
   * input stream indicates that the handler/servlet is ready for the request body and thus a 100
   * Continue response is sent.
   *
   * @return The input stream for this connection. The stream will be created if it does not already
   *     exist.
   */
  public ServletInputStream getInputStream() throws IOException {
    // If the client is expecting 100 CONTINUE, then send it now.
    if (_expect100Continue) {
      // is content missing?
      if (((HttpParser) _parser).getHeaderBuffer() == null
          || ((HttpParser) _parser).getHeaderBuffer().length() < 2) {
        if (_generator.isCommitted())
          throw new IllegalStateException("Committed before 100 Continues");

        ((HttpGenerator) _generator).send1xx(HttpStatus.CONTINUE_100);
      }
      _expect100Continue = false;
    }

    if (_in == null) _in = new HttpInput(HttpConnection.this);
    return _in;
  }
Ejemplo n.º 2
0
  /* ------------------------------------------------------------ */
  public void completeResponse() throws IOException {
    if (!_generator.isCommitted()) {
      _generator.setResponse(_response.getStatus(), _response.getReason());
      try {
        _generator.completeHeader(_responseFields, Generator.LAST);
      } catch (IOException io) {
        throw io;
      } catch (RuntimeException e) {
        LOG.warn("header full: " + e);
        LOG.debug(e);

        _response.reset();
        _generator.reset(true);
        _generator.setResponse(HttpStatus.INTERNAL_SERVER_ERROR_500, null);
        _generator.completeHeader(_responseFields, Generator.LAST);
        _generator.complete();
        throw new HttpException(HttpStatus.INTERNAL_SERVER_ERROR_500);
      }
    }

    _generator.complete();
  }
Ejemplo n.º 3
0
  /* ------------------------------------------------------------ */
  public void commitResponse(boolean last) throws IOException {
    if (!_generator.isCommitted()) {
      _generator.setResponse(_response.getStatus(), _response.getReason());
      try {
        // If the client was expecting 100 continues, but we sent something
        // else, then we need to close the connection
        if (_expect100Continue && _response.getStatus() != 100) _generator.setPersistent(false);
        _generator.completeHeader(_responseFields, last);
      } catch (IOException io) {
        throw io;
      } catch (RuntimeException e) {
        LOG.warn("header full: " + e);

        _response.reset();
        _generator.reset(true);
        _generator.setResponse(HttpStatus.INTERNAL_SERVER_ERROR_500, null);
        _generator.completeHeader(_responseFields, Generator.LAST);
        _generator.complete();
        throw new HttpException(HttpStatus.INTERNAL_SERVER_ERROR_500);
      }
    }
    if (last) _generator.complete();
  }
Ejemplo n.º 4
0
 /* ------------------------------------------------------------ */
 public boolean isResponseCommitted() {
   return _generator.isCommitted();
 }