當前位置: 首頁>>代碼示例>>Java>>正文


Java ConnRoutePNames類代碼示例

本文整理匯總了Java中org.apache.http.conn.params.ConnRoutePNames的典型用法代碼示例。如果您正苦於以下問題:Java ConnRoutePNames類的具體用法?Java ConnRoutePNames怎麽用?Java ConnRoutePNames使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ConnRoutePNames類屬於org.apache.http.conn.params包,在下文中一共展示了ConnRoutePNames類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createHTTPClient

import org.apache.http.conn.params.ConnRoutePNames; //導入依賴的package包/類
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;
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:32,代碼來源:HttpUtils.java

示例2: builder

import org.apache.http.conn.params.ConnRoutePNames; //導入依賴的package包/類
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();
    }
}
 
開發者ID:ozankaraali,項目名稱:InstaManager,代碼行數:27,代碼來源:Instaman.java

示例3: createNtlmProxyClient

import org.apache.http.conn.params.ConnRoutePNames; //導入依賴的package包/類
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;
}
 
開發者ID:slq,項目名稱:tokfm-parser,代碼行數:20,代碼來源:HttpClientFactory.java

示例4: setProxy

import org.apache.http.conn.params.ConnRoutePNames; //導入依賴的package包/類
/**
 * 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);
	}
}
 
開發者ID:CiscoUKIDCDev,項目名稱:ucsd-spark-plugin,代碼行數:23,代碼來源:UcsdHttpConnection.java

示例5: getResponseByProxy

import org.apache.http.conn.params.ConnRoutePNames; //導入依賴的package包/類
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;
}
 
開發者ID:wufeisoft,項目名稱:ryf_mms2,代碼行數:20,代碼來源:RemoteAccessor.java

示例6: setProxy

import org.apache.http.conn.params.ConnRoutePNames; //導入依賴的package包/類
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));
		}
	}
}
 
開發者ID:onyxbits,項目名稱:dummydroid,代碼行數:21,代碼來源:CheckinWorker.java

示例7: getHttpClient

import org.apache.http.conn.params.ConnRoutePNames; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:Hanmourang,項目名稱:Gobblin,代碼行數:20,代碼來源:RestApiExtractor.java

示例8: _createTwilioRESTClient

import org.apache.http.conn.params.ConnRoutePNames; //導入依賴的package包/類
@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;
}
 
開發者ID:opendata-euskadi,項目名稱:r01fb,代碼行數:27,代碼來源:TwilioService.java

示例9: main

import org.apache.http.conn.params.ConnRoutePNames; //導入依賴的package包/類
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();
	}
}
 
開發者ID:toulezu,項目名稱:play,代碼行數:25,代碼來源:TestProxy.java

示例10: getHttpProxyConfigToQueryWebGuiRoutes

import org.apache.http.conn.params.ConnRoutePNames; //導入依賴的package包/類
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;
}
 
開發者ID:orange-cloudfoundry,項目名稱:elpaaso-core,代碼行數:23,代碼來源:OnlineCfConsumerIT.java

示例11: createHttpClient

import org.apache.http.conn.params.ConnRoutePNames; //導入依賴的package包/類
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;
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:24,代碼來源:HttpClientTransport.java

示例12: setParamsToClient

import org.apache.http.conn.params.ConnRoutePNames; //導入依賴的package包/類
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 );
}
 
開發者ID:RUB-NDS,項目名稱:WS-Attacker,代碼行數:24,代碼來源:Http4RequestSenderImpl.java

示例13: execute

import org.apache.http.conn.params.ConnRoutePNames; //導入依賴的package包/類
/**
 * 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);
    }
}
 
開發者ID:shobhitchittora,項目名稱:OCR-Equation-Solver,代碼行數:29,代碼來源:ApacheHttpTransaction.java

示例14: createProxyClient

import org.apache.http.conn.params.ConnRoutePNames; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:onyxbits,項目名稱:raccoon4,代碼行數:35,代碼來源:PlayManager.java

示例15: createHttpRequest

import org.apache.http.conn.params.ConnRoutePNames; //導入依賴的package包/類
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;
}
 
開發者ID:MichaelSun,項目名稱:corelib,代碼行數:22,代碼來源:HttpClientInternalImpl.java


注:本文中的org.apache.http.conn.params.ConnRoutePNames類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。