Java 类org.apache.http.conn.params.ConnRoutePNames 实例源码

项目:jmeter-bzm-plugins    文件:HttpUtils.java   
private static AbstractHttpClient createHTTPClient() {
    AbstractHttpClient client = new DefaultHttpClient();
    String proxyHost = System.getProperty("https.proxyHost", "");
    if (!proxyHost.isEmpty()) {
        int proxyPort = Integer.parseInt(System.getProperty("https.proxyPort", "-1"));
        log.info("Using proxy " + proxyHost + ":" + proxyPort);
        HttpParams params = client.getParams();
        HttpHost proxy = new HttpHost(proxyHost, proxyPort);
        params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

        String proxyUser = System.getProperty(JMeter.HTTP_PROXY_USER, JMeterUtils.getProperty(JMeter.HTTP_PROXY_USER));
        if (proxyUser != null) {
            log.info("Using authenticated proxy with username: " + proxyUser);
            String proxyPass = System.getProperty(JMeter.HTTP_PROXY_PASS, JMeterUtils.getProperty(JMeter.HTTP_PROXY_PASS));

            String localHost;
            try {
                localHost = InetAddress.getLocalHost().getCanonicalHostName();
            } catch (Throwable e) {
                log.error("Failed to get local host name, defaulting to 'localhost'", e);
                localHost = "localhost";
            }

            AuthScope authscope = new AuthScope(proxyHost, proxyPort);
            String proxyDomain = JMeterUtils.getPropDefault("http.proxyDomain", "");
            NTCredentials credentials = new NTCredentials(proxyUser, proxyPass, localHost, proxyDomain);
            client.getCredentialsProvider().setCredentials(authscope, credentials);
        }
    }
    return client;
}
项目:InstaManager    文件:Instaman.java   
public void builder(String twoFact){
    instagram = Instagram4j.builder().username(username).password(password).build();
    instagram.setup();
    if(sneakUsername.equals("")){
        sneakUsername = username;
    }

    if (proxyEnabled){
    HttpHost proxy = new HttpHost(serverIp, portNumber, "http");
    instagram.getClient().getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    instagram.getClient().getParams().setIntParameter("http.connection.timeout", 600000);

    instagram.getClient().getCredentialsProvider().setCredentials(
            new AuthScope(serverIp, portNumber),
            new UsernamePasswordCredentials(netUser, netPass));
    }

    try {
        if(!twoFact.equals(""))
            instagram.login(twoFact);
        else{instagram.login();}
        refreshResult();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:tokfm-parser    文件:HttpClientFactory.java   
public static HttpClient createNtlmProxyClient() {
    final String proxyHost = Configuration.getProperty("http.proxyHost");
    final String proxyPort = Configuration.getProperty("http.proxyPort");
    final String proxyUser = Configuration.getProperty("http.proxyUser");
    final String proxyPassword = Configuration.getProperty("http.proxyPassword");

    System.setProperty("http.proxyHost", proxyHost);
    System.setProperty("http.proxyPort", proxyPort);

    DefaultHttpClient client = new DefaultHttpClient();
    client.getCredentialsProvider().setCredentials(
            new AuthScope(proxyHost, Integer.parseInt(proxyPort)),
            new NTCredentials(proxyUser + ":" + proxyPassword));

    HttpHost proxy = new HttpHost(proxyHost, Integer.parseInt(proxyPort));
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

    return client;
}
项目:ucsd-spark-plugin    文件:UcsdHttpConnection.java   
/**
 * Configure proxy for this connection with a ProxySettings object
 *
 * @param proxy
 *            Proxy configuration file to use
 */
public void setProxy(ProxySettings proxy) {
    // If the proxy is set:
    if (proxy.isEnabled()) {
        HttpHost proxyConnection = new HttpHost(proxy.getServer(), proxy.getPort(), "http");

        // Proxy auth is handled like http authentication
        if (proxy.isAuth()) {
            AuthScope proxyScope = new AuthScope(proxy.getServer(), proxy.getPort());
            Credentials proxyCreds = new UsernamePasswordCredentials(proxy.getUsername(), proxy.getPassword());
            this.httpclient.getCredentialsProvider().setCredentials(proxyScope, proxyCreds);
        }

        // Register the proxy server with the http client handler
        this.httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxyConnection);
    }
}
项目:ryf_mms2    文件:RemoteAccessor.java   
public String getResponseByProxy(String url)throws Exception{
    httpClient = new DefaultHttpClient();

    do{
        HttpHost proxy = new HttpHost((String)getProxy().get(0), (Integer)getProxy().get(1));
        httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        httpGet = new HttpGet(url); 
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        int count = 0;
        try{
                content = httpClient.execute(httpGet, responseHandler);
        }catch(Exception e){
            System.out.println("Remote accessed by proxy["+(String)getProxy().get(0)+":"+(Integer)getProxy().get(1)+"] had Error!Try next!");
        }
        count++;
        if(count>2){break;}
    }while(content.length()==0);
    return content;
}
项目:dummydroid    文件:CheckinWorker.java   
protected void setProxy(HttpClient client) throws IOException {
    File cfgfile = new File(NETCFG);
    if (cfgfile.exists()) {
        Properties cfg = new Properties();
        cfg.load(new FileInputStream(cfgfile));
        String ph = cfg.getProperty(PROXYHOST, null);
        String pp = cfg.getProperty(PROXYPORT, null);
        String pu = cfg.getProperty(PROXYUSER, null);
        String pw = cfg.getProperty(PROXYPASS, null);
        if (ph == null || pp == null) {
            return;
        }
        final HttpHost proxy = new HttpHost(ph, Integer.parseInt(pp));
        client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        if (pu != null && pw != null) {
            ((DefaultHttpClient) client).getCredentialsProvider().setCredentials(
                    new AuthScope(proxy), new UsernamePasswordCredentials(pu, pw));
        }
    }
}
项目:Gobblin    文件:RestApiExtractor.java   
/**
 * get http client
 * @return default httpclient
 */
protected HttpClient getHttpClient() {
  if (httpClient == null) {
    httpClient = new DefaultHttpClient();

    if (super.workUnitState.contains(ConfigurationKeys.SOURCE_CONN_USE_PROXY_URL) && !super.workUnitState
        .getProp(ConfigurationKeys.SOURCE_CONN_USE_PROXY_URL).isEmpty()) {
      log.info("Connecting via proxy: " + super.workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_USE_PROXY_URL));

      HttpHost proxy = new HttpHost(super.workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_USE_PROXY_URL),
          super.workUnitState.getPropAsInt(ConfigurationKeys.SOURCE_CONN_USE_PROXY_PORT));
      httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
  }
  return httpClient;
}
项目:r01fb    文件:TwilioService.java   
@SuppressWarnings({ "resource"})
private TwilioRestClient _createTwilioRESTClient() {
       TwilioRestClient outClient = new TwilioRestClient(_apiData.getAccountSID().asString(),
                                                      _apiData.getAccountToken().asString());
    if (_proxySettings != null && _proxySettings.isEnabled()) {
        UrlComponents proxyUrlComps = _proxySettings.getProxyUrl().getComponents();
        log.info("Connecting to twilio through {}:{}",proxyUrlComps.getHost(), 
                                                      proxyUrlComps.getPort());
        // Get the twilio api underlying http client
        DefaultHttpClient httpClient = (DefaultHttpClient)outClient.getHttpClient();

        // Set proxy details
        HttpHost proxy = new HttpHost(proxyUrlComps.getHost().asString(),proxyUrlComps.getPort(),
                                      "http");
        httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
                                            proxy);
        httpClient.getCredentialsProvider().setCredentials(new AuthScope(proxyUrlComps.getHost().asString(), 
                                                                         proxyUrlComps.getPort()),
                                                           new UsernamePasswordCredentials(_proxySettings.getUserCode().asString(),
                                                                                           _proxySettings.getPassword().asString()));
        httpClient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF,
                                            Lists.newArrayList(AuthPolicy.BASIC));

    } 
    return outClient;
}
项目:play    文件:TestProxy.java   
public static void main(String[] args) {
    DefaultHttpClient hc = new DefaultHttpClient();
    hc.getCredentialsProvider().setCredentials(new AuthScope("10.192.18.148", 6600), new UsernamePasswordCredentials("c_dianxiaoxiangmuzu-001", "Cpic12345"));
    HttpHost proxy = new HttpHost("10.192.18.148", 6600, "http");

    hc.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    HttpHost target = new HttpHost("www.hao123.com");
    HttpGet get = new HttpGet("/");
    System.out.println("executing request to " + target + " via " + proxy);
    try {
        HttpResponse resp = hc.execute(target, get);
        System.out.println("status = " + resp.getStatusLine());
        HttpEntity entity = resp.getEntity();
        Header[] headers = resp.getAllHeaders();
        for (Header h : headers) {
            System.out.println(h);
        }
        System.out.println(EntityUtils.getContentCharSet(entity));
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        hc.getConnectionManager().shutdown();
    }
}
项目:elpaaso-core    文件:OnlineCfConsumerIT.java   
protected HttpClientConfig getHttpProxyConfigToQueryWebGuiRoutes() {
    HttpClientConfig defaultProxyConfig = null;
    if (cfAdapter.isUsingHttpProxy()) {
        final String httpProxyHost = cfAdapter.getHttpProxyHost();
        final int httpProxyPort = cfAdapter.getHttpProxyPort();

        defaultProxyConfig = new HttpClientConfig() {
            @Override
            public void applyConfig(DefaultHttpClient httpclient) {
                HttpHost proxy = new HttpHost(httpProxyHost, httpProxyPort);
                httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
            }

            @Override
            public String toString() {
                return "HttpClientConfig {httpProxyHost=" + httpProxyHost + " httpProxyPort=" + httpProxyPort + " }";
            }
        };

    }
    return defaultProxyConfig;
}
项目:daq-eclipse    文件:HttpClientTransport.java   
protected HttpClient createHttpClient() {
    DefaultHttpClient client = new DefaultHttpClient(createClientConnectionManager());
    if (useCompression) {
        client.addRequestInterceptor( new HttpRequestInterceptor() {
            @Override
            public void process(HttpRequest request, HttpContext context) {
                // We expect to received a compression response that we un-gzip
                request.addHeader("Accept-Encoding", "gzip");
            }
        });
    }
    if (getProxyHost() != null) {
        HttpHost proxy = new HttpHost(getProxyHost(), getProxyPort());
        client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

        if(getProxyUser() != null && getProxyPassword() != null) {
            client.getCredentialsProvider().setCredentials(
                new AuthScope(getProxyHost(), getProxyPort()),
                new UsernamePasswordCredentials(getProxyUser(), getProxyPassword()));
        }
    }
    return client;
}
项目:WS-Attacker    文件:Http4RequestSenderImpl.java   
private void setParamsToClient( HttpClient client )
{
    int timeout = TIMEOUT;
    if ( httpConnectionTimeout > 0 )
    {
        timeout = httpConnectionTimeout;
    }
    HttpParams params = client.getParams();
    params.setParameter( "http.socket.timeout", timeout );
    params.setParameter( "http.connection.timeout", timeout );
    params.setParameter( "http.connection-manager.max-per-host", 3000 );
    params.setParameter( "http.connection-manager.max-total", 3000 );

    final HttpConfig httpConfig = Preferences.getInstance().getHttpConfig();
    if ( !httpConfig.getProxyHost().isEmpty() && !httpConfig.getProxyPort().isEmpty() )
    {
        HttpHost proxy = new HttpHost( httpConfig.getProxyHost(), Integer.parseInt( httpConfig.getProxyPort() ) );
        params.setParameter( ConnRoutePNames.DEFAULT_PROXY, proxy );
    }

    HttpConnectionParams.setConnectionTimeout( params, timeout );
    HttpConnectionParams.setSoTimeout( params, timeout );
}
项目:OCR-Equation-Solver    文件:ApacheHttpTransaction.java   
/**
 * If this returns without throwing, then you can (and must) proceed to reading the
 * content using getResponseAsString() or getResponseAsStream(). If it throws, then
 * you do not have to read. You must always call release().
 *
 * @throws HttpHandlerException
 */
