Hi !
I'm trying to implements my own 'cntlm' local proxy, my goal is to have a
centralized access for Java program, safari, and other, acessing to
internet thought the entreprise proxy.
Well, I'm using grizzly to listen http request, and httpclient to pass the
ntlm proxy, everything is ok for normal http connections.
But, when my browser have to access to https, this is another story. Well :
I have to implements the CONNECT method, so I'm using the following code :
HttpHost proxyHost = new HttpHost("proxy",8080);
HttpHost target = new HttpHost("mail.google.com",443);
Credentials credentials = new
UsernamePasswordCredentials("toto", "xb45");
ProxyClient proxyClient = new ProxyClient();
proxyClient.getAuthSchemeRegistry().register("ntlm", new
NTLMSchemeFactory());
Socket socket = proxyClient.tunnel(proxyHost, target,
credentials);
final InputStream in = httpRequest.getInputStream();
final OutputStream out = httpResponse.getOutputStream();
out.write(("HTTP/1.0 200 Connection
etablished \r\n\r\n").getBytes());
out.flush();
System.out.println("200 sended ");
Thread tread = new Thread(new Runnable() {
@Override
public void run() {
try {
System.out.println("read from socket");
int l = IOUtils.copy(secSocket.getInputStream(),
out);
System.out.println(" --> stop copy from socket
to out : " + l);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
});
Thread twrite = new Thread(new Runnable() {
@Override
public void run() {
try {
System.out.println("Write to socket");
int l = IOUtils.copy(in,
secSocket.getOutputStream());
System.out.println(" --> stop copy from in to
socket : " + l);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
});
tread.start();
twrite.start();
tread.join();
twrite.join();
Well, with this code, using wireshark, I can see that Proxyclient is
negociating well the NTLM session with the entreprise proxy, but my browser
hang...
I saw this type of code, making a simple bridge between socket and http
stream in a jetty proxy serlvet example, but this not working....
Anyone can help me ?