_logger.severe("Error layering SSL over the existing socket"); ioe.printStackTrace(); throw new SocketException("Error layering SSL over the socket " + ioe);
_logger.severe("Error layering SSL over the existing socket: " + ioe); throw ioe;
    private Socket opensocket(URL url, String proxyAuth) throws IOException {        // We initialise to null;        Socket socket = null;        _direct = true;                // We record where we are connected to, in case we might reuse this socket later        _host = url.getHost();        _port = url.getPort()==-1?url.getDefaultPort():url.getPort();        boolean ssl = url.getProtocol().equalsIgnoreCase("https");                if (useProxy(url)) {            if (!ssl) {                _logger.fine("Connect to " + _httpProxy + ":" + _httpProxyPort);                if (!_debug) {                    socket = new Socket(_httpProxy, _httpProxyPort);                    socket.setTcpNoDelay(true);                    socket.setSoTimeout(60 * 1000);                }                _direct = false;                return socket;            } else {                // Send CONNECT, get OK, then we have a socket to the server                // _logger.fine("Connect to " + _httpsProxy + ":" + _httpsProxyPort);                if (!_debug) {                    // _logger.fine("Proxy CONNECT to " + _host + ":" + _port);                    socket = new Socket(_httpsProxy, _httpsProxyPort);                    _in = socket.getInputStream();                    _out = socket.getOutputStream();                    if (_serverInput != null) {                        _in = new LogInputStream(_in, new PrintStream(_serverInput, true));                    }                    if (_serverOutput != null) {                        _out = new LogOutputStream(_out, new PrintStream(_serverOutput, true));                    }                }                if (_out != null) {                    _out.write(("CONNECT " + _host + ":" + _port + " HTTP/1.0\r\n").getBytes());                    if (proxyAuth != null && !proxyAuth.equals("")) {                        _out.write(("Proxy-Authorization: " + proxyAuth + "\r\n").getBytes());                    }                    _out.write("\r\n".getBytes());                    _out.flush();                    _logger.fine("Sent CONNECT, reading Proxy response");                }                Response response = new Response();                response.read(_in);                _logger.fine("Got proxy response " + response.getStatusLine());                if (!response.getStatus().equals("200")) {                    _response = response;                    return null;                }                _logger.fine("HTTPS CONNECT successful");            }        } else {            if (!_debug) {                _logger.fine("Connect to " + _host + ":" + _port );                socket = new Socket(_host, _port);                socket.setTcpNoDelay(true);                socket.setSoTimeout(60 * 1000);            }        }                if (!_debug && ssl && socket != null) {            if (_factory == null) {                try {                    initSSL();                } catch (Exception e) {                    throw new IOException(e.toString());                }            }            // Use the factory to create a secure socket connected to the            // HTTPS port of the specified web server.            try {                SSLSocket sslsocket=(SSLSocket)_factory.createSocket(socket,socket.getInetAddress().getHostName(),socket.getPort(),true);                sslsocket.setUseClientMode(true);                socket = sslsocket;            } catch (IOException ioe) {                _logger.severe("Error layering SSL over the existing socket");                ioe.printStackTrace();                throw new SocketException("Error layering SSL over the socket " + ioe);            }            _logger.fine("Finished negotiating SSL");        }        return socket;    }