You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by hi...@apache.org on 2010/09/12 12:10:43 UTC
svn commit: r996281 - in /synapse/trunk/java/modules/commons/src:
main/java/org/apache/synapse/commons/evaluators/
main/java/org/apache/synapse/commons/evaluators/config/
main/java/org/apache/synapse/commons/evaluators/source/
test/java/org/apache/syna...
Author: hiranya
Date: Sun Sep 12 10:10:42 2010
New Revision: 996281
URL: http://svn.apache.org/viewvc?rev=996281&view=rev
Log:
* Updated the equal and match evaluator factories to support SOAPEnvelope text retriever and the property text retriever (SYNAPSE-684)
* Refactored the SourceTextRetriever interface and the implementations
* Unified the configuration model for all types of text processing evaluators (now exclusively using the source attribute - this will keep the configuration language simple and clean)
* Updated the test cases accordingly
Added:
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/TextProcessingEvaluatorFactory.java
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/TextProcessingEvaluatorSerializer.java
Modified:
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/EvaluatorConstants.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/main/java/org/apache/synapse/commons/evaluators/source/PropertyTextRetriever.java
synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/SOAPEnvelopeTextRetriever.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
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/EqualSerializerTest.java
synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/config/MatchBuilderTest.java
synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/config/MatchSerializerTest.java
synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/source/SourceTextRetrieverTest.java
Modified: synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/EvaluatorConstants.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/EvaluatorConstants.java?rev=996281&r1=996280&r2=996281&view=diff
==============================================================================
--- synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/EvaluatorConstants.java (original)
+++ synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/EvaluatorConstants.java Sun Sep 12 10:10:42 2010
@@ -23,20 +23,24 @@ package org.apache.synapse.commons.evalu
* Constants used through out the evaluators
*/
public class EvaluatorConstants {
+
public static final String AND = "and";
public static final String OR = "or";
public static final String NOT = "not";
public static final String MATCH = "match";
public static final String EQUAL = "equal";
- public static final String TYPE = "type";
+ // Types of source text retrievers
public static final String HEADER = "header";
public static final String PARAM = "param";
public static final String URL = "url";
+ public static final String PROPERTY = "property";
+ public static final String SOAP = "soap";
+
+ public static final String TYPE = "type";
public static final String SOURCE = "source";
public static final String REGEX = "regex";
public static final String VALUE = "value";
- public static final String FRAGMENT = "fragment";
public static final String CONDITIONS = "conditions";
public static final String CONDITION = "condition";
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=996281&r1=996280&r2=996281&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 Sun Sep 12 10:10:42 2010
@@ -24,13 +24,8 @@ import org.apache.synapse.commons.evalua
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;
-import org.apache.commons.logging.LogFactory;
import javax.xml.namespace.QName;
@@ -41,50 +36,11 @@ import javax.xml.namespace.QName;
* <equal type="header | param | url" source="" value=""/>
* </pre>
*/
-public class EqualFactory implements EvaluatorFactory {
- private Log log = LogFactory.getLog(EqualFactory.class);
+public class EqualFactory extends TextProcessingEvaluatorFactory {
public Evaluator create(OMElement e) throws EvaluatorException {
EqualEvaluator equal = new EqualEvaluator();
-
- OMAttribute typeAttr = e.getAttribute(new QName(EvaluatorConstants.TYPE));
- OMAttribute sourceAttr = e.getAttribute(new QName(EvaluatorConstants.SOURCE));
-
- SourceTextRetriever textRetriever = null;
-
- if (typeAttr != null) {
- String value = typeAttr.getAttributeValue();
- if (value.equals(EvaluatorConstants.HEADER)) {
- if (sourceAttr != null) {
- textRetriever = new HeaderTextRetriever(sourceAttr.getAttributeValue());
- } else {
- handleException(EvaluatorConstants.SOURCE + " attribute is required");
- }
- } else if (value.equals(EvaluatorConstants.PARAM)) {
- if (sourceAttr != null) {
- textRetriever = new ParameterTextRetriever(sourceAttr.getAttributeValue());
- } else {
- handleException(EvaluatorConstants.SOURCE + " attribute is required");
- }
- } else if (value.equals(EvaluatorConstants.URL)) {
- textRetriever = new URLTextRetriever();
- OMAttribute fragAttr = e.getAttribute(new QName(EvaluatorConstants.FRAGMENT));
- if (fragAttr != null) {
- ((URLTextRetriever) textRetriever).setFragment(fragAttr.getAttributeValue());
- }
- } else {
- handleException("Unknown equal evaluator type: " + value);
- }
- }
-
- if (textRetriever == null) {
- if (sourceAttr != null) {
- textRetriever = new HeaderTextRetriever(sourceAttr.getAttributeValue());
- } else {
- handleException(EvaluatorConstants.SOURCE + " attribute is required");
- }
- }
-
+ SourceTextRetriever textRetriever = getSourceTextRetriever(e);
equal.setTextRetriever(textRetriever);
OMAttribute valueAttr = e.getAttribute(new QName(EvaluatorConstants.VALUE));
@@ -97,9 +53,4 @@ public class EqualFactory implements Eva
equal.setValue(valueAttr.getAttributeValue());
return equal;
}
-
- private void handleException(String message) throws EvaluatorException {
- log.error(message);
- throw new EvaluatorException(message);
- }
}
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=996281&r1=996280&r2=996281&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 Sun Sep 12 10:10:42 2010
@@ -21,10 +21,6 @@ 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;
@@ -32,39 +28,17 @@ import javax.xml.namespace.QName;
* Serialize the {@link EqualEvaluator} to the XML configuration defined in
* the {@link EqualFactory}.
*/
-public class EqualSerializer extends AbstractEvaluatorSerializer{
+public class EqualSerializer extends TextProcessingEvaluatorSerializer {
public OMElement serialize(OMElement parent, Evaluator evaluator) throws EvaluatorException {
if (!(evaluator instanceof EqualEvaluator)) {
- throw new IllegalArgumentException("Evalutor should be a EqualEvalutor");
+ throw new IllegalArgumentException("Evalutor must be an EqualEvalutor");
}
EqualEvaluator equalEvaluator = (EqualEvaluator) evaluator;
OMElement equalElement = fac.createOMElement(new QName(EvaluatorConstants.EQUAL));
-
- 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);
-
- } else if (textRetriever instanceof ParameterTextRetriever) {
- equalElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.TYPE, nullNS,
- EvaluatorConstants.PARAM));
- ParameterTextRetriever paramTextRetriever = (ParameterTextRetriever) textRetriever;
- addSourceAttribute(paramTextRetriever.getSource(), equalElement);
-
- } else {
- equalElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.TYPE, nullNS,
- EvaluatorConstants.URL));
- URLTextRetriever urlTextRetriever = (URLTextRetriever) textRetriever;
- if (urlTextRetriever.getFragment() != null) {
- equalElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.FRAGMENT,
- nullNS, urlTextRetriever.getFragment()));
- }
- }
+ serializeSourceTextRetriever(equalEvaluator.getTextRetriever(), equalElement);
equalElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.VALUE, nullNS,
equalEvaluator.getValue()));
@@ -75,18 +49,4 @@ public class EqualSerializer extends Abs
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=996281&r1=996280&r2=996281&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 Sun Sep 12 10:10:42 2010
@@ -24,14 +24,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.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;
-import org.apache.commons.logging.LogFactory;
import javax.xml.namespace.QName;
import java.util.regex.Pattern;
@@ -43,50 +38,11 @@ import java.util.regex.Pattern;
* <match type="header | param | url" source="" regex=""/>
* </pre>
*/
-public class MatchFactory implements EvaluatorFactory {
- private Log log = LogFactory.getLog(MatchFactory.class);
+public class MatchFactory extends TextProcessingEvaluatorFactory {
public Evaluator create(OMElement e) throws EvaluatorException {
MatchEvaluator equal = new MatchEvaluator();
-
- OMAttribute typeAttr = e.getAttribute(new QName(EvaluatorConstants.TYPE));
- OMAttribute sourceAttr = e.getAttribute(new QName(EvaluatorConstants.SOURCE));
-
- SourceTextRetriever textRetriever = null;
-
- if (typeAttr != null) {
- String value = typeAttr.getAttributeValue();
- if (value.equals(EvaluatorConstants.HEADER)) {
- if (sourceAttr != null) {
- textRetriever = new HeaderTextRetriever(sourceAttr.getAttributeValue());
- } else {
- handleException(EvaluatorConstants.SOURCE + " attribute is required");
- }
- } else if (value.equals(EvaluatorConstants.PARAM)) {
- if (sourceAttr != null) {
- textRetriever = new ParameterTextRetriever(sourceAttr.getAttributeValue());
- } else {
- handleException(EvaluatorConstants.SOURCE + " attribute is required");
- }
- } else if (value.equals(EvaluatorConstants.URL)) {
- textRetriever = new URLTextRetriever();
- OMAttribute fragAttr = e.getAttribute(new QName(EvaluatorConstants.FRAGMENT));
- if (fragAttr != null) {
- ((URLTextRetriever) textRetriever).setFragment(fragAttr.getAttributeValue());
- }
- } else {
- handleException("Unknown match evaluator type: " + value);
- }
- }
-
- if (textRetriever == null) {
- if (sourceAttr != null) {
- textRetriever = new HeaderTextRetriever(sourceAttr.getAttributeValue());
- } else {
- handleException(EvaluatorConstants.SOURCE + " attribute is required");
- }
- }
-
+ SourceTextRetriever textRetriever = getSourceTextRetriever(e);
equal.setTextRetriever(textRetriever);
OMAttribute regExAttr = e.getAttribute(new QName(EvaluatorConstants.REGEX));
@@ -96,12 +52,6 @@ public class MatchFactory implements Eva
}
equal.setRegex(Pattern.compile(regExAttr.getAttributeValue()));
-
return equal;
}
-
- private void handleException(String message) throws EvaluatorException {
- log.error(message);
- throw new EvaluatorException(message);
- }
}
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=996281&r1=996280&r2=996281&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 Sun Sep 12 10:10:42 2010
@@ -5,10 +5,6 @@ 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 org.apache.synapse.commons.evaluators.source.URLTextRetriever;
import javax.xml.namespace.QName;
@@ -16,38 +12,16 @@ import javax.xml.namespace.QName;
* Serialize the {@link MatchEvaluator} to the XML configuration defined in
* the {@link MatchFactory}.
*/
-public class MatchSerializer extends AbstractEvaluatorSerializer {
+public class MatchSerializer extends TextProcessingEvaluatorSerializer {
public OMElement serialize(OMElement parent, Evaluator evaluator) throws EvaluatorException {
if (!(evaluator instanceof MatchEvaluator)) {
- throw new IllegalArgumentException("Evalutor should be a NotEvalutor");
+ throw new IllegalArgumentException("Evalutor must be a NotEvalutor");
}
MatchEvaluator matchEvaluator = (MatchEvaluator) evaluator;
OMElement matchElement = fac.createOMElement(new QName(EvaluatorConstants.MATCH));
-
- SourceTextRetriever textRetriever = matchEvaluator.getTextRetriever();
- if (textRetriever instanceof HeaderTextRetriever) {
- matchElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.TYPE, nullNS,
- EvaluatorConstants.HEADER));
- HeaderTextRetriever headerTextRetriever = (HeaderTextRetriever) textRetriever;
- addSourceAttribute(headerTextRetriever.getSource(), matchElement);
-
- } else if (textRetriever instanceof ParameterTextRetriever) {
- matchElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.TYPE, nullNS,
- EvaluatorConstants.PARAM));
- ParameterTextRetriever paramTextRetriever = (ParameterTextRetriever) textRetriever;
- addSourceAttribute(paramTextRetriever.getSource(), matchElement);
-
- } else {
- matchElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.TYPE, nullNS,
- EvaluatorConstants.URL));
- URLTextRetriever urlTextRetriever = (URLTextRetriever) textRetriever;
- if (urlTextRetriever.getFragment() != null) {
- matchElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.FRAGMENT,
- nullNS, urlTextRetriever.getFragment()));
- }
- }
+ serializeSourceTextRetriever(matchEvaluator.getTextRetriever(), matchElement);
matchElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.REGEX, nullNS,
matchEvaluator.getRegex().toString()));
@@ -58,18 +32,4 @@ 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/config/TextProcessingEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/TextProcessingEvaluatorFactory.java?rev=996281&view=auto
==============================================================================
--- synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/TextProcessingEvaluatorFactory.java (added)
+++ synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/TextProcessingEvaluatorFactory.java Sun Sep 12 10:10:42 2010
@@ -0,0 +1,91 @@
+/*
+ * 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.config;
+
+import org.apache.synapse.commons.evaluators.source.*;
+import org.apache.synapse.commons.evaluators.EvaluatorConstants;
+import org.apache.synapse.commons.evaluators.EvaluatorException;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+
+public abstract class TextProcessingEvaluatorFactory implements EvaluatorFactory {
+
+ protected Log log = LogFactory.getLog(this.getClass());
+
+ protected SourceTextRetriever getSourceTextRetriever(OMElement e) throws EvaluatorException {
+ OMAttribute typeAttr = e.getAttribute(new QName(EvaluatorConstants.TYPE));
+ OMAttribute sourceAttr = e.getAttribute(new QName(EvaluatorConstants.SOURCE));
+
+ SourceTextRetriever textRetriever = null;
+ if (typeAttr != null) {
+ String value = typeAttr.getAttributeValue();
+ if (value.equals(EvaluatorConstants.HEADER)) {
+ if (sourceAttr != null) {
+ textRetriever = new HeaderTextRetriever(sourceAttr.getAttributeValue());
+ } else {
+ handleException(EvaluatorConstants.SOURCE + " attribute is required");
+ }
+ } else if (value.equals(EvaluatorConstants.PARAM)) {
+ if (sourceAttr != null) {
+ textRetriever = new ParameterTextRetriever(sourceAttr.getAttributeValue());
+ } else {
+ handleException(EvaluatorConstants.SOURCE + " attribute is required");
+ }
+ } else if (value.equals(EvaluatorConstants.URL)) {
+ textRetriever = new URLTextRetriever();
+ if (sourceAttr != null) {
+ ((URLTextRetriever) textRetriever).setSource(sourceAttr.getAttributeValue());
+ }
+ } else if (value.equals(EvaluatorConstants.PROPERTY)) {
+ if (sourceAttr != null) {
+ textRetriever = new PropertyTextRetriever(sourceAttr.getAttributeValue());
+ } else {
+ handleException(EvaluatorConstants.SOURCE + " attribute is required");
+ }
+ } else if (value.equals(EvaluatorConstants.SOAP)) {
+ if (sourceAttr != null) {
+ textRetriever = new SOAPEnvelopeTextRetriever(sourceAttr.getAttributeValue());
+ } else {
+ handleException(EvaluatorConstants.SOURCE + " attribute is required");
+ }
+ } else {
+ handleException("Unknown equal evaluator type: " + value);
+ }
+
+ } else {
+ if (sourceAttr != null) {
+ textRetriever = new HeaderTextRetriever(sourceAttr.getAttributeValue());
+ } else {
+ handleException(EvaluatorConstants.SOURCE + " attribute is required");
+ }
+ }
+
+ return textRetriever;
+ }
+
+ protected void handleException(String message) throws EvaluatorException {
+ log.error(message);
+ throw new EvaluatorException(message);
+ }
+}
Added: synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/TextProcessingEvaluatorSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/TextProcessingEvaluatorSerializer.java?rev=996281&view=auto
==============================================================================
--- synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/TextProcessingEvaluatorSerializer.java (added)
+++ synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/config/TextProcessingEvaluatorSerializer.java Sun Sep 12 10:10:42 2010
@@ -0,0 +1,76 @@
+/*
+ * 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.config;
+
+import org.apache.synapse.commons.evaluators.source.*;
+import org.apache.synapse.commons.evaluators.EvaluatorConstants;
+import org.apache.synapse.commons.evaluators.EvaluatorException;
+import org.apache.axiom.om.OMElement;
+
+public abstract class TextProcessingEvaluatorSerializer extends AbstractEvaluatorSerializer {
+
+ protected void serializeSourceTextRetriever(SourceTextRetriever textRetriever,
+ OMElement element) throws EvaluatorException {
+
+ if (textRetriever instanceof HeaderTextRetriever) {
+ element.addAttribute(fac.createOMAttribute(EvaluatorConstants.TYPE, nullNS,
+ EvaluatorConstants.HEADER));
+ addSourceAttribute(textRetriever.getSource(), element);
+
+ } else if (textRetriever instanceof ParameterTextRetriever) {
+ element.addAttribute(fac.createOMAttribute(EvaluatorConstants.TYPE, nullNS,
+ EvaluatorConstants.PARAM));
+ addSourceAttribute(textRetriever.getSource(), element);
+
+ } else if (textRetriever instanceof PropertyTextRetriever) {
+ element.addAttribute(fac.createOMAttribute(EvaluatorConstants.TYPE, nullNS,
+ EvaluatorConstants.PROPERTY));
+ addSourceAttribute(textRetriever.getSource(), element);
+
+ } else if (textRetriever instanceof SOAPEnvelopeTextRetriever) {
+ element.addAttribute(fac.createOMAttribute(EvaluatorConstants.TYPE, nullNS,
+ EvaluatorConstants.SOAP));
+ addSourceAttribute(textRetriever.getSource(), element);
+
+ } else {
+ element.addAttribute(fac.createOMAttribute(EvaluatorConstants.TYPE, nullNS,
+ EvaluatorConstants.URL));
+ if (textRetriever.getSource() != null) {
+ element.addAttribute(fac.createOMAttribute(EvaluatorConstants.SOURCE,
+ nullNS, textRetriever.getSource()));
+ }
+ }
+ }
+
+ private void addSourceAttribute(String source, OMElement element)
+ throws EvaluatorException {
+
+ if (source != null) {
+ element.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/source/PropertyTextRetriever.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/PropertyTextRetriever.java?rev=996281&r1=996280&r2=996281&view=diff
==============================================================================
--- synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/PropertyTextRetriever.java (original)
+++ synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/PropertyTextRetriever.java Sun Sep 12 10:10:42 2010
@@ -24,17 +24,17 @@ import org.apache.synapse.commons.evalua
public class PropertyTextRetriever implements SourceTextRetriever {
- private String key;
+ private String source;
- public PropertyTextRetriever(String key) {
- this.key = key;
+ public PropertyTextRetriever(String source) {
+ this.source = source;
}
public String getSourceText(EvaluatorContext context) throws EvaluatorException {
- return context.getProperty(key);
+ return context.getProperty(source);
}
- public String getKey() {
- return key;
+ public String getSource() {
+ return source;
}
}
Modified: synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/SOAPEnvelopeTextRetriever.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/SOAPEnvelopeTextRetriever.java?rev=996281&r1=996280&r2=996281&view=diff
==============================================================================
--- synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/SOAPEnvelopeTextRetriever.java (original)
+++ synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/SOAPEnvelopeTextRetriever.java Sun Sep 12 10:10:42 2010
@@ -33,11 +33,11 @@ import java.util.List;
public class SOAPEnvelopeTextRetriever implements SourceTextRetriever {
- private String xpath;
+ private String source;
private AXIOMXPath compiledXPath;
- public SOAPEnvelopeTextRetriever(String xpath) {
- this.xpath = xpath;
+ public SOAPEnvelopeTextRetriever(String source) {
+ this.source = source;
}
public String getSourceText(EvaluatorContext context) throws EvaluatorException {
@@ -46,11 +46,11 @@ public class SOAPEnvelopeTextRetriever i
try {
if (compiledXPath == null) {
- compiledXPath = new AXIOMXPath(xpath);
+ compiledXPath = new AXIOMXPath(source);
}
result = compiledXPath.evaluate(envelope);
} catch (JaxenException e) {
- throw new EvaluatorException("Error while parsing the XPath expression: " + xpath, e);
+ throw new EvaluatorException("Error while parsing the XPath expression: " + source, e);
}
if (result instanceof List) {
@@ -85,7 +85,7 @@ public class SOAPEnvelopeTextRetriever i
}
}
- public String getXpath() {
- return xpath;
+ public String getSource() {
+ return source;
}
}
Modified: 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=996281&r1=996280&r2=996281&view=diff
==============================================================================
--- synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/SourceTextRetriever.java (original)
+++ synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/SourceTextRetriever.java Sun Sep 12 10:10:42 2010
@@ -24,6 +24,8 @@ import org.apache.synapse.commons.evalua
public interface SourceTextRetriever {
+ public String getSource();
+
public String getSourceText(EvaluatorContext context) throws EvaluatorException;
}
Modified: 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=996281&r1=996280&r2=996281&view=diff
==============================================================================
--- synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/URLTextRetriever.java (original)
+++ synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/evaluators/source/URLTextRetriever.java Sun Sep 12 10:10:42 2010
@@ -58,14 +58,14 @@ public class URLTextRetriever implements
}
}
- public String getFragment() {
+ public String getSource() {
if (fragment != null) {
return fragment.name();
}
return null;
}
- public void setFragment(String fragment) {
+ public void setSource(String fragment) {
this.fragment = EvaluatorConstants.URI_FRAGMENTS.valueOf(fragment);
}
}
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=996281&r1=996280&r2=996281&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 Sun Sep 12 10:10:42 2010
@@ -43,7 +43,7 @@ public class EqualBuilderTest extends Te
EqualEvaluator eval = (EqualEvaluator) fac.create(AXIOMUtil.stringToOM(input));
SourceTextRetriever txtRtvr = eval.getTextRetriever();
assertTrue(txtRtvr instanceof HeaderTextRetriever);
- assertEquals(((HeaderTextRetriever) txtRtvr).getSource(), SOURCE);
+ assertEquals(txtRtvr.getSource(), SOURCE);
assertEquals(eval.getValue(), VALUE);
} catch (Exception e) {
fail("Error while parsing the input XML");
@@ -73,7 +73,7 @@ public class EqualBuilderTest extends Te
SourceTextRetriever txtRtvr = eval.getTextRetriever();
assertTrue(txtRtvr instanceof URLTextRetriever);
assertEquals(eval.getValue(), VALUE);
- assertNull(((URLTextRetriever) txtRtvr).getFragment());
+ assertNull(txtRtvr.getSource());
} catch (Exception e) {
fail("Error while parsing the input XML");
}
@@ -81,14 +81,14 @@ public class EqualBuilderTest extends Te
public void testURLEqual2() {
String input = "<equal type=\"url\" value=\"" + VALUE + "\"" +
- " fragment=\"" + FRAGMENT + "\"/>";
+ " source=\"" + FRAGMENT + "\"/>";
try {
EqualEvaluator eval = (EqualEvaluator) fac.create(AXIOMUtil.stringToOM(input));
SourceTextRetriever txtRtvr = eval.getTextRetriever();
assertTrue(txtRtvr instanceof URLTextRetriever);
assertEquals(eval.getValue(), VALUE);
- assertEquals(((URLTextRetriever) txtRtvr).getFragment(), FRAGMENT);
+ assertEquals(txtRtvr.getSource(), FRAGMENT);
} 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/EqualSerializerTest.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/config/EqualSerializerTest.java?rev=996281&r1=996280&r2=996281&view=diff
==============================================================================
--- synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/config/EqualSerializerTest.java (original)
+++ synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/config/EqualSerializerTest.java Sun Sep 12 10:10:42 2010
@@ -66,7 +66,7 @@ public class EqualSerializerTest extends
}
public void testURLEqualSerializer2() {
- String input = "<equal type=\"url\" value=\"http://foo.org\" fragment=\"protocol\"/>";
+ String input = "<equal type=\"url\" value=\"http://foo.org\" source=\"protocol\"/>";
try {
Evaluator eval = fac.create(AXIOMUtil.stringToOM(input));
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=996281&r1=996280&r2=996281&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 Sun Sep 12 10:10:42 2010
@@ -43,7 +43,7 @@ public class MatchBuilderTest extends Te
MatchEvaluator eval = (MatchEvaluator) fac.create(AXIOMUtil.stringToOM(input));
SourceTextRetriever txtRtvr = eval.getTextRetriever();
assertTrue(txtRtvr instanceof HeaderTextRetriever);
- assertEquals(((HeaderTextRetriever) txtRtvr).getSource(), SOURCE);
+ assertEquals(txtRtvr.getSource(), SOURCE);
assertEquals(eval.getRegex().pattern(), REGEX);
} catch (Exception e) {
fail("Error while parsing the input XML");
@@ -58,7 +58,7 @@ public class MatchBuilderTest extends Te
MatchEvaluator eval = (MatchEvaluator) fac.create(AXIOMUtil.stringToOM(input));
SourceTextRetriever txtRtvr = eval.getTextRetriever();
assertTrue(txtRtvr instanceof ParameterTextRetriever);
- assertEquals(((ParameterTextRetriever) txtRtvr).getSource(), SOURCE);
+ assertEquals(txtRtvr.getSource(), SOURCE);
assertEquals(eval.getRegex().pattern(), REGEX);
} catch (Exception e) {
fail("Error while parsing the input XML");
@@ -73,7 +73,7 @@ public class MatchBuilderTest extends Te
SourceTextRetriever txtRtvr = eval.getTextRetriever();
assertTrue(txtRtvr instanceof URLTextRetriever);
assertEquals(eval.getRegex().pattern(), REGEX);
- assertNull(((URLTextRetriever) txtRtvr).getFragment());
+ assertNull(txtRtvr.getSource());
} catch (Exception e) {
e.printStackTrace();
fail("Error while parsing the input XML");
@@ -81,7 +81,7 @@ public class MatchBuilderTest extends Te
}
public void testURLMatch2() {
- String input = "<match type=\"url\" regex=\"" + REGEX + "\" fragment=\"" +
+ String input = "<match type=\"url\" regex=\"" + REGEX + "\" source=\"" +
FRAGMENT +"\"/>";
try {
@@ -89,7 +89,7 @@ public class MatchBuilderTest extends Te
SourceTextRetriever txtRtvr = eval.getTextRetriever();
assertTrue(txtRtvr instanceof URLTextRetriever);
assertEquals(eval.getRegex().pattern(), REGEX);
- assertEquals(((URLTextRetriever) txtRtvr).getFragment(), FRAGMENT);
+ assertEquals(txtRtvr.getSource(), FRAGMENT);
} 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/MatchSerializerTest.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/config/MatchSerializerTest.java?rev=996281&r1=996280&r2=996281&view=diff
==============================================================================
--- synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/config/MatchSerializerTest.java (original)
+++ synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/config/MatchSerializerTest.java Sun Sep 12 10:10:42 2010
@@ -66,7 +66,7 @@ public class MatchSerializerTest extends
}
public void testURLMatchSerializer2() {
- String input = "<match type=\"url\" regex=\"http://foo.org\" fragment=\"protocol\"/>";
+ String input = "<match type=\"url\" regex=\"http://foo.org\" source=\"protocol\"/>";
try {
Evaluator eval = fac.create(AXIOMUtil.stringToOM(input));
Modified: synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/source/SourceTextRetrieverTest.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/source/SourceTextRetrieverTest.java?rev=996281&r1=996280&r2=996281&view=diff
==============================================================================
--- synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/source/SourceTextRetrieverTest.java (original)
+++ synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/commons/evaluators/source/SourceTextRetrieverTest.java Sun Sep 12 10:10:42 2010
@@ -29,9 +29,7 @@ import org.apache.axiom.om.OMAbstractFac
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.util.AXIOMUtil;
import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.AxisFault;
-import javax.xml.stream.XMLStreamException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
@@ -48,16 +46,16 @@ public class SourceTextRetrieverTest ext
URLTextRetriever txtRtvr = new URLTextRetriever();
assertEquals(uri.toString(), txtRtvr.getSourceText(context));
- txtRtvr.setFragment(EvaluatorConstants.URI_FRAGMENTS.host.name());
+ txtRtvr.setSource(EvaluatorConstants.URI_FRAGMENTS.host.name());
assertEquals(uri.getHost(), txtRtvr.getSourceText(context));
- txtRtvr.setFragment(EvaluatorConstants.URI_FRAGMENTS.port.name());
+ txtRtvr.setSource(EvaluatorConstants.URI_FRAGMENTS.port.name());
assertEquals(String.valueOf(uri.getPort()), txtRtvr.getSourceText(context));
- txtRtvr.setFragment(EvaluatorConstants.URI_FRAGMENTS.protocol.name());
+ txtRtvr.setSource(EvaluatorConstants.URI_FRAGMENTS.protocol.name());
assertEquals(uri.getScheme(), txtRtvr.getSourceText(context));
- txtRtvr.setFragment(EvaluatorConstants.URI_FRAGMENTS.path.name());
+ txtRtvr.setSource(EvaluatorConstants.URI_FRAGMENTS.path.name());
assertEquals(uri.getPath(), txtRtvr.getSourceText(context));
} catch (URISyntaxException ignore) {