public void execute() throws WAHttpException {

    httpGet = new HttpGet(url.toString());
    HttpHost proxy = proxySettings.getProxyForHttpClient(url.toString());
    httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

    try {
        response = httpClient.execute(httpGet);
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK)
            throw new WAHttpException(statusCode);
        entity = response.getEntity();
    } catch (Exception e) {
        // This also releases all resources.
        httpGet.abort();
        if (e instanceof WAHttpException)
            throw (WAHttpException) e;
        else
            throw new WAHttpException(e);
    }
}
项目:raccoon4    文件:PlayManager.java   
/**
 * create a proxy client
 * 
 * @return either a client or null if none is configured
 * @throws KeyManagementException
 * @throws NumberFormatException
 *           if that port could not be parsed.
 * @throws NoSuchAlgorithmException
 */
private static HttpClient createProxyClient(PlayProfile profile)
        throws KeyManagementException, NoSuchAlgorithmException {
    if (profile.getProxyAddress() == null) {
        return null;
    }

    PoolingClientConnectionManager connManager = new PoolingClientConnectionManager(
            SchemeRegistryFactory.createDefault());
    connManager.setMaxTotal(100);
    connManager.setDefaultMaxPerRoute(30);

    DefaultHttpClient client = new DefaultHttpClient(connManager);
    client.getConnectionManager().getSchemeRegistry()
            .register(Utils.getMockedScheme());
    HttpHost proxy = new HttpHost(profile.getProxyAddress(),
            profile.getProxyPort());
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    if (profile.getProxyUser() != null && profile.getProxyPassword() != null) {
        client.getCredentialsProvider().setCredentials(
                new AuthScope(proxy),
                new UsernamePasswordCredentials(profile.getProxyUser(), profile
                        .getProxyPassword()));
    }
    return client;
}
项目:corelib    文件:HttpClientInternalImpl.java   
private HttpRequestBase createHttpRequest(HttpClient httpClient, HttpClient httpClientByte, String url, String method, HttpEntity entity) {
    checkParams(url, method);
    HttpRequestBase httpRequest = null;
    if (method.equalsIgnoreCase(HTTP_REQUEST_METHOD_GET)) {
        httpRequest = new HttpGet(url);
    } else {
        httpRequest = new HttpPost(url);
        if (entity != null) {
            ((HttpPost) httpRequest).setEntity(entity);
        }
    }

    HttpHost host = HttpProxy.getProxyHttpHost(mContext);
    if (host != null) {
        httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, host);
        httpClientByte.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, host);
    } else {
        httpClient.getParams().removeParameter(ConnRoutePNames.DEFAULT_PROXY);
    }
    return httpRequest;
}
项目:testfairy-jenkins-plugin    文件:Uploader.java   
private DefaultHttpClient buildHttpClient() {
    DefaultHttpClient httpClient = new DefaultHttpClient();

    // configure proxy (patched by timothy-volvo, https://github.com/timothy-volvo/testfairy-gradle-plugin)
    String proxyHost = System.getProperty("http.proxyHost");
    if (proxyHost != null) {
        Integer proxyPort = System.getProperty("http.proxyPort") != null ? Integer.parseInt(System.getProperty("http.proxyPort")) : -1;
        HttpHost proxy = new HttpHost(proxyHost, proxyPort);
        String proxyUser = System.getProperty("http.proxyUser");
        if (proxyUser != null) {
            AuthScope authScope = new AuthScope(proxyUser, proxyPort);
            Credentials credentials = new UsernamePasswordCredentials(proxyUser, System.getProperty("http.proxyPassword"));
            httpClient.getCredentialsProvider().setCredentials(authScope, credentials);
        }

        httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }

    return httpClient;
}
项目:swift-explorer    文件:HttpClientFactoryImpl.java   
private void setProxySettings (org.apache.http.client.HttpClient client, HasProxySettings proxySettings, String prot)
{
    if (client == null)
        return ;
       if (proxySettings == null || !proxySettings.isActive())
        return ;
       if (prot == null || prot.isEmpty())
        return ;

    org.apache.http.HttpHost proxy = new org.apache.http.HttpHost(proxySettings.getHost(), proxySettings.getPort(), prot) ;
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy) ;

    CredentialsProvider credProvider = ((AbstractHttpClient) client).getCredentialsProvider();
    credProvider.setCredentials(
            new AuthScope(proxySettings.getHost(), proxySettings.getPort()), 
            new UsernamePasswordCredentials(proxySettings.getUsername(), proxySettings.getPassword()));  
}
项目:hapi-fhir    文件:ClientUtils.java   
/**
 * 
 * @param request
 * @param payload
 * @return
 */
