Folks:

I'm struggling with a problem with HttpClient 4.1.1 ... I'm trying to connect 
to a web site that requires basic authentication ... through a proxy (Squid) 
that requires NTLM authentication.

The error that's getting logged is 'Proxy authentication error: Unexpected 
state: MSG_TYPE3_GENERATED'.

I'm not dismissing the possibility that my code isn't correct, but it seems 
pretty straight forward.

I did find this issue, but it appears to apply to an older version of 
httpclient: https://issues.apache.org/jira/browse/HTTPCLIENT-856

Any suggestions?

Thanks!

Here is the code I'm using to connect to the site ...


----------
    private void execute() throws HttpException, IOException {
        
        System.setProperty("org.apache.commons.logging.Log", 
"org.apache.commons.logging.impl.SimpleLog");
        System.setProperty("org.apache.commons.logging.simplelog.showdatetime", 
"true");
        
System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire.header",
 "debug");
        
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient",
 "debug");

        URL targetUrl = new URL(TARGET_URL);
        
        DefaultHttpClient httpclient = new DefaultHttpClient();

        HttpHost targetHost = new HttpHost(targetUrl.getHost()); 
        HttpHost proxyHost = new HttpHost(PROXY_HOST, PROXY_PORT); 
        
        httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, 
                        proxyHost);

        CredentialsProvider credProvider = httpclient.getCredentialsProvider();
        
        Credentials proxyCredentials = new NTCredentials(PROXY_USER, 
                        PROXY_PASSWORD, PROXY_MACHINE, PROXY_DOMAIN);
        
        credProvider.setCredentials(new AuthScope(proxyHost.getHostName(),
                        proxyHost.getPort()), proxyCredentials);
        
        Credentials targetCredentials = new UsernamePasswordCredentials(
                        TARGET_USER, TARGET_PASSWORD);
        
        credProvider.setCredentials(new AuthScope(targetHost.getHostName(),
                        targetHost.getPort()), targetCredentials);
      
        HttpGet httpget = new HttpGet(targetUrl.getPath());

        HttpResponse response = httpclient.execute(targetHost, httpget);
        
        System.out.println("response = " + response);
----------

And here are the logs that are being generated ...

