Search in sources :

Example 1 with MatchEvaluator

use of org.apache.synapse.commons.evaluators.MatchEvaluator in project wso2-synapse by wso2.

the class MatchSerializer method serialize.

public OMElement serialize(OMElement parent, Evaluator evaluator) throws EvaluatorException {
    if (!(evaluator instanceof MatchEvaluator)) {
        throw new IllegalArgumentException("Evalutor must be a NotEvalutor");
    }
    MatchEvaluator matchEvaluator = (MatchEvaluator) evaluator;
    OMElement matchElement = fac.createOMElement(EvaluatorConstants.MATCH, EvaluatorConstants.SYNAPSE_NAMESPACE, EvaluatorConstants.EMPTY_PREFIX);
    serializeSourceTextRetriever(matchEvaluator.getTextRetriever(), matchElement);
    matchElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.REGEX, nullNS, matchEvaluator.getRegex().toString()));
    if (parent != null) {
        parent.addChild(matchElement);
    }
    return matchElement;
}
Also used : OMElement(org.apache.axiom.om.OMElement) MatchEvaluator(org.apache.synapse.commons.evaluators.MatchEvaluator)

Example 2 with MatchEvaluator

use of org.apache.synapse.commons.evaluators.MatchEvaluator in project wso2-synapse by wso2.

the class MatchBuilderTest method testParameterMatch.

public void testParameterMatch() {
    String input = "<match type=\"param\" source=\"" + SOURCE + "\" regex=\"" + REGEX + "\"/>";
    try {
        MatchEvaluator eval = (MatchEvaluator) fac.create(AXIOMUtil.stringToOM(input));
        SourceTextRetriever txtRtvr = eval.getTextRetriever();
        assertTrue(txtRtvr instanceof ParameterTextRetriever);
        assertEquals(txtRtvr.getSource(), SOURCE);
        assertEquals(eval.getRegex().pattern(), REGEX);
    } catch (Exception e) {
        fail("Error while parsing the input XML");
    }
}
Also used : ParameterTextRetriever(org.apache.synapse.commons.evaluators.source.ParameterTextRetriever) SourceTextRetriever(org.apache.synapse.commons.evaluators.source.SourceTextRetriever) MatchEvaluator(org.apache.synapse.commons.evaluators.MatchEvaluator)

Example 3 with MatchEvaluator

use of org.apache.synapse.commons.evaluators.MatchEvaluator in project wso2-synapse by wso2.

the class MatchBuilderTest method testHeaderMatch.

public void testHeaderMatch() {
    String input = "<match type=\"header\" source=\"" + SOURCE + "\" regex=\"" + REGEX + "\"/>";
    try {
        MatchEvaluator eval = (MatchEvaluator) fac.create(AXIOMUtil.stringToOM(input));
        SourceTextRetriever txtRtvr = eval.getTextRetriever();
        assertTrue(txtRtvr instanceof HeaderTextRetriever);
        assertEquals(txtRtvr.getSource(), SOURCE);
        assertEquals(eval.getRegex().pattern(), REGEX);
    } catch (Exception e) {
        fail("Error while parsing the input XML");
    }
}
Also used : HeaderTextRetriever(org.apache.synapse.commons.evaluators.source.HeaderTextRetriever) SourceTextRetriever(org.apache.synapse.commons.evaluators.source.SourceTextRetriever) MatchEvaluator(org.apache.synapse.commons.evaluators.MatchEvaluator)

Example 4 with MatchEvaluator

use of org.apache.synapse.commons.evaluators.MatchEvaluator in project wso2-synapse by wso2.

the class MatchBuilderTest method testURLMatch2.

public void testURLMatch2() {
    String input = "<match type=\"url\" regex=\"" + REGEX + "\" source=\"" + FRAGMENT + "\"/>";
    try {
        MatchEvaluator eval = (MatchEvaluator) fac.create(AXIOMUtil.stringToOM(input));
        SourceTextRetriever txtRtvr = eval.getTextRetriever();
        assertTrue(txtRtvr instanceof URLTextRetriever);
        assertEquals(eval.getRegex().pattern(), REGEX);
        assertEquals(txtRtvr.getSource(), FRAGMENT);
    } catch (Exception e) {
        fail("Error while parsing the input XML");
    }
}
Also used : URLTextRetriever(org.apache.synapse.commons.evaluators.source.URLTextRetriever) SourceTextRetriever(org.apache.synapse.commons.evaluators.source.SourceTextRetriever) MatchEvaluator(org.apache.synapse.commons.evaluators.MatchEvaluator)

Example 5 with MatchEvaluator

use of org.apache.synapse.commons.evaluators.MatchEvaluator in project wso2-synapse by wso2.

the class MatchBuilderTest method testURLMatch.

public void testURLMatch() {
    String input = "<match type=\"url\" regex=\"" + REGEX + "\"/>";
    try {
        MatchEvaluator eval = (MatchEvaluator) fac.create(AXIOMUtil.stringToOM(input));
        SourceTextRetriever txtRtvr = eval.getTextRetriever();
        assertTrue(txtRtvr instanceof URLTextRetriever);
        assertEquals(eval.getRegex().pattern(), REGEX);
        assertNull(txtRtvr.getSource());
    } catch (Exception e) {
        e.printStackTrace();
        fail("Error while parsing the input XML");
    }
}
Also used : URLTextRetriever(org.apache.synapse.commons.evaluators.source.URLTextRetriever) SourceTextRetriever(org.apache.synapse.commons.evaluators.source.SourceTextRetriever) MatchEvaluator(org.apache.synapse.commons.evaluators.MatchEvaluator)

Aggregations

MatchEvaluator (org.apache.synapse.commons.evaluators.MatchEvaluator)7 SourceTextRetriever (org.apache.synapse.commons.evaluators.source.SourceTextRetriever)5 URLTextRetriever (org.apache.synapse.commons.evaluators.source.URLTextRetriever)3 QName (javax.xml.namespace.QName)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 OMElement (org.apache.axiom.om.OMElement)1 EndpointReference (org.apache.axis2.addressing.EndpointReference)1 MessageContext (org.apache.synapse.MessageContext)1 EqualEvaluator (org.apache.synapse.commons.evaluators.EqualEvaluator)1 HeaderTextRetriever (org.apache.synapse.commons.evaluators.source.HeaderTextRetriever)1 ParameterTextRetriever (org.apache.synapse.commons.evaluators.source.ParameterTextRetriever)1 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)1