protected HttpResponse sendRequest(HttpUriRequest request) {
  HttpResponse response = null;
  try {
    HttpClient httpclient = new DefaultHttpClient();

    HttpParams params = httpclient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, timeout);
    HttpConnectionParams.setSoTimeout(params, timeout);
    if(proxy != null) {
      httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
    response = httpclient.execute(request);
  } catch(IOException ioe) {
    throw new EFhirClientException("Error sending Http Request: "+ioe.getMessage(), ioe);
  }
  return response;
}
项目:XPagesExtensionLibrary    文件:RestUtil.java   
public ClientHttpRequestFactory createRequestFactory(HttpProxyConfiguration httpProxyConfiguration, boolean trustSelfSignedCerts) {
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    HttpClient httpClient = requestFactory.getHttpClient();

    if (trustSelfSignedCerts) {
        registerSslSocketFactory(httpClient);
    } else {
        // We don't use self signed certs in Designer so this code will always be executed
        // TLSv1.0 has been disabled on Bluemix/Datapower 
        // We need to use TLSv1.2 or TLSv1.1 instead
        registerSslSocketFactoryTLS(httpClient);
    }

    if (httpProxyConfiguration != null) {
        HttpHost proxy = new HttpHost(httpProxyConfiguration.getProxyHost(), httpProxyConfiguration.getProxyPort());
        httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }

    return requestFactory;
}
项目:olingo-odata4    文件:ProxyWrappingHttpClientFactory.java   
@Override
public HttpClient create(final HttpMethod method, final URI uri) {
  // Use wrapped factory to obtain an httpclient instance for given method and uri
  final DefaultHttpClient httpclient = wrapped.create(method, uri);

  final HttpHost proxyHost = new HttpHost(proxy.getHost(), proxy.getPort());

  // Sets usage of HTTP proxy
  httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxyHost);

  // Sets proxy authentication, if credentials were provided
  if (proxyUsername != null && proxyPassword != null) {
    httpclient.getCredentialsProvider().setCredentials(
            new AuthScope(proxyHost),
            new UsernamePasswordCredentials(proxyUsername, proxyPassword));
  }

  return httpclient;
}
项目:SexyBelle    文件:HttpClientImpl.java   
private HttpRequestBase createHttpRequest(String url, String method, HttpEntity entity) {
    checkParams(url, method);
    HttpRequestBase httpRequest = null;
    if (method.equalsIgnoreCase(HTTP_REQUEST_METHOD_GET)) {
        httpRequest = new HttpGet(url);
    } else {
        httpRequest = new HttpPost(url);
        if (entity != null) {
            ((HttpPost) httpRequest).setEntity(entity);
        }
    }

    HttpHost host = HttpProxy.getProxyHttpHost(mContext);
    if (host != null) {
        httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, host);
        httpClientByte.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, host);
    } else {
        httpClient.getParams().removeParameter(ConnRoutePNames.DEFAULT_PROXY);
    }
    return httpRequest;
}
项目:InSpider    文件:HttpUtils.java   
/**
 * Method to create HttpsClient to handle https request.
 * @return Object of DefaultHttpClient
 * @throws NoSuchAlgorithmException
 * @throws KeyManagementException
 * @throws UnrecoverableKeyException
 * @throws CertificateException
 * @throws KeyStoreException
    * @throws IOException
    */
