use of org.apache.http.HttpHost in project neo4j by neo4j.
the class UdcExtensionImplTest method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
UdcTimerTask.successCounts.clear();
UdcTimerTask.failureCounts.clear();
handler = new PingerHandler();
serverBootstrap.registerHandler("/*", handler);
HttpHost target = start();
int servicePort = target.getPort();
String serviceHostName = target.getHostName();
String serverAddress = serviceHostName + ":" + servicePort;
config = new HashMap<>();
config.put(UdcSettings.first_delay.name(), "100");
config.put(UdcSettings.udc_host.name(), serverAddress);
blockUntilServerAvailable(new URL("http", serviceHostName, servicePort, "/"));
}
use of org.apache.http.HttpHost in project UltimateAndroid by cymcsg.
the class CommonHttpClient method getNewInstance.
// 每次返回同一实例
// public static synchronized HttpClient getInstance(Context mContext){
//
// if(null == singleStance){
// singleStance = getNewInstance(mContext);
// }
// return singleStance ;
// }
// 每次都返回新的HttpClient实例
public static HttpClient getNewInstance(Context mContext) {
HttpClient newInstance;
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
HttpProtocolParams.setUseExpectContinue(params, true);
// 自定义三个timeout参数
/*
* 1.set a timeout for the connection manager,it defines how long we
* should wait to get a connection out of the connection pool managed by
* the connection manager
*/
ConnManagerParams.setTimeout(params, 5000);
/*
* 2.The second timeout value defines how long we should wait to make a
* connection over the network to the server on the other end
*/
HttpConnectionParams.setConnectionTimeout(params, TIMEOUT);
/*
* 3.we set a socket timeout value to 4 seconds to define how long we
* should wait to get data back for our request.
*/
HttpConnectionParams.setSoTimeout(params, TIMEOUT_SOCKET);
SchemeRegistry schReg = new SchemeRegistry();
schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);
newInstance = new DefaultHttpClient(conMgr, params);
switch(checkNetworkTypeDeprecated(mContext)) {
case TYPE_CT_WAP:
{
// 通过代理解决中国移动联通GPRS中wap无法访问的问题
HttpHost proxy = new HttpHost("10.0.0.200", 80, "http");
newInstance.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
Logs.v("当前网络类型为cm_cu_wap,设置代理10.0.0.200访问www");
}
break;
case TYPE_CM_CU_WAP:
{
// 通过代理解决中国移动联通GPRS中wap无法访问的问题
HttpHost proxy = new HttpHost("10.0.0.172", 80, "http");
newInstance.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
Logs.v("当前网络类型为cm_cu_wap,设置代理10.0.0.172访问www");
}
break;
}
return newInstance;
}
use of org.apache.http.HttpHost in project dropwizard by dropwizard.
the class HttpClientBuilderTest method usesProxy.
@Test
public void usesProxy() throws Exception {
HttpClientConfiguration config = new HttpClientConfiguration();
ProxyConfiguration proxy = new ProxyConfiguration("192.168.52.11", 8080);
config.setProxyConfiguration(proxy);
checkProxy(config, new HttpHost("dropwizard.io", 80), new HttpHost("192.168.52.11", 8080));
}
use of org.apache.http.HttpHost in project dropwizard by dropwizard.
the class HttpClientBuilderTest method usesProxyWithAuth.
@Test
public void usesProxyWithAuth() throws Exception {
HttpClientConfiguration config = new HttpClientConfiguration();
AuthConfiguration auth = new AuthConfiguration("secret", "stuff");
ProxyConfiguration proxy = new ProxyConfiguration("192.168.52.11", 8080, "http", auth);
config.setProxyConfiguration(proxy);
CloseableHttpClient httpClient = checkProxy(config, new HttpHost("dropwizard.io", 80), new HttpHost("192.168.52.11", 8080, "http"));
CredentialsProvider credentialsProvider = (CredentialsProvider) FieldUtils.getField(httpClient.getClass(), "credentialsProvider", true).get(httpClient);
assertThat(credentialsProvider.getCredentials(new AuthScope("192.168.52.11", 8080))).isEqualTo(new UsernamePasswordCredentials("secret", "stuff"));
}
use of org.apache.http.HttpHost in project dropwizard by dropwizard.
the class HttpClientBuilderTest method usesProxyWithoutPort.
@Test
public void usesProxyWithoutPort() throws Exception {
HttpClientConfiguration config = new HttpClientConfiguration();
ProxyConfiguration proxy = new ProxyConfiguration("192.168.52.11");
config.setProxyConfiguration(proxy);
checkProxy(config, new HttpHost("dropwizard.io", 80), new HttpHost("192.168.52.11"));
}
Aggregations