单元测试apache http客户端代理407

单元测试apache http客户端代理407,apache,junit4,apache-httpclient-4.x,http-proxy,Apache,Junit4,Apache Httpclient 4.x,Http Proxy,我正在尝试构建一个Junit/Integration测试,它需要联系外部服务器。但是,我无法通过代理。我得到一个407空白身份验证页错误 我使用的测试设置 @Before public void onSetUp() throws Exception { System.setProperty("http.proxyHost", "webproxy-nl.test.com"); System.setProperty("http.proxyPort", "8080"); Sy

我正在尝试构建一个Junit/Integration测试,它需要联系外部服务器。但是,我无法通过代理。我得到一个407空白身份验证页错误

我使用的测试设置

@Before
public void onSetUp() throws Exception {

    System.setProperty("http.proxyHost", "webproxy-nl.test.com");
    System.setProperty("http.proxyPort", "8080");
    System.setProperty("https.proxyHost", "webproxy-nl.test.com");
    System.setProperty("https.proxyPort", "8080");

    System.setProperty("http.proxyUser", "DOM\\lalal");
    System.setProperty("http.proxyPassword", "tesssst");

    System.setProperty("https.proxyUser", "DOM\\lalala");
    System.setProperty("https.proxyPassword", "sldjsdkl");
}
现在,所有代理设置都100%正确。我还添加了一些非ProxyHosts

我不知道我还能在这里配置什么

返回信息为:

Http request failed: HTTP/1.1 407 BlankAuthenticationPage [status code 407]
更新

我构建了一个使用CloseableHttpClient的测试存根。这仍然给了我HTTP407错误

private CloseableHttpClient httpClient;

public IDealHttpClientStub() {

    LOG.debug("Creating IDealHttpClientStub");

    System.setProperty("http.proxyHost", "webproxy-nl.test.com");
    System.setProperty("http.proxyPort", "8080");
    System.setProperty("https.proxyHost", "webproxy-nl.test.com");
    System.setProperty("https.proxyPort", "8080");

    System.setProperty("http.proxyUser", "DOM\\lalal");
    System.setProperty("http.proxyPassword", "tesssst");

    System.setProperty("https.proxyUser", "DOM\\lalala");
    System.setProperty("https.proxyPassword", "sldjsdkl");

    this.httpClient = HttpClients.custom().useSystemProperties().build();
}

除非明确配置为使用系统属性,否则HttpClient不会使用系统属性

CloseableHttpClient client1 = HttpClients.createSystem();
CloseableHttpClient client2 = HttpClients.custom()
        .useSystemProperties()
        .build();

我已经使用以下impl完成了它

private CloseableHttpClient httpClient;

public HttpClientStub() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {

    // Trust all certs
    SSLContext sslcontext = buildSSLContext();

    // Allow TLSv1 protocol only
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null,
            SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

    HttpHost proxy = new HttpHost("someproxy", 8080, "http");
    DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);

    CredentialsProvider credsProvider = new BasicCredentialsProvider();

    credsProvider.setCredentials(
            new AuthScope("someproxy", 8080, AuthScope.ANY_HOST, "ntlm"), new NTCredentials(
                    "itsme", "xxxx", "", "MYDOMAIN"));

    this.httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider)
            .setRoutePlanner(routePlanner).setSSLSocketFactory(sslsf).build();

}

private static SSLContext buildSSLContext() throws NoSuchAlgorithmException, KeyManagementException,
        KeyStoreException {
    SSLContext sslcontext = SSLContexts.custom().setSecureRandom(new SecureRandom())
            .loadTrustMaterial(null, new TrustStrategy() {

                @Override
                public boolean isTrusted(java.security.cert.X509Certificate[] chain, String authType)
                        throws java.security.cert.CertificateException {                        
                    return true;
                }
            }).build();
    return sslcontext;
}

然后您将代理配置为HTTP(测试)客户端。

这不起作用。我围绕CloseableHttpClient构建了测试。仍然得到相同的407错误。请看我更新的问题,原因可能有很多。服务器已配置为支持哪些身份验证方案?HC选择什么方案进行身份验证?是NTLM吗?看起来creds包含一个NT域。