public static DefaultHttpClient createHttpsClient() throws NoSuchAlgorithmException, KeyManagementException, UnrecoverableKeyException, CertificateException,
        KeyStoreException, IOException {
    // create key managers
    keyManagers = HttpUtils.createKeyManagers();
    trustManagers = HttpUtils.createTrustManagers();

    SSLContext context = SSLContext.getInstance("SSLv3");
    context.init(keyManagers, trustManagers, null);
    org.apache.http.conn.ssl.SSLSocketFactory sslSocketFactory = new SSLSocketFactory(context);
    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, 60000);// was 10000
    HttpConnectionParams.setSoTimeout(httpParams, 60000);// was 30000
    DefaultHttpClient httpClient = new DefaultHttpClient(httpParams);
    // http-proxy
    if (!StringUtils.isEmpty(System.getProperty("https.proxyHost")) && !StringUtils.isEmpty(System.getProperty("https.proxyPort"))) {
        HttpHost proxy = new HttpHost(System.getProperty("https.proxyHost"), Integer.parseInt(System.getProperty("https.proxyPort")));
        httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
    httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 443, sslSocketFactory));
    return httpClient;
}
项目:itheima    文件:HttpClientUtils.java   
/**
     * 构造方法,如果有代理就设置代理。
     */
    public HttpClientUtils(){

        HttpParams params = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(params, 4000); //设置连接超时
        HttpConnectionParams.setSoTimeout(params, 5000); //设置请求超时
//        post.setParams(params);

        client = new DefaultHttpClient(params);//默认的Http客户端。

        //如果有代理地址,先设置代理。
        if(StringUtils.isNotBlank(GlobalParams.PROXY)){

            //设置代理主机的地址和端口。
            HttpHost host = new HttpHost(GlobalParams.PROXY, GlobalParams.PORT);
            //设置client的代理主机。
            client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, host);

        }
    }
