Пример #1
0
  @Override
  protected final CloseableHttpResponse doExecute(
      final HttpHost target, final HttpRequest request, final HttpContext context)
      throws IOException, ClientProtocolException {

    Args.notNull(request, "HTTP request");
    // a null target may be acceptable, this depends on the route planner
    // a null context is acceptable, default context created below

    HttpContext execContext = null;
    RequestDirector director = null;
    HttpRoutePlanner routePlanner = null;
    ConnectionBackoffStrategy connectionBackoffStrategy = null;
    BackoffManager backoffManager = null;

    // Initialize the request execution context making copies of
    // all shared objects that are potentially threading unsafe.
    synchronized (this) {
      final HttpContext defaultContext = createHttpContext();
      if (context == null) {
        execContext = defaultContext;
      } else {
        execContext = new DefaultedHttpContext(context, defaultContext);
      }
      final HttpParams params = determineParams(request);
      final RequestConfig config = HttpClientParamConfig.getRequestConfig(params);
      execContext.setAttribute(ClientContext.REQUEST_CONFIG, config);

      // Create a director for this request
      director =
          createClientRequestDirector(
              getRequestExecutor(),
              getConnectionManager(),
              getConnectionReuseStrategy(),
              getConnectionKeepAliveStrategy(),
              getRoutePlanner(),
              getProtocolProcessor(),
              getHttpRequestRetryHandler(),
              getRedirectStrategy(),
              getTargetAuthenticationStrategy(),
              getProxyAuthenticationStrategy(),
              getUserTokenHandler(),
              params);
      routePlanner = getRoutePlanner();
      connectionBackoffStrategy = getConnectionBackoffStrategy();
      backoffManager = getBackoffManager();
    }

    try {
      if (connectionBackoffStrategy != null && backoffManager != null) {
        final HttpHost targetForRoute =
            (target != null)
                ? target
                : (HttpHost) determineParams(request).getParameter(ClientPNames.DEFAULT_HOST);
        final HttpRoute route = routePlanner.determineRoute(targetForRoute, request, execContext);

        final CloseableHttpResponse out;
        try {
          out = CloseableHttpResponseProxy.newProxy(director.execute(target, request, execContext));
        } catch (final RuntimeException re) {
          if (connectionBackoffStrategy.shouldBackoff(re)) {
            backoffManager.backOff(route);
          }
          throw re;
        } catch (final Exception e) {
          if (connectionBackoffStrategy.shouldBackoff(e)) {
            backoffManager.backOff(route);
          }
          if (e instanceof HttpException) {
            throw (HttpException) e;
          }
          if (e instanceof IOException) {
            throw (IOException) e;
          }
          throw new UndeclaredThrowableException(e);
        }
        if (connectionBackoffStrategy.shouldBackoff(out)) {
          backoffManager.backOff(route);
        } else {
          backoffManager.probe(route);
        }
        return out;
      } else {
        return CloseableHttpResponseProxy.newProxy(director.execute(target, request, execContext));
      }
    } catch (final HttpException httpException) {
      throw new ClientProtocolException(httpException);
    }
  }
Пример #2
0
 protected final CloseableHttpResponse m12027a(
     HttpHost httpHost, HttpRequest httpRequest, HttpContext httpContext) {
   HttpContext httpContext2;
   CloseableHttpResponse a;
   HttpRoute a2;
   Args.m12722a((Object) httpRequest, "HTTP request");
   synchronized (this) {
     HttpContext c = m12035c();
     if (httpContext == null) {
       httpContext2 = c;
     } else {
       Object defaultedHttpContext = new DefaultedHttpContext(httpContext, c);
     }
     HttpParams a3 = m12029a(httpRequest);
     httpContext2.m11529a("http.request-config", HttpClientParamConfig.m11524a(a3));
     RequestDirector a4 =
         m12026a(
             m12051s(), m12050r(), m12056x(), m12057y(), m12023F(), m12017I(), m12058z(),
             m12018A(), m12019B(), m12020C(), m12024G(), a3);
     HttpRoutePlanner F = m12023F();
     ConnectionBackoffStrategy u = m12053u();
     BackoffManager w = m12055w();
   }
   if (u == null || w == null) {
     a = CloseableHttpResponseProxy.m12097a(a4.m11474a(httpHost, httpRequest, httpContext2));
   } else {
     HttpHost httpHost2;
     if (httpHost != null) {
       httpHost2 = httpHost;
     } else {
       httpHost2 = (HttpHost) m12029a(httpRequest).m12084a("http.default-host");
     }
     try {
       a2 = F.m11701a(httpHost2, httpRequest, httpContext2);
       a = CloseableHttpResponseProxy.m12097a(a4.m11474a(httpHost, httpRequest, httpContext2));
       if (u.m11465a((HttpResponse) a)) {
         w.m11463a(a2);
       } else {
         w.m11464b(a2);
       }
     } catch (Throwable e) {
       if (u.m11466a(e)) {
         w.m11463a(a2);
       }
       throw e;
     } catch (Throwable e2) {
       if (u.m11466a(e2)) {
         w.m11463a(a2);
       }
       if (e2 instanceof HttpException) {
         throw ((HttpException) e2);
       } else if (e2 instanceof IOException) {
         throw ((IOException) e2);
       } else {
         throw new UndeclaredThrowableException(e2);
       }
     } catch (Throwable e22) {
       throw new ClientProtocolException(e22);
     }
   }
   return a;
 }