Return-Path: Delivered-To: apmail-xml-axis-dev-archive@xml.apache.org Received: (qmail 6329 invoked by uid 500); 6 Oct 2001 15:22:47 -0000 Mailing-List: contact axis-dev-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list axis-dev@xml.apache.org Received: (qmail 6320 invoked by uid 500); 6 Oct 2001 15:22:47 -0000 Delivered-To: apmail-xml-axis-cvs@apache.org Date: 6 Oct 2001 15:19:33 -0000 Message-ID: <20011006151933.15793.qmail@icarus.apache.org> From: rubys@apache.org To: xml-axis-cvs@apache.org Subject: cvs commit: xml-axis/java/src/org/apache/axis/transport/http HTTPSender.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N rubys 01/10/06 08:19:33 Modified: java/src/org/apache/axis/transport/http HTTPSender.java Log: Add support for http.nonProxyHosts Submitted by: Davanum Srinivas Revision Changes Path 1.23 +171 -1 xml-axis/java/src/org/apache/axis/transport/http/HTTPSender.java Index: HTTPSender.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/transport/http/HTTPSender.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- HTTPSender.java 2001/10/03 15:53:47 1.22 +++ HTTPSender.java 2001/10/06 15:19:32 1.23 @@ -74,6 +74,7 @@ import java.net.Socket; import java.net.URL; import java.util.Hashtable; +import java.util.StringTokenizer; /** * This is meant to be used on a SOAP Client to call a SOAP server. @@ -181,10 +182,14 @@ } else { String proxyHost = System.getProperty("http.proxyHost"); String proxyPort = System.getProperty("http.proxyPort"); + String nonProxyHosts = System.getProperty("http.nonProxyHosts"); + boolean hostInNonProxyList = isHostInNonProxyList(host, nonProxyHosts); + if ((port = tmpURL.getPort()) == -1 ) port = 80; if (proxyHost == null || proxyHost.equals("") - || proxyPort == null || proxyPort.equals("")) { + || proxyPort == null || proxyPort.equals("") + || hostInNonProxyList) { sock = new Socket( host, port ); category.debug( "Created an insecure HTTP connection"); } else { @@ -423,6 +428,171 @@ } } + private boolean isHostInNonProxyList(String host, String nonProxyHosts) + { + if(nonProxyHosts == null || host == null) + return false; + StringTokenizer tokenizer = new StringTokenizer(nonProxyHosts,"|"); + while(tokenizer.hasMoreTokens()) { + String pattern = tokenizer.nextToken(); + category.debug( "HTTPSender match Host: " + host + " Pattern:" + pattern); + if(match(pattern, host, false)) + return true; + } + return false; + } + + /** + * Matches a string against a pattern. The pattern contains two special + * characters: + * '*' which means zero or more characters, + * + * @param pattern the (non-null) pattern to match against + * @param str the (non-null) string that must be matched against the + * pattern + * + * @return true when the string matches against the pattern, + * false otherwise. + */ + private static boolean match(String pattern, String str, boolean isCaseSensitive) { + char[] patArr = pattern.toCharArray(); + char[] strArr = str.toCharArray(); + int patIdxStart = 0; + int patIdxEnd = patArr.length-1; + int strIdxStart = 0; + int strIdxEnd = strArr.length-1; + char ch; + + boolean containsStar = false; + for (int i = 0; i < patArr.length; i++) { + if (patArr[i] == '*') { + containsStar = true; + break; + } + } + + if (!containsStar) { + // No '*'s, so we make a shortcut + if (patIdxEnd != strIdxEnd) { + return false; // Pattern and string do not have the same size + } + for (int i = 0; i <= patIdxEnd; i++) { + ch = patArr[i]; + if (isCaseSensitive && ch != strArr[i]) { + return false;// Character mismatch + } + if (!isCaseSensitive && Character.toUpperCase(ch) != + Character.toUpperCase(strArr[i])) { + return false; // Character mismatch + } + } + return true; // String matches against pattern + } + + if (patIdxEnd == 0) { + return true; // Pattern contains only '*', which matches anything + } + + // Process characters before first star + while((ch = patArr[patIdxStart]) != '*' && strIdxStart <= strIdxEnd) { + if (isCaseSensitive && ch != strArr[strIdxStart]) { + return false;// Character mismatch + } + if (!isCaseSensitive && Character.toUpperCase(ch) != + Character.toUpperCase(strArr[strIdxStart])) { + return false;// Character mismatch + } + patIdxStart++; + strIdxStart++; + } + if (strIdxStart > strIdxEnd) { + // All characters in the string are used. Check if only '*'s are + // left in the pattern. If so, we succeeded. Otherwise failure. + for (int i = patIdxStart; i <= patIdxEnd; i++) { + if (patArr[i] != '*') { + return false; + } + } + return true; + } + + // Process characters after last star + while((ch = patArr[patIdxEnd]) != '*' && strIdxStart <= strIdxEnd) { + if (isCaseSensitive && ch != strArr[strIdxEnd]) { + return false;// Character mismatch + } + if (!isCaseSensitive && Character.toUpperCase(ch) != + Character.toUpperCase(strArr[strIdxEnd])) { + return false;// Character mismatch + } + patIdxEnd--; + strIdxEnd--; + } + if (strIdxStart > strIdxEnd) { + // All characters in the string are used. Check if only '*'s are + // left in the pattern. If so, we succeeded. Otherwise failure. + for (int i = patIdxStart; i <= patIdxEnd; i++) { + if (patArr[i] != '*') { + return false; + } + } + return true; + } + + // process pattern between stars. padIdxStart and patIdxEnd point + // always to a '*'. + while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) { + int patIdxTmp = -1; + for (int i = patIdxStart+1; i <= patIdxEnd; i++) { + if (patArr[i] == '*') { + patIdxTmp = i; + break; + } + } + if (patIdxTmp == patIdxStart+1) { + // Two stars next to each other, skip the first one. + patIdxStart++; + continue; + } + // Find the pattern between padIdxStart & padIdxTmp in str between + // strIdxStart & strIdxEnd + int patLength = (patIdxTmp-patIdxStart-1); + int strLength = (strIdxEnd-strIdxStart+1); + int foundIdx = -1; + strLoop: + for (int i = 0; i <= strLength - patLength; i++) { + for (int j = 0; j < patLength; j++) { + ch = patArr[patIdxStart+j+1]; + if (isCaseSensitive && ch != strArr[strIdxStart+i+j]) { + continue strLoop; + } + if (!isCaseSensitive && Character.toUpperCase(ch) != + Character.toUpperCase(strArr[strIdxStart+i+j])) { + continue strLoop; + } + } + + foundIdx = strIdxStart+i; + break; + } + + if (foundIdx == -1) { + return false; + } + + patIdxStart = patIdxTmp; + strIdxStart = foundIdx+patLength; + } + + // All characters in the string are used. Check if only '*'s are left + // in the pattern. If so, we succeeded. Otherwise failure. + for (int i = patIdxStart; i <= patIdxEnd; i++) { + if (patArr[i] != '*') { + return false; + } + } + return true; + } public void undo(MessageContext msgContext) {