项目:ns-api    文件:NationStates.java   
private synchronized InputStream doRequest(String url) throws IOException {
    if (verbose) {
        System.out.println("Making HTTP request: " + url);
    }

    final HttpParams httpParams = new BasicHttpParams();
    HttpClient client = new DefaultHttpClient(httpParams);
    if (proxyIP != null) {
        HttpHost proxy = new HttpHost(proxyIP, proxyPort);
        client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
    HttpConnectionParams.setConnectionTimeout(client.getParams(), (int) timeout);
    HttpConnectionParams.setSoTimeout(client.getParams(), (int) timeout);
    client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, this.userAgent);
    client.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
    HttpGet get = new HttpGet(url);
    HttpResponse response = client.execute(get);
    if (verbose) {
        System.out.println("Status code for request: " + response.getStatusLine().getStatusCode());
    }
    if (response.getStatusLine().getStatusCode() == 429)  {
        hardRateLimit = System.currentTimeMillis() + 900000L; //15 min
        throw new RateLimitReachedException();
    }
    return response.getEntity().getContent();
}
项目:iaf    文件:WebServiceNtlmSender.java   
public void configure() throws ConfigurationException {
    super.configure();

    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, getTimeout());
    HttpConnectionParams.setSoTimeout(httpParameters, getTimeout());
    httpClient = new DefaultHttpClient(connectionManager, httpParameters);
    httpClient.getAuthSchemes().register("NTLM", new NTLMSchemeFactory());
    CredentialFactory cf = new CredentialFactory(getAuthAlias(),
            getUserName(), getPassword());
    httpClient.getCredentialsProvider().setCredentials(
            new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
            new NTCredentials(cf.getUsername(), cf.getPassword(), Misc
                    .getHostname(), getAuthDomain()));
    if (StringUtils.isNotEmpty(getProxyHost())) {
        HttpHost proxy = new HttpHost(getProxyHost(), getProxyPort());
        httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
                proxy);
    }
}
项目:h2o-2    文件:GoogleAnalytics.java   
protected HttpClient createHttpClient(GoogleAnalyticsConfig config) {
  ThreadSafeClientConnManager connManager = new ThreadSafeClientConnManager();
  connManager.setDefaultMaxPerRoute(getDefaultMaxPerRoute(config));

  BasicHttpParams params = new BasicHttpParams();

  if (isNotEmpty(config.getUserAgent())) {
    params.setParameter(CoreProtocolPNames.USER_AGENT, config.getUserAgent());
  }

  if (isNotEmpty(config.getProxyHost())) {
    params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(config.getProxyHost(), config.getProxyPort()));
  }

  DefaultHttpClient client = new DefaultHttpClient(connManager, params);

  if (isNotEmpty(config.getProxyUserName())) {
    BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(config.getProxyHost(), config.getProxyPort()),
            new UsernamePasswordCredentials(config.getProxyUserName(), config.getProxyPassword()));
    client.setCredentialsProvider(credentialsProvider);
  }

  return client;
}
项目:deezer-api-client    文件:HttpResourceConnection.java   
@Override
public String getData(String url) throws IOException {

    HttpClient client = new DefaultHttpClient();

    if (useProxy()) {
        HttpHost proxy = new HttpHost(proxyHost,proxyPort);
        client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);
    }

    HttpGet request = new HttpGet(url);
    HttpResponse response = client.execute(request);

    BufferedReader rd = new BufferedReader(
            new InputStreamReader(response.getEntity().getContent()));

    StringBuffer result = new StringBuffer();
    String line = "";
    while ((line = rd.readLine()) != null) {
        result.append(line);
    }

    return result.toString();

}
项目:isc-maven-plugin    文件:Downloads.java   
/**
 * Configures the {@link #httpClient}, specifically with the current {@link #proxyConfiguration}. 
 * 
 * @throws MojoExecutionException
 */