2011/05/13 07:57:39:656 CDT [DEBUG] SingleClientConnManager - Get connection 
for route HttpRoute[{}->http://testproxy:3128->http://www.example.com]
2011/05/13 07:57:39:671 CDT [DEBUG] DefaultClientConnectionOperator - 
Connecting to testproxy/10.17.8.61:3128
2011/05/13 07:57:39:687 CDT [DEBUG] RequestAddCookies - CookieSpec selected: 
best-match
2011/05/13 07:57:39:702 CDT [DEBUG] RequestAuthCache - Auth cache not set in 
the context
2011/05/13 07:57:39:702 CDT [DEBUG] DefaultHttpClient - Attempt 1 to execute 
request
2011/05/13 07:57:39:702 CDT [DEBUG] DefaultClientConnection - Sending request: 
GET http://www.example.com/somedir/verify.txt HTTP/1.1
2011/05/13 07:57:39:718 CDT [DEBUG] headers - >> GET 
http://www.example.com/somedir/verify.txt HTTP/1.1
2011/05/13 07:57:39:718 CDT [DEBUG] headers - >> Host: www.example.com
2011/05/13 07:57:39:718 CDT [DEBUG] headers - >> Proxy-Connection: Keep-Alive
2011/05/13 07:57:39:718 CDT [DEBUG] headers - >> User-Agent: 
Apache-HttpClient/4.1.1 (java 1.5)
2011/05/13 07:57:39:718 CDT [DEBUG] DefaultClientConnection - Receiving 
response: HTTP/1.0 407 Proxy Authentication Required
2011/05/13 07:57:39:718 CDT [DEBUG] headers - << HTTP/1.0 407 Proxy 
Authentication Required
2011/05/13 07:57:39:718 CDT [DEBUG] headers - << Server: squid/2.7.STABLE8
2011/05/13 07:57:39:718 CDT [DEBUG] headers - << Date: Fri, 13 May 2011 
12:57:39 GMT
2011/05/13 07:57:39:718 CDT [DEBUG] headers - << Content-Type: text/html
2011/05/13 07:57:39:718 CDT [DEBUG] headers - << Content-Length: 1465
2011/05/13 07:57:39:718 CDT [DEBUG] headers - << X-Squid-Error: 
ERR_CACHE_ACCESS_DENIED 0
2011/05/13 07:57:39:718 CDT [DEBUG] headers - << Proxy-Authenticate: NTLM
2011/05/13 07:57:39:718 CDT [DEBUG] headers - << X-Cache: MISS from 
testproxy.example.com
2011/05/13 07:57:39:718 CDT [DEBUG] headers - << X-Cache-Lookup: NONE from 
testproxy.example.com:3128
2011/05/13 07:57:39:718 CDT [DEBUG] headers - << Via: 1.0 
testproxy.example.com:3128 (squid/2.7.STABLE8)
2011/05/13 07:57:39:718 CDT [DEBUG] headers - << Connection: close
2011/05/13 07:57:39:718 CDT [DEBUG] DefaultHttpClient - Proxy requested 
authentication
2011/05/13 07:57:39:718 CDT [DEBUG] DefaultProxyAuthenticationHandler - 
Authentication schemes in the order of preference: [negotiate, NTLM, Digest, 
Basic]
2011/05/13 07:57:39:718 CDT [DEBUG] DefaultProxyAuthenticationHandler - 
Challenge for negotiate authentication scheme not available
2011/05/13 07:57:39:718 CDT [DEBUG] DefaultProxyAuthenticationHandler - NTLM 
authentication scheme selected
2011/05/13 07:57:39:734 CDT [DEBUG] DefaultHttpClient - Authorization challenge 
processed
2011/05/13 07:57:39:734 CDT [DEBUG] DefaultHttpClient - Authentication scope: 
NTLM <any realm>@testproxy:3128
2011/05/13 07:57:39:734 CDT [DEBUG] DefaultHttpClient - Found credentials
2011/05/13 07:57:39:734 CDT [DEBUG] DefaultClientConnection - Connection closed
2011/05/13 07:57:39:734 CDT [DEBUG] DefaultClientConnectionOperator - 
Connecting to testproxy/10.17.8.61:3128
2011/05/13 07:57:39:734 CDT [DEBUG] RequestAddCookies - CookieSpec selected: 
best-match
2011/05/13 07:57:39:734 CDT [DEBUG] RequestAuthCache - Auth cache not set in 
the context
2011/05/13 07:57:39:734 CDT [DEBUG] DefaultHttpClient - Attempt 2 to execute 
request
2011/05/13 07:57:39:734 CDT [DEBUG] DefaultClientConnection - Sending request: 
GET http://www.example.com/somedir/verify.txt HTTP/1.1
2011/05/13 07:57:39:734 CDT [DEBUG] headers - >> GET 
http://www.example.com/somedir/verify.txt HTTP/1.1
2011/05/13 07:57:39:734 CDT [DEBUG] headers - >> Host: www.example.com
2011/05/13 07:57:39:734 CDT [DEBUG] headers - >> Proxy-Connection: Keep-Alive
2011/05/13 07:57:39:734 CDT [DEBUG] headers - >> User-Agent: 
Apache-HttpClient/4.1.1 (java 1.5)
2011/05/13 07:57:39:734 CDT [DEBUG] headers - >> Proxy-Authorization: NTLM 
TlRMTVNTUAABAAAANQIIIAYABgA0AAAAFAAUACAAAABJAEwARABHAEkAQgBCAFMAVwA3AE0ASwBTAA==
2011/05/13 07:57:39:749 CDT [DEBUG] DefaultClientConnection - Receiving 
response: HTTP/1.0 407 Proxy Authentication Required
2011/05/13 07:57:39:749 CDT [DEBUG] headers - << HTTP/1.0 407 Proxy 
Authentication Required
2011/05/13 07:57:39:749 CDT [DEBUG] headers - << Server: squid/2.7.STABLE8
2011/05/13 07:57:39:749 CDT [DEBUG] headers - << Date: Fri, 13 May 2011 
12:57:39 GMT
2011/05/13 07:57:39:749 CDT [DEBUG] headers - << Content-Type: text/html
2011/05/13 07:57:39:749 CDT [DEBUG] headers - << Content-Length: 1465
2011/05/13 07:57:39:749 CDT [DEBUG] headers - << X-Squid-Error: 
ERR_CACHE_ACCESS_DENIED 0
2011/05/13 07:57:39:749 CDT [DEBUG] headers - << Proxy-Authenticate: NTLM 
TlRMTVNTUAACAAAABgAGADgAAAA1Aoki1QXgTwJlb48AAAAAAAAAAHYAdgA+AAAABQEoCgAAAA9NAEsAUwACAAYATQBLAFMAAQAWAEkATABOAFQARABFAFYAUwBFAFIAVgAEAA4AbQBrAHMALgBjAG8AbQADACYAaQBsAG4AdABkAGUAdgBzAGUAcgB2AC4AbQBrAHMALgBjAG8AbQAFAA4AbQBrAHMALgBjAG8AbQAAAAAA
2011/05/13 07:57:39:749 CDT [DEBUG] headers - << X-Cache: MISS from 
testproxy.example.com
2011/05/13 07:57:39:749 CDT [DEBUG] headers - << X-Cache-Lookup: NONE from 
testproxy.example.com:3128
2011/05/13 07:57:39:749 CDT [DEBUG] headers - << Via: 1.0 
testproxy.example.com:3128 (squid/2.7.STABLE8)
2011/05/13 07:57:39:749 CDT [DEBUG] headers - << Connection: keep-alive
2011/05/13 07:57:39:749 CDT [DEBUG] headers - << Proxy-Connection: keep-alive
2011/05/13 07:57:39:749 CDT [DEBUG] DefaultHttpClient - Connection can be kept 
alive indefinitely
2011/05/13 07:57:39:749 CDT [DEBUG] DefaultHttpClient - Proxy requested 
authentication
2011/05/13 07:57:39:749 CDT [DEBUG] DefaultHttpClient - Authorization challenge 
processed
2011/05/13 07:57:39:749 CDT [DEBUG] DefaultHttpClient - Authentication scope: 
NTLM <any realm>@testproxy:3128
2011/05/13 07:57:39:749 CDT [DEBUG] RequestAddCookies - CookieSpec selected: 
best-match
2011/05/13 07:57:39:749 CDT [DEBUG] RequestAuthCache - Auth cache not set in 
the context
2011/05/13 07:57:39:765 CDT [DEBUG] DefaultHttpClient - Attempt 3 to execute 
request
2011/05/13 07:57:39:765 CDT [DEBUG] DefaultClientConnection - Sending request: 
GET http://www.example.com/somedir/verify.txt HTTP/1.1
2011/05/13 07:57:39:765 CDT [DEBUG] headers - >> GET 
http://www.example.com/somedir/verify.txt HTTP/1.1
2011/05/13 07:57:39:765 CDT [DEBUG] headers - >> Host: www.example.com
2011/05/13 07:57:39:765 CDT [DEBUG] headers - >> Proxy-Connection: Keep-Alive
2011/05/13 07:57:39:765 CDT [DEBUG] headers - >> User-Agent: 
Apache-HttpClient/4.1.1 (java 1.5)
2011/05/13 07:57:39:765 CDT [DEBUG] headers - >> Proxy-Authorization: NTLM 
TlRMTVNTUAADAAAAGAAYAEAAAACiAKIAWAAAAAYABgD6AAAADAAMAAABAAAUABQADAEAAAAAAAAgAQAANQIIINwMX0rhp/Cg5d4HJs8gkWrKathFlkMf8/aSdHa7WpFa774Q1XhUPPsBAQAAAAAAAFDeHldtEcwBymrYRZZDH/MAAAAAAgAGAE0ASwBTAAEAFgBJAEwATgBUAEQARQBWAFMARQBSAFYABAAOAG0AawBzAC4AYwBvAG0AAwAmAGkAbABuAHQAZABlAHYAcwBlAHIAdgAuAG0AawBzAC4AYwBvAG0ABQAOAG0AawBzAC4AYwBvAG0AAAAAAE0ASwBTAGQAZQB2AGQAbQBnAEkATABEAEcASQBCAEIAUwBXADcA
2011/05/13 07:57:39:858 CDT [DEBUG] DefaultClientConnection - Receiving 
response: HTTP/1.0 401 Unauthorized
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << HTTP/1.0 401 Unauthorized
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << Date: Fri, 13 May 2011 
12:57:39 GMT
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << Pragma: No-cache
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << Cache-Control: no-cache
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << Expires: Wed, 31 Dec 1969 
19:00:00 EST
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << WWW-Authenticate: Basic 
realm="Target Realm "
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << Content-Type: 
text/html;charset=utf-8
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << Content-Length: 954
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << X-Cache: MISS from 
testproxy.example.com
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << X-Cache-Lookup: MISS from 
testproxy.example.com:3128
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << Via: 1.1 
testproxy.example.com:3128 (squid/2.7.STABLE8)
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << Connection: close
2011/05/13 07:57:39:858 CDT [DEBUG] DefaultHttpClient - Target requested 
authentication
2011/05/13 07:57:39:858 CDT [DEBUG] DefaultTargetAuthenticationHandler - 
Authentication schemes in the order of preference: [negotiate, NTLM, Digest, 
Basic]
2011/05/13 07:57:39:858 CDT [DEBUG] DefaultTargetAuthenticationHandler - 
Challenge for negotiate authentication scheme not available
2011/05/13 07:57:39:858 CDT [DEBUG] DefaultTargetAuthenticationHandler - 
Challenge for NTLM authentication scheme not available
2011/05/13 07:57:39:858 CDT [DEBUG] DefaultTargetAuthenticationHandler - 
Challenge for Digest authentication scheme not available
2011/05/13 07:57:39:858 CDT [DEBUG] DefaultTargetAuthenticationHandler - Basic 
authentication scheme selected
2011/05/13 07:57:39:858 CDT [DEBUG] DefaultHttpClient - Authorization challenge 
processed
2011/05/13 07:57:39:858 CDT [DEBUG] DefaultHttpClient - Authentication scope: 
BASIC 'Target Realm'@www.example.com:80
2011/05/13 07:57:39:858 CDT [DEBUG] DefaultHttpClient - Found credentials
2011/05/13 07:57:39:858 CDT [DEBUG] DefaultClientConnection - Connection closed
2011/05/13 07:57:39:858 CDT [DEBUG] DefaultClientConnectionOperator - 
Connecting to testproxy/10.17.8.61:3128
2011/05/13 07:57:39:858 CDT [DEBUG] RequestAddCookies - CookieSpec selected: 
best-match
2011/05/13 07:57:39:858 CDT [DEBUG] RequestAuthCache - Auth cache not set in 
the context
2011/05/13 07:57:39:858 CDT [ERROR] RequestProxyAuthentication - Proxy 
authentication error: Unexpected state: MSG_TYPE3_GENERATED
2011/05/13 07:57:39:858 CDT [DEBUG] DefaultHttpClient - Attempt 4 to execute 
request
2011/05/13 07:57:39:858 CDT [DEBUG] DefaultClientConnection - Sending request: 
GET http://www.example.com/somedir/verify.txt HTTP/1.1
2011/05/13 07:57:39:858 CDT [DEBUG] headers - >> GET 
http://www.example.com/somedir/verify.txt HTTP/1.1
2011/05/13 07:57:39:858 CDT [DEBUG] headers - >> Host: www.example.com
2011/05/13 07:57:39:858 CDT [DEBUG] headers - >> Proxy-Connection: Keep-Alive
2011/05/13 07:57:39:858 CDT [DEBUG] headers - >> User-Agent: 
Apache-HttpClient/4.1.1 (java 1.5)
2011/05/13 07:57:39:858 CDT [DEBUG] headers - >> Authorization: Basic 
ZGdpYmJzQG1rcy5jb206cmVkMXdhc2g=
2011/05/13 07:57:39:858 CDT [DEBUG] DefaultClientConnection - Receiving 
response: HTTP/1.0 407 Proxy Authentication Required
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << HTTP/1.0 407 Proxy 
Authentication Required
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << Server: squid/2.7.STABLE8
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << Date: Fri, 13 May 2011 
12:57:39 GMT
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << Content-Type: text/html
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << Content-Length: 1465
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << X-Squid-Error: 
ERR_CACHE_ACCESS_DENIED 0
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << Proxy-Authenticate: NTLM
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << X-Cache: MISS from 
testproxy.example.com
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << X-Cache-Lookup: NONE from 
testproxy.example.com:3128
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << Via: 1.0 
testproxy.example.com:3128 (squid/2.7.STABLE8)
2011/05/13 07:57:39:858 CDT [DEBUG] headers - << Connection: close
2011/05/13 07:57:39:874 CDT [DEBUG] ResponseAuthCache - Caching 'basic' auth 
scheme for http://www.example.com
2011/05/13 07:57:39:874 CDT [DEBUG] DefaultHttpClient - Proxy requested 
authentication
2011/05/13 07:57:39:874 CDT [DEBUG] DefaultHttpClient - Authorization challenge 
processed
2011/05/13 07:57:39:874 CDT [DEBUG] DefaultHttpClient - Authentication scope: 
NTLM <any realm>@testproxy:3128
2011/05/13 07:57:39:874 CDT [DEBUG] DefaultHttpClient - Authentication failed
response = HTTP/1.0 407 Proxy Authentication Required [Server: 
squid/2.7.STABLE8, Date: Fri, 13 May 2011 12:57:39 GMT, Content-Type: 
text/html, Content-Length: 1465, X-Squid-Error: ERR_CACHE_ACCESS_DENIED 0, 
Proxy-Authenticate: NTLM, X-Cache: MISS from testproxy.example.com, 
X-Cache-Lookup: NONE from testproxy.example.com:3128, Via: 1.0 
testproxy.example.com:3128 (squid/2.7.STABLE8), Connection: close]

-- 
David Gibbs
Sr. Software Engineer
MKS Software, Inc. http://www.mks.com
Oakbrook Terrace, IL   60181
Phone: 630-827-4900 x5004
Email: [email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to