/* Handle a request from a connection.
   * Called to handle a request on the connection when either the header has been received,
   * or after the entire request has been received (for short requests of known length), or
   * on the dispatch of an async request.
   */
  public void handleAsync(AbstractHttpConnection connection) throws IOException, ServletException {
    final AsyncContinuation async = connection.getRequest().getAsyncContinuation();
    final AsyncContinuation.AsyncEventState state = async.getAsyncEventState();

    final Request baseRequest = connection.getRequest();
    final String path = state.getPath();

    if (path != null) {
      // this is a dispatch with a path
      final String contextPath = state.getServletContext().getContextPath();
      HttpURI uri = new HttpURI(URIUtil.addPaths(contextPath, path));
      baseRequest.setUri(uri);
      baseRequest.setRequestURI(null);
      baseRequest.setPathInfo(baseRequest.getRequestURI());
      if (uri.getQuery() != null) baseRequest.mergeQueryString(uri.getQuery());
    }

    final String target = baseRequest.getPathInfo();
    final HttpServletRequest request = (HttpServletRequest) async.getRequest();
    final HttpServletResponse response = (HttpServletResponse) async.getResponse();

    if (LOG.isDebugEnabled()) {
      LOG.debug("REQUEST " + target + " on " + connection);
      handle(target, baseRequest, request, response);
      LOG.debug("RESPONSE " + target + "  " + connection.getResponse().getStatus());
    } else handle(target, baseRequest, request, response);
  }
示例#2
0
    @Override
    protected SelectChannelEndPoint newEndPoint(
        SocketChannel channel, SelectSet selectSet, SelectionKey key) throws IOException {
      // We're connected, cancel the connect timeout
      Timeout.Task connectTimeout = _connectingChannels.remove(channel);
      if (connectTimeout != null) connectTimeout.cancel();
      if (LOG.isDebugEnabled())
        LOG.debug("Channels with connection pending: {}", _connectingChannels.size());

      // key should have destination at this point (will be replaced by endpoint after this call)
      HttpDestination dest = (HttpDestination) key.attachment();

      SelectChannelEndPoint scep =
          new SelectChannelEndPoint(channel, selectSet, key, (int) _httpClient.getIdleTimeout());
      AsyncEndPoint ep = scep;

      if (dest.isSecure()) {
        LOG.debug("secure to {}, proxied={}", channel, dest.isProxied());
        ep = new UpgradableEndPoint(ep, newSslEngine(channel));
      }

      AsyncConnection connection =
          selectSet.getManager().newConnection(channel, ep, key.attachment());
      ep.setConnection(connection);

      AbstractHttpConnection httpConnection = (AbstractHttpConnection) connection;
      httpConnection.setDestination(dest);

      if (dest.isSecure() && !dest.isProxied()) ((UpgradableEndPoint) ep).upgrade();

      dest.onNewConnection(httpConnection);

      return scep;
    }
  /* Handle a request from a connection.
   * Called to handle a request on the connection when either the header has been received,
   * or after the entire request has been received (for short requests of known length), or
   * on the dispatch of an async request.
   */
  public void handle(AbstractHttpConnection connection) throws IOException, ServletException {
    final String target = connection.getRequest().getPathInfo();
    final Request request = connection.getRequest();
    final Response response = connection.getResponse();

    if (LOG.isDebugEnabled()) {
      LOG.debug("REQUEST " + target + " on " + connection);
      handle(target, request, request, response);
      LOG.debug("RESPONSE " + target + "  " + connection.getResponse().getStatus());
    } else handle(target, request, request, response);
  }