private void setup() throws MojoExecutionException {
    try {
        if (proxyConfiguration != null && isProxied(proxyConfiguration) ) {
            if (proxyConfiguration.getUsername() != null) {
                httpClient.getCredentialsProvider().setCredentials(
                    new AuthScope(proxyConfiguration.getHost(), proxyConfiguration.getPort()),
                    new UsernamePasswordCredentials(proxyConfiguration.getUsername(), proxyConfiguration.getPassword()));   
            }
            HttpHost proxy = new HttpHost(proxyConfiguration.getHost(), proxyConfiguration.getPort());
            httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Error obtaining Maven settings", e);
    }
}
项目:neo4j-webgraph    文件:SimpleHttpClient.java   
public void configProxy(String proxyHost, int proxyPort, String proxyUsername, String proxyPassword) {
    if (isShutdown.get()) {
        return;
    }

    if (proxyHost == null) {
        return;
    }

    theClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(proxyHost, proxyPort, "http"));
    logger.info("Configured proxy host " + proxyHost);

    if (proxyUsername != null) {
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort),
                new UsernamePasswordCredentials(proxyUsername, proxyPassword));
        defaultClient.setCredentialsProvider(credsProvider);
        logger.info("Configured proxy user " + proxyUsername);
    }
}
项目:red5-mobileconsole    文件:HttpConnectionUtil.java   
/**
 * Returns a client with all our selected properties / params.
 * 
 * @return client
 */
