最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

HttpClient HttpRoutePlanner接口確定請(qǐng)求目標(biāo)路由

 更新時(shí)間:2023年10月16日 09:30:31   作者:codecraft  
這篇文章主要為大家介紹了使用HttpClient HttpRoutePlanner接口確定請(qǐng)求目標(biāo)路由,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

本文主要研究一下HttpClient的HttpRoutePlanner

HttpRoutePlanner

org/apache/http/conn/routing/HttpRoutePlanner.java

/**
 * Encapsulates logic to compute a {@link HttpRoute} to a target host.
 * Implementations may for example be based on parameters, or on the
 * standard Java system properties.
 * <p>
 * Implementations of this interface must be thread-safe. Access to shared
 * data must be synchronized as methods of this interface may be executed
 * from multiple threads.
 * </p>
 *
 * @since 4.0
 */
public interface HttpRoutePlanner {

    /**
     * Determines the route for a request.
     *
     * @param target    the target host for the request.
     *                  Implementations may accept {@code null}
     *                  if they can still determine a route, for example
     *                  to a default target or by inspecting the request.
     * @param request   the request to execute
     * @param context   the context to use for the subsequent execution.
     *                  Implementations may accept {@code null}.
     *
     * @return  the route that the request should take
     *
     * @throws HttpException    in case of a problem
     */
    HttpRoute determineRoute(HttpHost target,
                                    HttpRequest request,
                                    HttpContext context) throws HttpException;

}
HttpRoutePlanner接口定義了determineRoute方法,用于決定該請(qǐng)求的目標(biāo)route

DefaultRoutePlanner

org/apache/http/impl/conn/DefaultRoutePlanner.java

/**
 * Default implementation of an {@link HttpRoutePlanner}. It will not make use of
 * any Java system properties, nor of system or browser proxy settings.
 *
 * @since 4.3
 */
@Contract(threading = ThreadingBehavior.IMMUTABLE_CONDITIONAL)
public class DefaultRoutePlanner implements HttpRoutePlanner {
    private final SchemePortResolver schemePortResolver;
    public DefaultRoutePlanner(final SchemePortResolver schemePortResolver) {
        super();
        this.schemePortResolver = schemePortResolver != null ? schemePortResolver :
            DefaultSchemePortResolver.INSTANCE;
    }
    @Override
    public HttpRoute determineRoute(
            final HttpHost host,
            final HttpRequest request,
            final HttpContext context) throws HttpException {
        Args.notNull(request, "Request");
        if (host == null) {
            throw new ProtocolException("Target host is not specified");
        }
        final HttpClientContext clientContext = HttpClientContext.adapt(context);
        final RequestConfig config = clientContext.getRequestConfig();
        final InetAddress local = config.getLocalAddress();
        HttpHost proxy = config.getProxy();
        if (proxy == null) {
            proxy = determineProxy(host, request, context);
        }
        final HttpHost target;
        if (host.getPort() <= 0) {
            try {
                target = new HttpHost(
                        host.getHostName(),
                        this.schemePortResolver.resolve(host),
                        host.getSchemeName());
            } catch (final UnsupportedSchemeException ex) {
                throw new HttpException(ex.getMessage());
            }
        } else {
            target = host;
        }
        final boolean secure = target.getSchemeName().equalsIgnoreCase("https");
        return proxy == null
                        ? new HttpRoute(target, local, secure)
                        : new HttpRoute(target, local, proxy, secure);
    }
    /**
     * This implementation returns null.
     *
     * @throws HttpException may be thrown if overridden
     */
    protected HttpHost determineProxy(
            final HttpHost target,
            final HttpRequest request,
            final HttpContext context) throws HttpException {
        return null;
    }
}
DefaultRoutePlanner實(shí)現(xiàn)了HttpRoutePlanner接口,其determineRoute方法在host的port小于等于0時(shí)通過(guò)schemePortResolver.resolve來(lái)確定port

SchemePortResolver

org/apache/http/conn/SchemePortResolver.java

/**
 * Strategy for default port resolution for protocol schemes.
 *
 * @since 4.3
 */
public interface SchemePortResolver {
    /**
     * Returns the actual port for the host based on the protocol scheme.
     */
    int resolve(HttpHost host) throws UnsupportedSchemeException;
}
SchemePortResolver接口定義了resolve方法,用于根據(jù)協(xié)議來(lái)返回真正的port

DefaultSchemePortResolver

org/apache/http/impl/conn/DefaultSchemePortResolver.java

@Contract(threading = ThreadingBehavior.IMMUTABLE)
public class DefaultSchemePortResolver implements SchemePortResolver {
    public static final DefaultSchemePortResolver INSTANCE = new DefaultSchemePortResolver();
    @Override
    public int resolve(final HttpHost host) throws UnsupportedSchemeException {
        Args.notNull(host, "HTTP host");
        final int port = host.getPort();
        if (port > 0) {
            return port;
        }
        final String name = host.getSchemeName();
        if (name.equalsIgnoreCase("http")) {
            return 80;
        } else if (name.equalsIgnoreCase("https")) {
            return 443;
        } else {
            throw new UnsupportedSchemeException(name + " protocol is not supported");
        }
    }
}
DefaultSchemePortResolver方法針對(duì)http返回80,針對(duì)https返回443,其他的拋出UnsupportedSchemeException

小結(jié)

HttpClient的HttpRoutePlanner接口定義了determineRoute方法,用于決定該請(qǐng)求的目標(biāo)route;

