当前位置: 首页>>代码示例>>Java>>正文


Java HttpHost类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:DecompressingHttpClient.java

示例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;
}
 
开发者ID:Nordstrom,项目名称:Selenium-Foundation,代码行数:26,代码来源:GridUtility.java

示例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);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:AuthenticationStrategyImpl.java

示例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;
}
 
开发者ID:fengzhizi715,项目名称:ProxyPool,代码行数:20,代码来源:ProxyController.java

示例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);
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:21,代码来源:SdkTlsSocketFactory.java

示例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");

}
 
开发者ID:vy,项目名称:hrrs,代码行数:22,代码来源:ApacheHttpRequestRecordReplayer.java

示例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) {
        }
    }
}
 
开发者ID:StevenKin,项目名称:ZhihuQuestionsSpider,代码行数:17,代码来源:ProxyPool.java

示例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));
}
 
开发者ID:LAW-Unimi,项目名称:BUbiNG,代码行数:25,代码来源:URLRespectsRobotsTest.java

示例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);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:RequestLogger.java

示例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();
    }
}
 
开发者ID:ozankaraali,项目名称:InstaManager,代码行数:27,代码来源:Instaman.java

示例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());
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:11,代码来源:TestConfiguration.java

示例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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:37,代码来源:DefaultClientConnectionOperator.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:56,代码来源:ProxySelectorRoutePlanner.java

示例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;
}
 
开发者ID:brucezee,项目名称:jspider,代码行数:15,代码来源:HttpClientFactory.java

示例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();
}
 
开发者ID:fengzhizi715,项目名称:NetDiscovery,代码行数:45,代码来源:HttpManager.java


注:本文中的org.apache.http.HttpHost类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。