public static final DefaultHttpClient getClient() {
    // create a singular HttpClient object
    DefaultHttpClient client = new DefaultHttpClient(connectionManager);
    // dont retry
    client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
    // get the params for the client
    HttpParams params = client.getParams();
    // establish a connection within x seconds
    params.setParameter(CoreConnectionPNames.SO_TIMEOUT, connectionTimeout);
    // no redirects
    params.setParameter(ClientPNames.HANDLE_REDIRECTS, false);
    // set custom ua
    params.setParameter(CoreProtocolPNames.USER_AGENT, userAgent);
    // set the proxy if the user has one set
    if ((System.getProperty("http.proxyHost") != null) && (System.getProperty("http.proxyPort") != null)) {
           HttpHost proxy = new HttpHost(System.getProperty("http.proxyHost").toString(), Integer.valueOf(System.getProperty("http.proxyPort")));
           client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
    return client;
}
项目:Equella    文件:HttpServiceImpl.java   
private ResponseImpl getWebContentPrivate(Request request, @Nullable ProxyDetails proxy, boolean followRedirects)
{
    final String url = request.getUrl();
    try
    {
        @SuppressWarnings("unused")
        URL u = new URL(url); // NOSONAR
    }
    catch( MalformedURLException ex )
    {
        return new ResponseImpl(HttpServletResponse.SC_BAD_REQUEST, "Invalid URL: " + url);
    }
    HttpRequestBase httpMethod = null;
    try
    {
        httpMethod = getHttpMethod(request);
        if( httpMethod == null )
        {
            return new ResponseImpl(HttpServletResponse.SC_METHOD_NOT_ALLOWED,
                "Only GET, POST, HEAD, PUT, DELETE and OPTIONS methods are supported");
        }
        if( !followRedirects )
        {
            HttpClientParams.setRedirecting(httpMethod.getParams(), false);
        }

        final DefaultHttpClient client = createClient(httpMethod.getURI().getScheme().equals("https"));

        if( proxy != null && proxy.isConfigured() )
        {
            final URI uri = httpMethod.getURI();
            final String host = uri.getHost();
            if( !proxy.isHostExcepted(host) )
            {
                final HttpHost proxyHost = new HttpHost(proxy.getHost(), proxy.getPort());
                client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxyHost);
                if( !Check.isEmpty(proxy.getUsername()) )
                {
                    client.getCredentialsProvider().setCredentials(
                        new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
                        new UsernamePasswordCredentials(proxy.getUsername(), proxy.getPassword()));

                }
            }
        }

        // TODO: see fixme about cookie cache
        final String cacheKey = /* req.getSession().getId() */"FIXME" + ':' + url;
        Cookies cookies = COOKIE_CACHE.getIfPresent(cacheKey);
        if( cookies == null )
        {
            cookies = new Cookies();
            COOKIE_CACHE.put(cacheKey, cookies);
        }

        final HttpResponse response = exec(client, httpMethod, cookies);
        return new ResponseImpl(response, httpMethod);
    }
    catch( Exception e )
    {
        throw new RuntimeException(e);
    }
}
项目:sealtalk-android-master    文件:AsyncHttpClient.java   
/**
 * Sets the Proxy by it's hostname,port,username and password
 *
 * @param hostname the hostname (IP or DNS name)
 * @param port     the port number. -1 indicates the scheme default port.
 * @param username the username
 * @param password the password
 */