DefaultRoutePlanner實(shí)現(xiàn)了HttpRoutePlanner接口,其determineRoute方法在host的port小于等于0時(shí)通過(guò)schemePortResolver.resolve來(lái)確定port(http返回80,https返回443)。

以上就是HttpClient HttpRoutePlanner接口確定請(qǐng)求目標(biāo)路由的詳細(xì)內(nèi)容,更多關(guān)于HttpClient HttpRoutePlanner接口的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Java JDBC連接Kerberos認(rèn)證的HIVE和Impala方式

    Java JDBC連接Kerberos認(rèn)證的HIVE和Impala方式

    本文主要介紹了HiveJDBC和ImpalaJDBC的使用方法,包括版本對(duì)應(yīng)、Maven安裝、主機(jī)名配置、端口開通、JDBC連接和Kerberos認(rèn)證等
    2025-02-02
  • Spring框架中TaskExecutor類型Bean沖突導(dǎo)致的自動(dòng)注入失敗問(wèn)題的解決步驟

    Spring框架中TaskExecutor類型Bean沖突導(dǎo)致的自動(dòng)注入失敗問(wèn)題的解決步驟

    Spring中多個(gè)TaskExecutor Bean沖突導(dǎo)致注入失敗,本文給大家介紹的解決方案包括使用@Qualifier或@Primary明確注入目標(biāo)、重命名Bean、排除自動(dòng)配置,確保版本兼容以避免沖突,需要的朋友可以參考下
    2025-07-07
  • += 和 ++ 操作符區(qū)別簡(jiǎn)單介紹

    += 和 ++ 操作符區(qū)別簡(jiǎn)單介紹

    這篇文章主要介紹了+= 和 ++ 操作符區(qū)別簡(jiǎn)單介紹的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2016-09-09
  • Spring?boot框架JWT實(shí)現(xiàn)用戶賬戶密碼登錄驗(yàn)證流程

    Spring?boot框架JWT實(shí)現(xiàn)用戶賬戶密碼登錄驗(yàn)證流程

    這篇文章主要介紹了Springboot框架JWT實(shí)現(xiàn)用戶賬戶密碼登錄驗(yàn)證,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-06-06
  • Struts2 Result 參數(shù)詳解

    Struts2 Result 參數(shù)詳解

    這篇文章主要講解Struts2 Result的參數(shù),講的比較詳細(xì),希望能給大家做一個(gè)參考。
    2016-06-06
  • Flyway詳解及Springboot集成Flyway的詳細(xì)教程

    Flyway詳解及Springboot集成Flyway的詳細(xì)教程

    Flayway是一款數(shù)據(jù)庫(kù)版本控制管理工具,,支持?jǐn)?shù)據(jù)庫(kù)版本自動(dòng)升級(jí),Migrations可以寫成sql腳本,也可以寫在java代碼里。這篇文章主要介紹了Flyway詳解及Springboot集成Flyway的詳細(xì)教程的相關(guān)資料,需要的朋友可以參考下
    2020-07-07
  • MyBatis+MyBatisPlus中遇到的一些坑及解決

    MyBatis+MyBatisPlus中遇到的一些坑及解決

    這篇文章主要介紹了MyBatis+MyBatisPlus中遇到的一些坑及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • Java字符串與正則表達(dá)式操作方法詳解

    Java字符串與正則表達(dá)式操作方法詳解

    在Java編程中正則表達(dá)式是一個(gè)強(qiáng)大的工具,用于處理字符串和進(jìn)行模式匹配,這篇文章主要介紹了Java字符串與正則表達(dá)式操作的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2025-09-09
  • Spring Data Redis 中的 opsFor 方法深入解析

    Spring Data Redis 中的 opsFor 方法深入解析

    opsFor是RedisTemplate類中的一系列方法,用于獲取特定數(shù)據(jù)類型的操作接口,這些方法返回的是 Operations 對(duì)象,每個(gè)對(duì)象都提供了針對(duì)特定 Redis 數(shù)據(jù)類型的操作方法,本文重點(diǎn)介紹Spring Data Redis 中的opsFor方法,感興趣的朋友一起看看吧
    2025-12-12
  • 解讀@Data注解父子類繼承的問(wèn)題

    解讀@Data注解父子類繼承的問(wèn)題

    在Java開發(fā)中,使用Lombok庫(kù)的@Data注解簡(jiǎn)化了代碼,但在父子類繼承關(guān)系中使用@Data注解時(shí)會(huì)遇到問(wèn)題,主要問(wèn)題是:當(dāng)父類和子類都使用@Data注解時(shí),會(huì)導(dǎo)致equals方法不對(duì)稱,解決方案是在子類中使用@EqualsAndHashCode注解
    2024-11-11

最新評(píng)論

东城区| 承德市| 东丽区| 遂平县| 湟中县| 牙克石市| 庆云县| 信丰县| 宜黄县| 广南县| 宜昌市| 大洼县| 株洲市| 成武县| 邓州市| 盱眙县| 浦东新区| 密云县| 黄平县| 砀山县| 同江市| 长岛县| 马关县| 怀来县| 成安县| 贺州市| 泗洪县| 阿拉尔市| 湄潭县| 辽宁省| 柳州市| 大化| 黄梅县| 宁蒗| 尉氏县| 乃东县| 商城县| 岗巴县| 霸州市| 乐安县| 洛川县|