示例#1
0
  protected void construct(String legalurl) throws HTTPException {
    this.legalurl = legalurl;
    try {
      sessionClient = new HttpClient(connmgr);
      HttpClientParams clientparams = sessionClient.getParams();

      // Allow (circular) redirects
      clientparams.setParameter(ALLOW_CIRCULAR_REDIRECTS, true);
      clientparams.setParameter(MAX_REDIRECTS, 25);

      if (globalSoTimeout > 0) setSoTimeout(globalSoTimeout);

      if (globalConnectionTimeout > 0) setConnectionTimeout(globalConnectionTimeout);

      if (globalAgent != null) setUserAgent(globalAgent); // May get overridden by setUserAgent

      setAuthenticationPreemptive(globalauthpreemptive);

      setProxy();

      if (TESTING) HTTPSession.track(this);

    } catch (Exception e) {
      throw new HTTPException("url=" + legalurl, e);
    }
  }
  public HttpImpl() {

    // Mimic behavior found in
    // http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html

    if (Validator.isNotNull(_NON_PROXY_HOSTS)) {
      String nonProxyHostsRegEx = _NON_PROXY_HOSTS;

      nonProxyHostsRegEx = nonProxyHostsRegEx.replaceAll("\\.", "\\\\.");
      nonProxyHostsRegEx = nonProxyHostsRegEx.replaceAll("\\*", ".*?");
      nonProxyHostsRegEx = nonProxyHostsRegEx.replaceAll("\\|", ")|(");

      nonProxyHostsRegEx = "(" + nonProxyHostsRegEx + ")";

      _nonProxyHostsPattern = Pattern.compile(nonProxyHostsRegEx);
    }

    MultiThreadedHttpConnectionManager httpConnectionManager =
        new MultiThreadedHttpConnectionManager();

    HttpConnectionManagerParams httpConnectionManagerParams = httpConnectionManager.getParams();

    httpConnectionManagerParams.setConnectionTimeout(_TIMEOUT);
    httpConnectionManagerParams.setDefaultMaxConnectionsPerHost(
        new Integer(_MAX_CONNECTIONS_PER_HOST));
    httpConnectionManagerParams.setMaxTotalConnections(new Integer(_MAX_TOTAL_CONNECTIONS));
    httpConnectionManagerParams.setSoTimeout(_TIMEOUT);

    _httpClient.setHttpConnectionManager(httpConnectionManager);
    _proxyHttpClient.setHttpConnectionManager(httpConnectionManager);

    if (hasProxyConfig() && Validator.isNotNull(_PROXY_USERNAME)) {
      List<String> authPrefs = new ArrayList<String>();

      if (_PROXY_AUTH_TYPE.equals("username-password")) {
        _proxyCredentials = new UsernamePasswordCredentials(_PROXY_USERNAME, _PROXY_PASSWORD);

        authPrefs.add(AuthPolicy.BASIC);
        authPrefs.add(AuthPolicy.DIGEST);
        authPrefs.add(AuthPolicy.NTLM);
      } else if (_PROXY_AUTH_TYPE.equals("ntlm")) {
        _proxyCredentials =
            new NTCredentials(
                _PROXY_USERNAME, _PROXY_PASSWORD, _PROXY_NTLM_HOST, _PROXY_NTLM_DOMAIN);

        authPrefs.add(AuthPolicy.NTLM);
        authPrefs.add(AuthPolicy.BASIC);
        authPrefs.add(AuthPolicy.DIGEST);
      }

      HttpClientParams httpClientParams = _proxyHttpClient.getParams();

      httpClientParams.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
    }
  }
示例#3
0
 public void setMaxRedirects(int n) {
   HttpClientParams clientparams = sessionClient.getParams();
   clientparams.setParameter(MAX_REDIRECTS, n);
 }