当前位置: 首页>>代码示例>>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;未经允许,请勿转载。