public void setProxy(String hostname, int port, String username, String password) {
    httpClient.getCredentialsProvider().setCredentials(
        new AuthScope(hostname, port),
        new UsernamePasswordCredentials(username, password));
    final HttpHost proxy = new HttpHost(hostname, port);
    final HttpParams httpParams = this.httpClient.getParams();
    httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
项目:android-project-gallery    文件:AsyncHttpClient.java   
/**
 * Sets the Proxy by it's hostname,port,username and password
 *
 * @param hostname the hostname (IP or DNS name)
 * @param port     the port number. -1 indicates the scheme default port.
 * @param username the username
 * @param password the password
 */
public void setProxy(String hostname, int port, String username, String password) {
    httpClient.getCredentialsProvider().setCredentials(
            new AuthScope(hostname, port),
            new UsernamePasswordCredentials(username, password));
    final HttpHost proxy = new HttpHost(hostname, port);
    final HttpParams httpParams = this.httpClient.getParams();
    httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
项目:rongyunDemo    文件:AsyncHttpClient.java   
/**
 * Sets the Proxy by it's hostname,port,username and password
 *
 * @param hostname the hostname (IP or DNS name)
 * @param port     the port number. -1 indicates the scheme default port.
 * @param username the username
 * @param password the password
 */
public void setProxy(String hostname, int port, String username, String password) {
    httpClient.getCredentialsProvider().setCredentials(
        new AuthScope(hostname, port),
        new UsernamePasswordCredentials(username, password));
    final HttpHost proxy = new HttpHost(hostname, port);
    final HttpParams httpParams = this.httpClient.getParams();
    httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
项目:Mobike    文件:AsyncHttpClient.java   
/**
 * Sets the Proxy by it's hostname,port,username and password
 *
 * @param hostname the hostname (IP or DNS name)
 * @param port     the port number. -1 indicates the scheme default port.
 * @param username the username
 * @param password the password
 */
public void setProxy(String hostname, int port, String username, String password) {
    httpClient.getCredentialsProvider().setCredentials(
            new AuthScope(hostname, port),
            new UsernamePasswordCredentials(username, password));
    final HttpHost proxy = new HttpHost(hostname, port);
    final HttpParams httpParams = this.httpClient.getParams();
    httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
项目:bdf2    文件:HttpClientUtils.java   
public static void testWithProxy(HttpClient httpClient) {
    HttpHost proxy = new HttpHost("172.16.80.8", 8080);
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    UsernamePasswordCredentials creds = new UsernamePasswordCredentials("yaoman", "sinochem1");
    credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), creds);
    httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    ((DefaultHttpClient) httpClient).setCredentialsProvider(credsProvider);
}
项目:RongCloudJcenter    文件:AsyncHttpClient.java   
/**
 * Sets the Proxy by it's hostname,port,username and password
 *
 * @param hostname the hostname (IP or DNS name)
 * @param port     the port number. -1 indicates the scheme default port.
 * @param username the username
 * @param password the password
 */
public void setProxy(String hostname, int port, String username, String password) {
    httpClient.getCredentialsProvider().setCredentials(
        new AuthScope(hostname, port),
        new UsernamePasswordCredentials(username, password));
    final HttpHost proxy = new HttpHost(hostname, port);
    final HttpParams httpParams = this.httpClient.getParams();
    httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
项目:TAG    文件:AsyncHttpClient.java   
/**
 * Sets the Proxy by it's hostname,port,username and password
 *
 * @param hostname the hostname (IP or DNS name)
 * @param port     the port number. -1 indicates the scheme default port.
 * @param username the username
 * @param password the password
 */
public void setProxy(String hostname, int port, String username, String password) {
    httpClient.getCredentialsProvider().setCredentials(
            new AuthScope(hostname, port),
            new UsernamePasswordCredentials(username, password));
    final HttpHost proxy = new HttpHost(hostname, port);
    final HttpParams httpParams = this.httpClient.getParams();
    httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
项目:codePay    文件:SafeHttpClient.java   
/**
 * 设置代理.
 */
private void setProxy() {
    HttpHost httpHost = httpHosts.get(0);
    String proxyUserName = "test";
    String proxyPassWord = "123456";
    AuthScope authScope = new AuthScope(httpHost.getHostName(), httpHost.getPort());
    this.getCredentialsProvider().setCredentials(authScope,
            new UsernamePasswordCredentials(proxyUserName, proxyPassWord));
    this.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, httpHost);
}
项目:RongChat    文件:AsyncHttpClient.java   
/**
 * Sets the Proxy by it's hostname,port,username and password
 *
 * @param hostname the hostname (IP or DNS name)
 * @param port     the port number. -1 indicates the scheme default port.
 * @param username the username
 * @param password the password
 */
public void setProxy(String hostname, int port, String username, String password) {
    httpClient.getCredentialsProvider().setCredentials(
            new AuthScope(hostname, port),
            new UsernamePasswordCredentials(username, password));
    final HttpHost proxy = new HttpHost(hostname, port);
    final HttpParams httpParams = this.httpClient.getParams();
    httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}