本文整理匯總了Java中org.apache.http.HttpHost類的典型用法代碼示例。如果您正苦於以下問題:Java HttpHost類的具體用法?Java HttpHost怎麽用?Java HttpHost使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HttpHost類屬於org.apache.http包,在下文中一共展示了HttpHost類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execute
import org.apache.http.HttpHost; //導入依賴的package包/類
public <T> T execute(HttpHost target, HttpRequest request,
ResponseHandler<? extends T> responseHandler, HttpContext context)
throws IOException, ClientProtocolException {
HttpResponse response = execute(target, request, context);
try {
return responseHandler.handleResponse(response);
} finally {
HttpEntity entity = response.getEntity();
if (entity != null) EntityUtils.consume(entity);
}
}
示例2: stopGridHub
import org.apache.http.HttpHost; //導入依賴的package包/類
/**
* Stop the configured Selenium Grid hub server.
*
* @param localOnly 'true' to target only local Grid hub server
* @return 'false' if [localOnly] and hub is remote; otherwise 'true'
*/
public static boolean stopGridHub(boolean localOnly) {
if (localOnly && !isLocalHub()) {
return false;
}
GridHubConfiguration hubConfig = SeleniumConfig.getConfig().getHubConfig();
if (isHubActive(hubConfig)) {
HttpHost hubHost = GridUtility.getHubHost(hubConfig);
try {
GridUtility.getHttpResponse(hubHost, HUB_SHUTDOWN);
new UrlChecker().waitUntilUnavailable(SHUTDOWN_DELAY, TimeUnit.SECONDS, URI.create(hubHost.toURI()).toURL());
} catch (IOException | TimeoutException e) {
throw UncheckedThrow.throwUnchecked(e);
}
}
setHubProcess(null);
return true;
}
示例3: authFailed
import org.apache.http.HttpHost; //導入依賴的package包/類
public void authFailed(
final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) {
if (authhost == null) {
throw new IllegalArgumentException("Host may not be null");
}
if (context == null) {
throw new IllegalArgumentException("HTTP context may not be null");
}
AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
if (authCache != null) {
if (this.log.isDebugEnabled()) {
this.log.debug("Clearing cached auth scheme for " + authhost);
}
authCache.remove(authhost);
}
}
示例4: doValidateProxy
import org.apache.http.HttpHost; //導入依賴的package包/類
@WebLog
@RequestMapping(value="/proxyController/doValidateProxy")
@ResponseBody
public Proxy doValidateProxy(String id, String proxyType, String proxyIp, Integer proxyPort) {
HttpHost httpHost = new HttpHost(proxyIp, proxyPort, proxyType);
Proxy proxy = new Proxy();
if(HttpManager.get().checkProxy(httpHost)) {
proxy.setType(proxyType);
proxy.setIp(proxyIp);
proxy.setPort(proxyPort);
proxyDao.updateProxyById(id); //更新最後驗證時間
} else {
proxyDao.deleteProxyById(id); //物理刪除數據
}
return proxy;
}
示例5: connectSocket
import org.apache.http.HttpHost; //導入依賴的package包/類
@Override
public Socket connectSocket(
final int connectTimeout,
final Socket socket,
final HttpHost host,
final InetSocketAddress remoteAddress,
final InetSocketAddress localAddress,
final HttpContext context) throws IOException {
if (log.isDebugEnabled()) {
log.debug("Connecting to {}:{}", remoteAddress.getAddress(), remoteAddress.getPort());
}
Socket connectedSocket = super.connectSocket(connectTimeout, socket, host, remoteAddress, localAddress, context);
if (connectedSocket instanceof SSLSocket) {
return new SdkSslSocket((SSLSocket) connectedSocket);
}
return new SdkSocket(connectedSocket);
}
示例6: ApacheHttpRequestRecordReplayer
import org.apache.http.HttpHost; //導入依賴的package包/類
@Inject
public ApacheHttpRequestRecordReplayer(
Config config,
ApacheHttpClientFactory httpClientFactory,
MetricRegistry metricRegistry,
JtlPrinter jtlPrinter) {
// Check arguments.
checkNotNull(config, "config");
checkNotNull(httpClientFactory, "httpClientFactory");
checkNotNull(metricRegistry, "metricRegistry");
checkNotNull(jtlPrinter, "jtlPrinter");
// Set class fields.
this.metricRegistry = metricRegistry;
this.jtlPrinter = jtlPrinter;
this.httpHost = new HttpHost(config.getTargetHost(), config.getTargetPort());
this.httpClient = httpClientFactory.create();
LOGGER.debug("instantiated");
}
示例7: checkProxys
import org.apache.http.HttpHost; //導入依賴的package包/類
public void checkProxys(){
while(true){
Proxy proxy = this.poplProxy();
HttpHost host = new HttpHost(proxy.getIp(),proxy.getPort());
RequestConfig config = RequestConfig.custom().setProxy(host).build();
HttpGet httpGet = new HttpGet(PROXY_TEST_URL);
httpGet.setConfig(config);
try {
CloseableHttpResponse response = this.httpClient.execute(httpGet);
String content = EntityUtils.toString(response.getEntity(), Charset.forName("UTF-8"));
if(content!=null&&content.trim().equals(proxy.getIp()))
this.pushrProxy(proxy);
} catch (IOException e) {
}
}
}
示例8: testAllowOnlySync
import org.apache.http.HttpHost; //導入依賴的package包/類
@Test
public void testAllowOnlySync() throws Exception {
proxy = new SimpleFixedHttpProxy();
URI robotsURL = URI.create("http://foo.bor/robots.txt");
proxy.add200(robotsURL, "",
"# goodguy can do anything\n" +
"User-agent: goodguy\n" +
"Disallow:\n\n" +
"# every other guy can do nothing\n" +
"User-agent: *\n" +
"Disallow: /\n"
);
final URI url = URI.create("http://foo.bor/goo/zoo.html"); // Disallowed
proxy.start();
HttpClient httpClient = FetchDataTest.getHttpClient(new HttpHost("localhost", proxy.port()), false);
FetchData fetchData = new FetchData(Helpers.getTestConfiguration(this));
fetchData.fetch(robotsURL, httpClient, null, null, true);
assertTrue(URLRespectsRobots.apply(URLRespectsRobots.parseRobotsResponse(fetchData, "goodGuy"), url));
assertTrue(URLRespectsRobots.apply(URLRespectsRobots.parseRobotsResponse(fetchData, "goodGuy foo"), url));
assertFalse(URLRespectsRobots.apply(URLRespectsRobots.parseRobotsResponse(fetchData, "badGuy"), url));
assertFalse(URLRespectsRobots.apply(URLRespectsRobots.parseRobotsResponse(fetchData, "badGuy foo"), url));
}
示例9: logFailedRequest
import org.apache.http.HttpHost; //導入依賴的package包/類
/**
* Logs a request that failed
*/
static void logFailedRequest(Log logger, HttpUriRequest request, HttpHost host, Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("request [" + request.getMethod() + " " + host + getUri(request.getRequestLine()) + "] failed", e);
}
if (tracer.isTraceEnabled()) {
String traceRequest;
try {
traceRequest = buildTraceRequest(request, host);
} catch (IOException e1) {
tracer.trace("error while reading request for trace purposes", e);
traceRequest = "";
}
tracer.trace(traceRequest);
}
}
示例10: builder
import org.apache.http.HttpHost; //導入依賴的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();
}
}
示例11: vertxProxyHosts
import org.apache.http.HttpHost; //導入依賴的package包/類
public static List<HttpHost> vertxProxyHosts() {
final List<String> hostStrings = Arrays.asList(proxyHostsString().split(","));
final int port = vertxProxyPort();
return hostStrings.stream()
.map(String::trim)
.filter(s -> !s.isEmpty())
.map(s -> new HttpHost(s, port))
.collect(Collectors.toList());
}
示例12: updateSecureConnection
import org.apache.http.HttpHost; //導入依賴的package包/類
public void updateSecureConnection(
final OperatedClientConnection conn,
final HttpHost target,
final HttpContext context,
final HttpParams params) throws IOException {
if (conn == null) {
throw new IllegalArgumentException("Connection may not be null");
}
if (target == null) {
throw new IllegalArgumentException("Target host may not be null");
}
if (params == null) {
throw new IllegalArgumentException("Parameters may not be null");
}
if (!conn.isOpen()) {
throw new IllegalStateException("Connection must be open");
}
final Scheme schm = schemeRegistry.getScheme(target.getSchemeName());
if (!(schm.getSchemeSocketFactory() instanceof SchemeLayeredSocketFactory)) {
throw new IllegalArgumentException
("Target scheme (" + schm.getName() +
") must have layered socket factory.");
}
SchemeLayeredSocketFactory lsf = (SchemeLayeredSocketFactory) schm.getSchemeSocketFactory();
Socket sock;
try {
sock = lsf.createLayeredSocket(
conn.getSocket(), target.getHostName(), target.getPort(), params);
} catch (ConnectException ex) {
throw new HttpHostConnectException(target, ex);
}
prepareSocket(sock, context, params);
conn.update(sock, target, lsf.isSecure(sock), params);
}
示例13: chooseProxy
import org.apache.http.HttpHost; //導入依賴的package包/類
/**
* Chooses a proxy from a list of available proxies.
* The default implementation just picks the first non-SOCKS proxy
* from the list. If there are only SOCKS proxies,
* {@link Proxy#NO_PROXY Proxy.NO_PROXY} is returned.
* Derived classes may implement more advanced strategies,
* such as proxy rotation if there are multiple options.
*
* @param proxies the list of proxies to choose from,
* never <code>null</code> or empty
* @param target the planned target, never <code>null</code>
* @param request the request to be sent, never <code>null</code>
* @param context the context, or <code>null</code>
*
* @return a proxy type
*/
protected Proxy chooseProxy(List<Proxy> proxies,
HttpHost target,
HttpRequest request,
HttpContext context) {
if ((proxies == null) || proxies.isEmpty()) {
throw new IllegalArgumentException
("Proxy list must not be empty.");
}
Proxy result = null;
// check the list for one we can use
for (int i=0; (result == null) && (i < proxies.size()); i++) {
Proxy p = proxies.get(i);
switch (p.type()) {
case DIRECT:
case HTTP:
result = p;
break;
case SOCKS:
// SOCKS hosts are not handled on the route level.
// The socket may make use of the SOCKS host though.
break;
}
}
if (result == null) {
//@@@ log as warning or info that only a socks proxy is available?
// result can only be null if all proxies are socks proxies
// socks proxies are not handled on the route planning level
result = Proxy.NO_PROXY;
}
return result;
}
示例14: createRequestConfigBuilder
import org.apache.http.HttpHost; //導入依賴的package包/類
public RequestConfig.Builder createRequestConfigBuilder(SiteConfig siteConfig, Request request, HttpHost proxy) {
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
requestConfigBuilder.setConnectTimeout(siteConfig.getConnectTimeout());
requestConfigBuilder.setSocketTimeout(siteConfig.getSocketTimeout());
requestConfigBuilder.setRedirectsEnabled(siteConfig.isRedirectsEnabled());
requestConfigBuilder.setConnectionRequestTimeout(siteConfig.getConnectionRequestTimeout());
requestConfigBuilder.setCircularRedirectsAllowed(siteConfig.isCircularRedirectsAllowed());
requestConfigBuilder.setMaxRedirects(siteConfig.getMaxRedirects());
requestConfigBuilder.setCookieSpec(siteConfig.getCookieSpec());
requestConfigBuilder.setProxy(proxy);
return requestConfigBuilder;
}
示例15: createHttpClient
import org.apache.http.HttpHost; //導入依賴的package包/類
/**
* 獲取Http客戶端連接對象
* @param timeOut 超時時間
* @param proxy 代理
* @param cookie Cookie
* @return Http客戶端連接對象
*/
public CloseableHttpClient createHttpClient(int timeOut,HttpHost proxy,BasicClientCookie cookie) {
// 創建Http請求配置參數
RequestConfig.Builder builder = RequestConfig.custom()
// 獲取連接超時時間
.setConnectionRequestTimeout(timeOut)
// 請求超時時間
.setConnectTimeout(timeOut)
// 響應超時時間
.setSocketTimeout(timeOut)
.setCookieSpec(CookieSpecs.STANDARD);
if (proxy!=null) {
builder.setProxy(proxy);
}
RequestConfig requestConfig = builder.build();
// 創建httpClient
HttpClientBuilder httpClientBuilder = HttpClients.custom();
httpClientBuilder
// 把請求相關的超時信息設置到連接客戶端
.setDefaultRequestConfig(requestConfig)
// 把請求重試設置到連接客戶端
.setRetryHandler(new RetryHandler())
// 配置連接池管理對象
.setConnectionManager(connManager);
if (cookie!=null) {
CookieStore cookieStore = new BasicCookieStore();
cookieStore.addCookie(cookie);
httpClientBuilder.setDefaultCookieStore(cookieStore);
}
return httpClientBuilder.build();
}