本文整理汇总了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;
}
示例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();
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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));
}
}
}
示例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;
}
示例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;
}
示例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();
}
}
示例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;
}
示例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;
}
示例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 );
}
示例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);
}
}
示例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;
}
示例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;
}