You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by va...@apache.org on 2014/07/25 12:11:20 UTC
[3/3] git commit: ODE-742: Fixing a OS X issue with HTTP binding.
ODE-742: Fixing a OS X issue with HTTP binding.
Project: http://git-wip-us.apache.org/repos/asf/ode/repo
Commit: http://git-wip-us.apache.org/repos/asf/ode/commit/4900097f
Tree: http://git-wip-us.apache.org/repos/asf/ode/tree/4900097f
Diff: http://git-wip-us.apache.org/repos/asf/ode/diff/4900097f
Branch: refs/heads/master
Commit: 4900097f4c17b26881672e8ee6adec9aae59c605
Parents: dec47e4
Author: Tammo van Lessen <tv...@gmail.com>
Authored: Fri Jul 25 12:09:48 2014 +0200
Committer: Tammo van Lessen <tv...@gmail.com>
Committed: Fri Jul 25 12:09:48 2014 +0200
----------------------------------------------------------------------
.../apache/ode/axis2/httpbinding/ProxyConf.java | 165 ++++++++++++++++++-
1 file changed, 164 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ode/blob/4900097f/axis2/src/main/java/org/apache/ode/axis2/httpbinding/ProxyConf.java
----------------------------------------------------------------------
diff --git a/axis2/src/main/java/org/apache/ode/axis2/httpbinding/ProxyConf.java b/axis2/src/main/java/org/apache/ode/axis2/httpbinding/ProxyConf.java
index c0402e9..fa554d3 100644
--- a/axis2/src/main/java/org/apache/ode/axis2/httpbinding/ProxyConf.java
+++ b/axis2/src/main/java/org/apache/ode/axis2/httpbinding/ProxyConf.java
@@ -100,10 +100,173 @@ public class ProxyConf {
if (nonProxyHosts != null) {
String[] splitted = nonProxyHosts.split("\\|");
for (int i = 0; i < splitted.length; i++) {
- if (targetHost.matches(splitted[i])) return true;
+ if (match(splitted[i], targetHost, 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
+ * @param isCaseSensitive
+ *
+ * @return <code>true</code> when the string matches against the pattern,
+ * <code>false</code> otherwise.
+ */
+ protected 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;
+ }
}