jira-importer opened a new issue, #967:
URL: https://github.com/apache/httpcomponents-client/issues/967

   
**[Kelvin](https://issues.apache.org/jira/secure/[email protected])**
 opened 
**[HTTPCLIENT-2](https://issues.apache.org/jira/browse/HTTPCLIENT-2?redirect=false)**
 and commented
   
   Hi there,
   
   I am using httpclient 2.0 alpha 1.0 and having problem to connect to Web 
server
   with https.
   
   Problem 1. Failed to connect to web server with https.
   
   ---
   
   http client hang for couple minutes and throw exceptions...
   java.net.SocketException: Socket closed
   at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a([DashoPro-V1.2-120198])
   at com.sun.net.ssl.internal.ssl.AppOutputStream.write([DashoPro-V1.2-120
   198])
   at java.io.OutputStream.write(OutputStream.java:65)
   at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake([DashoPro-V
   1.2-120198])
   at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java
   :296)
   at TestEGate.init(TestEGate.java:27)
   at TestEGate.main(TestEGate.java:18)
   
   I follow the suggestion from the example in JSSE 1.02
   SSLSocketClientWithTunneling.java. First of all, I create socket to do
   tunneling through the proxy and then layer SSL over the top of it. It works
   after the change. The function doTunnelHandshake() can be found in
   SSLSocketClientWithTunneling.java. (Notice, I used DummySSLSockeyFactory
   because of the website certificate which I connected to was expired.)
   
   Here is the modified open method in HttpConnection
   
       public void open() throws IOException {
           log.debug("HttpConnection.open()");
           assertNotOpen(); // ??? is this worth doing?
           try {
               if(null == _socket) {
                   if(null == _proxyHost || 0 >= _proxyPort) {
                       if(_ssl) {
                           _socket = SSLSocketFactory.getDefault().createSocket
   
   (_host,_port);
   } else {
   _socket = new Socket(_host,_port);
   }
   } else {
   if(_ssl) {
   SSLSocketFactory factory =
   (SSLSocketFactory)DummySSLSocketFactory.getDefault();
   Socket tunnel = new Socket(_proxyHost,_proxyPort);
   doTunnelHandshake (tunnel,_host,_port);
   System.out.println ("do Tunnel OK");
   _socket =
   (SSLSocket)factory.createSocket(tunnel, _host, _port, true);
   ((SSLSocket)_socket).startHandshake();
   
                       } else {
                           _socket = new Socket(_proxyHost,_proxyPort);
                       }
                   }
               }
               _input = _socket.getInputStream();
               _output = _socket.getOutputStream();
               _open = true;
           } catch (IOException e) {
               // Connection wasn't opened properly
               // so close everything out
               closeSocketAndStreams();
               throw e;
           }
       }
   
   Problem 2: Got 501 network not support when connected to some websites using
   https
   
   message dump
   
   ---
   
   DummySocketFactory instantiated
   do Tunnel OK
   get login page
   request line:GET https://www.egate.com.au/merchants/login.asp HTTP/1.1
   
   \<html>\<head>\<title>Error\</title>\</head>\<body>The network request is 
not supporte
   d. \</body>\</html>
   code:501
   text:Not Supported
   
   However, if I change the request line to GET /merchants/login.asp HTTP/1.1
   It works.
   
   Is there a bug in isProxied() method of HttpConnection class and
   generateRequestLine() method of HttpMethodBase class???
   
       public boolean isProxied() {
           return (!(null == _proxyHost || 0 >= _proxyPort));
       }
       
       protected static String generateRequestLine(HttpConnection connection, 
   
   String name, String reqPath, String qString, String protocol) {
   
       if(!connection.isProxied()) {
           return (name + " " + buf.toString() + " " + protocol + "\r\n");
       } else {
           if(connection.isSecure()) {
   
   
   
   ---
   No further details from 
[HTTPCLIENT-2](https://issues.apache.org/jira/browse/HTTPCLIENT-2?redirect=false)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to