My solution is this here:
public class PreemptiveNTLMHeader implements Header {
private HttpRequest request;
private NTCredentials ntc;
public PreemptiveNTLMHeader(HttpRequest request, NTCredentials ntc) {
this.request = request;
this.ntc = ntc;
}
/* (non-Javadoc)
* @see org.apache.http.Header#getName()
*/
public String getName() {
return "Authorization";
}
/* (non-Javadoc)
* @see org.apache.http.Header#getValue()
*/
public String getValue() {
request.removeHeader(this);
try {
return "NTLM " + new JCIFSEngine().generateType1Msg(ntc.getDomain(), ntc.getWorkstation());
} catch(NTLMEngineException e) {
return "Failed";
}
}
/* (non-Javadoc)
* @see org.apache.http.Header#getElements()
*/
public HeaderElement[] getElements() throws ParseException {
return null;
}
}
With this usage:
NTCredentials ntc = new NTCredentials("example.com/user:password");
httpPost.addHeader(new PreemptiveNTLMHeader(httpPost, ntc));
So will the DefaultHttpClient send a Authorization: NTLM AAA...
header which skips the initial request. After the first usage of this header this header deletes itself to avoid that this dummy header overrides the real auth process. This works for me.