Author: hiranya
Date: Fri Aug 13 18:22:14 2010
New Revision: 985315
URL: http://svn.apache.org/viewvc?rev=985315&view=rev
Log:
Adding the concept of source test retrievers to the match and equal evaluators.
This allows for better extensibility of the evaluators and better code reuse.
Added:
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/HeaderTextRetriever.java
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/ParameterTextRetriever.java
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/SourceTextRetriever.java
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/URLTextRetriever.java
Modified:
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/EqualEvaluator.java
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/MatchEvaluator.java
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/EqualFactory.java
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/EqualSerializer.java
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/MatchFactory.java
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/MatchSerializer.java
synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/config/EqualBuilderTest.java
synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/config/MatchBuilderTest.java
Modified:
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/EqualEvaluator.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/EqualEvaluator.java?rev=985315&r1=985314&r2=985315&view=diff
==============================================================================
---
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/EqualEvaluator.java
(original)
+++
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/EqualEvaluator.java
Fri Aug 13 18:22:14 2010
@@ -21,8 +21,8 @@ package org.apache.synapse.commons.evalu
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.commons.evaluators.source.SourceTextRetriever;
-import java.io.UnsupportedEncodingException;
/**
* Try to see weather a part of the HTTP request is equal to the value
provided.
@@ -32,30 +32,15 @@ import java.io.UnsupportedEncodingExcept
* </pre>
*/
public class EqualEvaluator implements Evaluator {
+
private Log log = LogFactory.getLog(EqualEvaluator.class);
private String value = null;
- private String source = null;
-
- private int type = EvaluatorConstants.TYPE_HEADER;
+ private SourceTextRetriever textRetriever;
public boolean evaluate(EvaluatorContext context) throws
EvaluatorException {
- String sourceText = null;
-
- if (type == EvaluatorConstants.TYPE_URL) {
- sourceText = context.getUrl();
- } else if (type == EvaluatorConstants.TYPE_PARAM) {
- try {
- sourceText = context.getParam(source);
- } catch (UnsupportedEncodingException e) {
- handleException("Error retrieving paramter: " + source);
- }
- } else if (type == EvaluatorConstants.TYPE_HEADER) {
- sourceText = context.getHeader(source);
- }
-
+ String sourceText = textRetriever.getSourceText(context);
return sourceText != null && sourceText.equalsIgnoreCase(value);
-
}
public String getName() {
@@ -66,28 +51,16 @@ public class EqualEvaluator implements E
this.value = value;
}
- public void setSource(String source) {
- this.source = source;
- }
-
- public void setType(int type) {
- this.type = type;
+ public void setTextRetriever(SourceTextRetriever textRetriever) {
+ this.textRetriever = textRetriever;
}
public String getValue() {
return value;
}
- public String getSource() {
- return source;
- }
-
- public int getType() {
- return type;
- }
-
- private void handleException(String message) throws EvaluatorException {
- log.error(message);
- throw new EvaluatorException(message);
+ public SourceTextRetriever getTextRetriever() {
+ return textRetriever;
}
+
}
Modified:
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/MatchEvaluator.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/MatchEvaluator.java?rev=985315&r1=985314&r2=985315&view=diff
==============================================================================
---
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/MatchEvaluator.java
(original)
+++
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/MatchEvaluator.java
Fri Aug 13 18:22:14 2010
@@ -21,10 +21,10 @@ package org.apache.synapse.commons.evalu
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.commons.evaluators.source.SourceTextRetriever;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
-import java.io.UnsupportedEncodingException;
/**
* This evaluator uses regular expressions to match a given HTTP request.</p>
@@ -40,26 +40,12 @@ public class MatchEvaluator implements E
private Log log = LogFactory.getLog(MatchEvaluator.class);
- private int type = EvaluatorConstants.TYPE_HEADER;
-
- private String source = null;
+ private SourceTextRetriever textRetriever;
private Pattern regex = null;
public boolean evaluate(EvaluatorContext context) throws
EvaluatorException {
- String sourceText = null;
-
- if (type == EvaluatorConstants.TYPE_URL) {
- sourceText = context.getUrl();
- } else if (type == EvaluatorConstants.TYPE_PARAM) {
- try {
- sourceText = context.getParam(source);
- } catch (UnsupportedEncodingException e) {
- handleException("Error retrieving paramter: " + source);
- }
- } else if (type == EvaluatorConstants.TYPE_HEADER) {
- sourceText = context.getHeader(source);
- }
+ String sourceText = textRetriever.getSourceText(context);
if (sourceText == null) {
return false;
@@ -73,28 +59,20 @@ public class MatchEvaluator implements E
return EvaluatorConstants.MATCH;
}
- public int getType() {
- return type;
- }
-
- public String getSource() {
- return source;
- }
-
public Pattern getRegex() {
return regex;
}
- public void setType(int type) {
- this.type = type;
+ public void setRegex(Pattern regex) {
+ this.regex = regex;
}
- public void setSource(String source) {
- this.source = source;
+ public SourceTextRetriever getTextRetriever() {
+ return textRetriever;
}
- public void setRegex(Pattern regex) {
- this.regex = regex;
+ public void setTextRetriever(SourceTextRetriever textRetriever) {
+ this.textRetriever = textRetriever;
}
private void handleException(String message) throws EvaluatorException {
Modified:
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/EqualFactory.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/EqualFactory.java?rev=985315&r1=985314&r2=985315&view=diff
==============================================================================
---
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/EqualFactory.java
(original)
+++
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/EqualFactory.java
Fri Aug 13 18:22:14 2010
@@ -23,6 +23,10 @@ import org.apache.synapse.commons.evalua
import org.apache.synapse.commons.evaluators.EvaluatorException;
import org.apache.synapse.commons.evaluators.EqualEvaluator;
import org.apache.synapse.commons.evaluators.EvaluatorConstants;
+import org.apache.synapse.commons.evaluators.source.SourceTextRetriever;
+import org.apache.synapse.commons.evaluators.source.HeaderTextRetriever;
+import org.apache.synapse.commons.evaluators.source.ParameterTextRetriever;
+import org.apache.synapse.commons.evaluators.source.URLTextRetriever;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMAttribute;
import org.apache.commons.logging.Log;
@@ -44,32 +48,41 @@ public class EqualFactory implements Eva
EqualEvaluator equal = new EqualEvaluator();
OMAttribute typeAttr = e.getAttribute(new
QName(EvaluatorConstants.TYPE));
+ OMAttribute sourceAttr = e.getAttribute(new
QName(EvaluatorConstants.SOURCE));
- int type = EvaluatorConstants.TYPE_HEADER;
+ SourceTextRetriever textRetriever = null;
if (typeAttr != null) {
String value = typeAttr.getAttributeValue();
if (value.equals(EvaluatorConstants.HEADER)) {
- type = EvaluatorConstants.TYPE_HEADER;
+ if (sourceAttr != null) {
+ textRetriever = new
HeaderTextRetriever(sourceAttr.getAttributeValue());
+ } else {
+ handleException(EvaluatorConstants.SOURCE + " attribute is
required");
+ }
} else if (value.equals(EvaluatorConstants.PARAM)) {
- type = EvaluatorConstants.TYPE_PARAM;
+ if (sourceAttr != null) {
+ textRetriever = new
ParameterTextRetriever(sourceAttr.getAttributeValue());
+ } else {
+ handleException(EvaluatorConstants.SOURCE + " attribute is
required");
+ }
} else if (value.equals(EvaluatorConstants.URL)) {
- type = EvaluatorConstants.TYPE_URL;
+ textRetriever = new URLTextRetriever();
+ } else {
+ handleException("Unknown equal evaluator type: " + value);
}
}
- equal.setType(type);
-
- OMAttribute sourceAttr = e.getAttribute(new
QName(EvaluatorConstants.SOURCE));
- if (sourceAttr == null) {
- if (type != EvaluatorConstants.TYPE_URL) {
+ if (textRetriever == null) {
+ if (sourceAttr != null) {
+ textRetriever = new
HeaderTextRetriever(sourceAttr.getAttributeValue());
+ } else {
handleException(EvaluatorConstants.SOURCE + " attribute is
required");
- return null;
}
- } else {
- equal.setSource(sourceAttr.getAttributeValue());
}
+ equal.setTextRetriever(textRetriever);
+
OMAttribute valueAttr = e.getAttribute(new
QName(EvaluatorConstants.VALUE));
if (valueAttr == null) {
Modified:
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/EqualSerializer.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/EqualSerializer.java?rev=985315&r1=985314&r2=985315&view=diff
==============================================================================
---
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/EqualSerializer.java
(original)
+++
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/EqualSerializer.java
Fri Aug 13 18:22:14 2010
@@ -21,6 +21,10 @@ package org.apache.synapse.commons.evalu
import org.apache.axiom.om.OMElement;
import org.apache.synapse.commons.evaluators.*;
+import org.apache.synapse.commons.evaluators.source.SourceTextRetriever;
+import org.apache.synapse.commons.evaluators.source.HeaderTextRetriever;
+import org.apache.synapse.commons.evaluators.source.ParameterTextRetriever;
+import org.apache.synapse.commons.evaluators.source.URLTextRetriever;
import javax.xml.namespace.QName;
@@ -29,48 +33,55 @@ import javax.xml.namespace.QName;
* the {...@link EqualFactory}.
*/
public class EqualSerializer extends AbstractEvaluatorSerializer{
+
public OMElement serialize(OMElement parent, Evaluator evaluator) throws
EvaluatorException {
+
if (!(evaluator instanceof EqualEvaluator)) {
throw new IllegalArgumentException("Evalutor should be a
EqualEvalutor");
}
EqualEvaluator equalEvaluator = (EqualEvaluator) evaluator;
- OMElement eqaulElement = fac.createOMElement(new
QName(EvaluatorConstants.EQUAL));
+ OMElement equalElement = fac.createOMElement(new
QName(EvaluatorConstants.EQUAL));
- if (equalEvaluator.getType() != EvaluatorConstants.TYPE_URL) {
- if (equalEvaluator.getSource() != null) {
-
eqaulElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.SOURCE,
nullNS,
- equalEvaluator.getSource()));
- } else {
- String msg = "If type is not URL a source value should be
specified for " +
- "the equal evaluator";
- log.error(msg);
- throw new EvaluatorException(msg);
- }
- }
+ SourceTextRetriever textRetriever = equalEvaluator.getTextRetriever();
+ if (textRetriever instanceof HeaderTextRetriever) {
+
equalElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.TYPE, nullNS,
+ EvaluatorConstants.HEADER));
+ HeaderTextRetriever headerTextRetriever = (HeaderTextRetriever)
textRetriever;
+ addSourceAttribute(headerTextRetriever.getSource(), equalElement);
- if (equalEvaluator.getType() == EvaluatorConstants.TYPE_URL) {
-
eqaulElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.TYPE, nullNS,
- EvaluatorConstants.URL));
- } else if (equalEvaluator.getType() == EvaluatorConstants.TYPE_PARAM) {
-
eqaulElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.TYPE, nullNS,
+ } else if (textRetriever instanceof ParameterTextRetriever) {
+
equalElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.TYPE, nullNS,
EvaluatorConstants.PARAM));
- } else if (equalEvaluator.getType() == EvaluatorConstants.TYPE_HEADER)
{
-
eqaulElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.TYPE, nullNS,
- EvaluatorConstants.HEADER));
+ ParameterTextRetriever paramTextRetriever =
(ParameterTextRetriever) textRetriever;
+ addSourceAttribute(paramTextRetriever.getSource(), equalElement);
+
} else {
- String msg = "Unsupported type value: " + equalEvaluator.getType();
- log.error(msg);
- throw new EvaluatorException(msg);
+
equalElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.TYPE, nullNS,
+ EvaluatorConstants.URL));
}
-
eqaulElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.VALUE,
nullNS,
+
equalElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.VALUE,
nullNS,
equalEvaluator.getValue()));
if (parent != null) {
- parent.addChild(eqaulElement);
+ parent.addChild(equalElement);
}
- return eqaulElement;
+ return equalElement;
+ }
+
+ private void addSourceAttribute(String source, OMElement equalElement)
+ throws EvaluatorException {
+
+ if (source != null) {
+
equalElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.SOURCE,
nullNS,
+ source));
+ } else {
+ String msg = "If type is not URL a source value should be
specified for " +
+ "the equal evaluator";
+ log.error(msg);
+ throw new EvaluatorException(msg);
+ }
}
}
Modified:
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/MatchFactory.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/MatchFactory.java?rev=985315&r1=985314&r2=985315&view=diff
==============================================================================
---
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/MatchFactory.java
(original)
+++
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/MatchFactory.java
Fri Aug 13 18:22:14 2010
@@ -24,6 +24,10 @@ import org.apache.synapse.commons.evalua
import org.apache.synapse.commons.evaluators.EvaluatorException;
import org.apache.synapse.commons.evaluators.MatchEvaluator;
import org.apache.synapse.commons.evaluators.EvaluatorConstants;
+import org.apache.synapse.commons.evaluators.source.HeaderTextRetriever;
+import org.apache.synapse.commons.evaluators.source.ParameterTextRetriever;
+import org.apache.synapse.commons.evaluators.source.URLTextRetriever;
+import org.apache.synapse.commons.evaluators.source.SourceTextRetriever;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMAttribute;
import org.apache.commons.logging.Log;
@@ -46,34 +50,40 @@ public class MatchFactory implements Eva
MatchEvaluator equal = new MatchEvaluator();
OMAttribute typeAttr = e.getAttribute(new
QName(EvaluatorConstants.TYPE));
+ OMAttribute sourceAttr = e.getAttribute(new
QName(EvaluatorConstants.SOURCE));
- int type = EvaluatorConstants.TYPE_HEADER;
+ SourceTextRetriever textRetriever = null;
if (typeAttr != null) {
String value = typeAttr.getAttributeValue();
if (value.equals(EvaluatorConstants.HEADER)) {
- type = EvaluatorConstants.TYPE_HEADER;
+ if (sourceAttr != null) {
+ textRetriever = new
HeaderTextRetriever(sourceAttr.getAttributeValue());
+ } else {
+ handleException(EvaluatorConstants.SOURCE + " attribute is
required");
+ }
} else if (value.equals(EvaluatorConstants.PARAM)) {
- type = EvaluatorConstants.TYPE_PARAM;
+ if (sourceAttr != null) {
+ textRetriever = new
ParameterTextRetriever(sourceAttr.getAttributeValue());
+ } else {
+ handleException(EvaluatorConstants.SOURCE + " attribute is
required");
+ }
} else if (value.equals(EvaluatorConstants.URL)) {
- type = EvaluatorConstants.TYPE_URL;
+ textRetriever = new URLTextRetriever();
} else {
handleException("Unknown match evaluator type: " + value);
}
}
- equal.setType(type);
-
- OMAttribute sourceAttr = e.getAttribute(new
QName(EvaluatorConstants.SOURCE));
- if (sourceAttr == null) {
- if (type != 1) {
+ if (textRetriever == null) {
+ if (sourceAttr != null) {
+ textRetriever = new
HeaderTextRetriever(sourceAttr.getAttributeValue());
+ } else {
handleException(EvaluatorConstants.SOURCE + " attribute is
required");
- return null;
}
- } else {
- equal.setSource(sourceAttr.getAttributeValue());
}
+ equal.setTextRetriever(textRetriever);
OMAttribute regExAttr = e.getAttribute(new
QName(EvaluatorConstants.REGEX));
if (regExAttr == null) {
@@ -83,7 +93,7 @@ public class MatchFactory implements Eva
equal.setRegex(Pattern.compile(regExAttr.getAttributeValue()));
- return equal ;
+ return equal;
}
private void handleException(String message) throws EvaluatorException {
Modified:
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/MatchSerializer.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/MatchSerializer.java?rev=985315&r1=985314&r2=985315&view=diff
==============================================================================
---
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/MatchSerializer.java
(original)
+++
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/MatchSerializer.java
Fri Aug 13 18:22:14 2010
@@ -5,6 +5,9 @@ import org.apache.synapse.commons.evalua
import org.apache.synapse.commons.evaluators.EvaluatorException;
import org.apache.synapse.commons.evaluators.MatchEvaluator;
import org.apache.synapse.commons.evaluators.EvaluatorConstants;
+import org.apache.synapse.commons.evaluators.source.SourceTextRetriever;
+import org.apache.synapse.commons.evaluators.source.HeaderTextRetriever;
+import org.apache.synapse.commons.evaluators.source.ParameterTextRetriever;
import javax.xml.namespace.QName;
@@ -22,31 +25,22 @@ public class MatchSerializer extends Abs
MatchEvaluator matchEvaluator = (MatchEvaluator) evaluator;
OMElement matchElement = fac.createOMElement(new
QName(EvaluatorConstants.MATCH));
- if (matchEvaluator.getType() != EvaluatorConstants.TYPE_URL) {
- if (matchEvaluator.getSource() != null) {
-
matchElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.SOURCE,
nullNS,
- matchEvaluator.getSource()));
- } else {
- String msg = "If type is not URL a source value should be
specified for " +
- "the match evaluator";
- log.error(msg);
- throw new EvaluatorException(msg);
- }
- }
-
- if (matchEvaluator.getType() == EvaluatorConstants.TYPE_URL) {
+ SourceTextRetriever textRetriever = matchEvaluator.getTextRetriever();
+ if (textRetriever instanceof HeaderTextRetriever) {
matchElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.TYPE, nullNS,
- EvaluatorConstants.URL));
- } else if (matchEvaluator.getType() == EvaluatorConstants.TYPE_PARAM) {
+ EvaluatorConstants.HEADER));
+ HeaderTextRetriever headerTextRetriever = (HeaderTextRetriever)
textRetriever;
+ addSourceAttribute(headerTextRetriever.getSource(), matchElement);
+
+ } else if (textRetriever instanceof ParameterTextRetriever) {
matchElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.TYPE, nullNS,
EvaluatorConstants.PARAM));
- } else if (matchEvaluator.getType() == EvaluatorConstants.TYPE_HEADER)
{
-
matchElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.TYPE, nullNS,
- EvaluatorConstants.HEADER));
+ ParameterTextRetriever paramTextRetriever =
(ParameterTextRetriever) textRetriever;
+ addSourceAttribute(paramTextRetriever.getSource(), matchElement);
+
} else {
- String msg = "Unsupported type value: " + matchEvaluator.getType();
- log.error(msg);
- throw new EvaluatorException(msg);
+
matchElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.TYPE, nullNS,
+ EvaluatorConstants.URL));
}
matchElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.REGEX,
nullNS,
@@ -58,4 +52,18 @@ public class MatchSerializer extends Abs
return matchElement;
}
+
+ private void addSourceAttribute(String source, OMElement equalElement)
+ throws EvaluatorException {
+
+ if (source != null) {
+
equalElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.SOURCE,
nullNS,
+ source));
+ } else {
+ String msg = "If type is not URL a source value should be
specified for " +
+ "the match evaluator";
+ log.error(msg);
+ throw new EvaluatorException(msg);
+ }
+ }
}
Added:
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/HeaderTextRetriever.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/HeaderTextRetriever.java?rev=985315&view=auto
==============================================================================
---
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/HeaderTextRetriever.java
(added)
+++
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/HeaderTextRetriever.java
Fri Aug 13 18:22:14 2010
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.synapse.commons.evaluators.source;
+
+import org.apache.synapse.commons.evaluators.EvaluatorContext;
+import org.apache.synapse.commons.evaluators.EvaluatorException;
+
+public class HeaderTextRetriever implements SourceTextRetriever {
+
+ private String source;
+
+ public HeaderTextRetriever(String source) {
+ this.source = source;
+ }
+
+ public String getSourceText(EvaluatorContext context) throws
EvaluatorException {
+ return context.getHeader(source);
+ }
+
+ public String getSource() {
+ return source;
+ }
+}
Added:
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/ParameterTextRetriever.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/ParameterTextRetriever.java?rev=985315&view=auto
==============================================================================
---
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/ParameterTextRetriever.java
(added)
+++
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/ParameterTextRetriever.java
Fri Aug 13 18:22:14 2010
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.synapse.commons.evaluators.source;
+
+import org.apache.synapse.commons.evaluators.EvaluatorContext;
+import org.apache.synapse.commons.evaluators.EvaluatorException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.UnsupportedEncodingException;
+
+public class ParameterTextRetriever implements SourceTextRetriever {
+
+ private static final Log log =
LogFactory.getLog(ParameterTextRetriever.class);
+
+ private String source;
+
+ public ParameterTextRetriever(String source) {
+ this.source = source;
+ }
+
+ public String getSourceText(EvaluatorContext context) throws
EvaluatorException {
+ try {
+ return context.getParam(source);
+ } catch (UnsupportedEncodingException e) {
+ String message = "Error retrieving paramter: " + source;
+ log.error(message);
+ throw new EvaluatorException(message);
+ }
+ }
+
+ public String getSource() {
+ return source;
+ }
+}
Added:
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/SourceTextRetriever.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/SourceTextRetriever.java?rev=985315&view=auto
==============================================================================
---
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/SourceTextRetriever.java
(added)
+++
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/SourceTextRetriever.java
Fri Aug 13 18:22:14 2010
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.synapse.commons.evaluators.source;
+
+import org.apache.synapse.commons.evaluators.EvaluatorContext;
+import org.apache.synapse.commons.evaluators.EvaluatorException;
+
+public interface SourceTextRetriever {
+
+ public String getSourceText(EvaluatorContext context) throws
EvaluatorException;
+
+}
Added:
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/URLTextRetriever.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/URLTextRetriever.java?rev=985315&view=auto
==============================================================================
---
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/URLTextRetriever.java
(added)
+++
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/URLTextRetriever.java
Fri Aug 13 18:22:14 2010
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.synapse.commons.evaluators.source;
+
+import org.apache.synapse.commons.evaluators.EvaluatorContext;
+import org.apache.synapse.commons.evaluators.EvaluatorException;
+
+public class URLTextRetriever implements SourceTextRetriever {
+
+ public String getSourceText(EvaluatorContext context) throws
EvaluatorException {
+ return context.getUrl();
+ }
+}
Modified:
synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/config/EqualBuilderTest.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/config/EqualBuilderTest.java?rev=985315&r1=985314&r2=985315&view=diff
==============================================================================
---
synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/config/EqualBuilderTest.java
(original)
+++
synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/config/EqualBuilderTest.java
Fri Aug 13 18:22:14 2010
@@ -21,8 +21,11 @@ package org.apache.synapse.commons.evalu
import junit.framework.TestCase;
import org.apache.axiom.om.util.AXIOMUtil;
-import org.apache.synapse.commons.evaluators.EvaluatorConstants;
import org.apache.synapse.commons.evaluators.EqualEvaluator;
+import org.apache.synapse.commons.evaluators.source.SourceTextRetriever;
+import org.apache.synapse.commons.evaluators.source.HeaderTextRetriever;
+import org.apache.synapse.commons.evaluators.source.ParameterTextRetriever;
+import org.apache.synapse.commons.evaluators.source.URLTextRetriever;
public class EqualBuilderTest extends TestCase {
@@ -37,8 +40,9 @@ public class EqualBuilderTest extends Te
try {
EqualEvaluator eval = (EqualEvaluator)
fac.create(AXIOMUtil.stringToOM(input));
- assertEquals(eval.getType(), EvaluatorConstants.TYPE_HEADER);
- assertEquals(eval.getSource(), SOURCE);
+ SourceTextRetriever txtRtvr = eval.getTextRetriever();
+ assertTrue(txtRtvr instanceof HeaderTextRetriever);
+ assertEquals(((HeaderTextRetriever) txtRtvr).getSource(), SOURCE);
assertEquals(eval.getValue(), VALUE);
} catch (Exception e) {
fail("Error while parsing the input XML");
@@ -51,8 +55,9 @@ public class EqualBuilderTest extends Te
try {
EqualEvaluator eval = (EqualEvaluator)
fac.create(AXIOMUtil.stringToOM(input));
- assertEquals(eval.getType(), EvaluatorConstants.TYPE_PARAM);
- assertEquals(eval.getSource(), SOURCE);
+ SourceTextRetriever txtRtvr = eval.getTextRetriever();
+ assertTrue(txtRtvr instanceof ParameterTextRetriever);
+ assertEquals(((ParameterTextRetriever) txtRtvr).getSource(),
SOURCE);
assertEquals(eval.getValue(), VALUE);
} catch (Exception e) {
fail("Error while parsing the input XML");
@@ -64,8 +69,8 @@ public class EqualBuilderTest extends Te
try {
EqualEvaluator eval = (EqualEvaluator)
fac.create(AXIOMUtil.stringToOM(input));
- assertEquals(eval.getType(), EvaluatorConstants.TYPE_URL);
- assertNull(eval.getSource());
+ SourceTextRetriever txtRtvr = eval.getTextRetriever();
+ assertTrue(txtRtvr instanceof URLTextRetriever);
assertEquals(eval.getValue(), VALUE);
} catch (Exception e) {
fail("Error while parsing the input XML");
Modified:
synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/config/MatchBuilderTest.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/config/MatchBuilderTest.java?rev=985315&r1=985314&r2=985315&view=diff
==============================================================================
---
synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/config/MatchBuilderTest.java
(original)
+++
synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/config/MatchBuilderTest.java
Fri Aug 13 18:22:14 2010
@@ -22,7 +22,10 @@ package org.apache.synapse.commons.evalu
import junit.framework.TestCase;
import org.apache.axiom.om.util.AXIOMUtil;
import org.apache.synapse.commons.evaluators.MatchEvaluator;
-import org.apache.synapse.commons.evaluators.EvaluatorConstants;
+import org.apache.synapse.commons.evaluators.source.SourceTextRetriever;
+import org.apache.synapse.commons.evaluators.source.HeaderTextRetriever;
+import org.apache.synapse.commons.evaluators.source.ParameterTextRetriever;
+import org.apache.synapse.commons.evaluators.source.URLTextRetriever;
public class MatchBuilderTest extends TestCase {
@@ -37,8 +40,9 @@ public class MatchBuilderTest extends Te
try {
MatchEvaluator eval = (MatchEvaluator)
fac.create(AXIOMUtil.stringToOM(input));
- assertEquals(eval.getType(), EvaluatorConstants.TYPE_HEADER);
- assertEquals(eval.getSource(), SOURCE);
+ SourceTextRetriever txtRtvr = eval.getTextRetriever();
+ assertTrue(txtRtvr instanceof HeaderTextRetriever);
+ assertEquals(((HeaderTextRetriever) txtRtvr).getSource(), SOURCE);
assertEquals(eval.getRegex().pattern(), REGEX);
} catch (Exception e) {
fail("Error while parsing the input XML");
@@ -51,8 +55,9 @@ public class MatchBuilderTest extends Te
try {
MatchEvaluator eval = (MatchEvaluator)
fac.create(AXIOMUtil.stringToOM(input));
- assertEquals(eval.getType(), EvaluatorConstants.TYPE_PARAM);
- assertEquals(eval.getSource(), SOURCE);
+ SourceTextRetriever txtRtvr = eval.getTextRetriever();
+ assertTrue(txtRtvr instanceof ParameterTextRetriever);
+ assertEquals(((ParameterTextRetriever) txtRtvr).getSource(),
SOURCE);
assertEquals(eval.getRegex().pattern(), REGEX);
} catch (Exception e) {
fail("Error while parsing the input XML");
@@ -64,8 +69,8 @@ public class MatchBuilderTest extends Te
try {
MatchEvaluator eval = (MatchEvaluator)
fac.create(AXIOMUtil.stringToOM(input));
- assertEquals(eval.getType(), EvaluatorConstants.TYPE_URL);
- assertNull(eval.getSource());
+ SourceTextRetriever txtRtvr = eval.getTextRetriever();
+ assertTrue(txtRtvr instanceof URLTextRetriever);
assertEquals(eval.getRegex().pattern(), REGEX);
} catch (Exception e) {
fail("Error while parsing the input XML");