snichol 2002/10/18 13:30:54 Modified: java/src/org/apache/soap/util/net HTTPUtils.java SSLUtils.java Log: Allow proxyUserName and proxyPassword to be used for SSL connection as well as straight HTTP. Move all auth string manipulation out of SSLUtils. Thanks to Mike Ladwig ([EMAIL PROTECTED]) for testing this change. Revision Changes Path 1.35 +11 -4 xml-soap/java/src/org/apache/soap/util/net/HTTPUtils.java Index: HTTPUtils.java =================================================================== RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/util/net/HTTPUtils.java,v retrieving revision 1.34 retrieving revision 1.35 diff -u -r1.34 -r1.35 --- HTTPUtils.java 16 Oct 2002 04:16:15 -0000 1.34 +++ HTTPUtils.java 18 Oct 2002 20:30:54 -0000 1.35 @@ -118,6 +118,7 @@ Hashtable headers, Boolean tcpNoDelay) throws Exception { + String proxyAuth = null; if (httpProxyHost == null) { String proxyHost = System.getProperty("https.proxyHost"); String nonProxyHosts = System.getProperty("https.nonProxyHosts"); @@ -126,21 +127,27 @@ // use proxy from system values httpProxyHost = proxyHost; httpProxyPort = Integer.getInteger("https.proxyPort", HTTPS_DEFAULT_PORT).intValue(); - // TODO: build authentication string here instead of SSLUtils, - // but into headers, and pass headers to SSLUtils. } } + if (httpProxyHost != null) { + proxyAuth = (String) headers.get(Constants.HEADER_PROXY_AUTHORIZATION); + if (proxyAuth == null) + proxyAuth = System.getProperty("https.proxyAuth"); + else + headers.remove(Constants.HEADER_PROXY_AUTHORIZATION); + } + // Using reflection to avoid compile time dependencies Class SSLUtilsClass = Class.forName("org.apache.soap.util.net.SSLUtils"); Class[] paramTypes = new Class[] {String.class, int.class, String.class, int.class, - Boolean.class}; + String.class, Boolean.class}; Method buildSSLSocket = SSLUtilsClass.getMethod("buildSSLSocket", paramTypes); Object[] params = new Object[] {host, new Integer(port), httpProxyHost, new Integer(httpProxyPort), - tcpNoDelay}; + proxyAuth, tcpNoDelay}; try { return (Socket) buildSSLSocket.invoke(null, params); 1.8 +29 -15 xml-soap/java/src/org/apache/soap/util/net/SSLUtils.java Index: SSLUtils.java =================================================================== RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/util/net/SSLUtils.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- SSLUtils.java 4 Oct 2002 19:50:19 -0000 1.7 +++ SSLUtils.java 18 Oct 2002 20:30:54 -0000 1.8 @@ -90,7 +90,7 @@ return buildSSLSocket(host, port, tunnelHost, tunnelPort, - null); + null, null); } /** @@ -109,6 +109,28 @@ Boolean tcpNoDelay) throws IOException, UnknownHostException { + return buildSSLSocket(host, port, + tunnelHost, tunnelPort, + null, null); + } + + /** + * Builds an SSL socket, after auto-starting SSL. + * + * @param host The host to which to connect. + * @param port The port to which to connect. + * @param tunnelHost The host to which to tunnel through. + * @param tunnelPort The port to which to tunnel through. + * @param tunnelAuth The authentication string for the tunnel. + * @param tcpNoDelay Whether or not to disable Nagling. + * + * @return The socket. + */ + public static Socket buildSSLSocket(String host, int port, + String tunnelHost, int tunnelPort, + String tunnelAuth, Boolean tcpNoDelay) + throws IOException, UnknownHostException { + SSLSocket sslSocket = null; SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory.getDefault(); @@ -124,7 +146,7 @@ * Start it off as a regular socket, then layer SSL * over the top of it. */ - Socket tunnel = doTunnelHandshake(tunnelHost, tunnelPort, + Socket tunnel = doTunnelHandshake(tunnelHost, tunnelPort, tunnelAuth, host, port, tcpNoDelay); // Overlay tunnel socket with SSL @@ -150,6 +172,7 @@ } static private Socket doTunnelHandshake(String tunnelHost, int tunnelPort, + String tunnelAuth, String host, int port, Boolean tcpNoDelay) throws IOException { @@ -158,28 +181,19 @@ if (tunnel != null && tcpNoDelay != null) tunnel.setTcpNoDelay(tcpNoDelay.booleanValue()); - /* - * The proxy may need an authorization string. Check - * standard https property. - * - * TODO: pass this as a parameter. - */ - String proxyAuth = System.getProperty("https.proxyAuth"); - String msg; OutputStream out = tunnel.getOutputStream(); - if (proxyAuth == null) { - // Authorization not required - + if (tunnelAuth == null) { + // Authentication not required msg = "CONNECT " + host + ":" + port + " HTTP/1.0\r\n" + "User-Agent: " + sun.net.www.protocol.http.HttpURLConnection.userAgent + "\r\n\r\n"; } else { - // need to specify an authorization string in http header + // need to specify an authentication string in http header msg = "CONNECT " + host + ":" + port + " HTTP/1.0\r\n" - + "Proxy-Authorization: " + proxyAuth + "\r\n" + + "Proxy-Authorization: " + tunnelAuth + "\r\n" + "User-Agent: " + sun.net.www.protocol.http.HttpURLConnection.userAgent + "\r\n\r\n";
-- To unsubscribe, e-mail: <mailto:soap-dev-unsubscribe@;xml.apache.org> For additional commands, e-mail: <mailto:soap-dev-help@;xml.apache.org>