如何读取org.apache.http.impl.client.InternalHttpClient类型的httpComponentsClientHttpRequestFactory.getHttpClient()

时间:2018-11-26 12:53:58

标签: apache-httpclient-4.x

我们的代码:

OAuth2RestTemplate oauthClient = new OAuth2RestTemplate();
oauthClient.setRequestFactory(buildHttpRequestFactory());

buildHttpRequestFactory()方法:

HttpComponentsClientHttpRequestFactory buildHttpRequestFactory() throws 
                           KeyManagementException, NoSuchAlgorithmException, KeyStoreException, 
                           CertificateException, IOException {

HttpComponentsClientHttpRequestFactory requestFactory = new 
                              HttpComponentsClientHttpRequestFactory();

requestFactory.setHttpClient(buildHttpClient());

return requestFactory;
}

buildHttpClient()方法:

HttpClient buildHttpClient(){
httpClient = 
clientBuilder.setConnectionManager(buildConnectionManager())
            .disableCookieManagement()
            .build();
HttpClient httpClient = null;           

}

buildConnectionManager()方法:

buildConnectionManager(){
// returns BasicHttpClientConnectionManager with 
Registry<ConnectionSocketFactory> of http, https schemes
}

现在,在编写Junit来读取注册表以检查加载的配置时,

@Autowired
OAuth2RestTemplate oAuth2RestTemplate;

HttpComponentsClientHttpRequestFactory 
             httpComponentsClientHttpRequestFactory = 
(HttpComponentsClientHttpRequestFactory) oAuth2RestTemplate
        .getRequestFactory();

httpComponentsClientHttpRequestFactory.getHttpClient()的返回类型为InternalHttpClient。

因为InternalHttpClient类具有默认访问修饰符。因此无法获取httpComponentsClientHttpRequestFactory.getHttpClient()

的对象

如何读取类型为InternalHttpClient的httpComponentsClientHttpRequestFactory.getHttpClient()

我们正在使用4.5.6版本的httpclient

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>

0 个答案:

没有答案