Package org.apache.synapse.commons.evaluators

Examples of org.apache.synapse.commons.evaluators.MatchEvaluator


    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");
        }
    }
View Full Code Here


    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");
        }
    }
View Full Code Here

    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");
        }
View Full Code Here

    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");
        }
    }
View Full Code Here

* </pre>
*/
public class MatchFactory extends TextProcessingEvaluatorFactory {

    public Evaluator create(OMElement e) throws EvaluatorException {
        MatchEvaluator equal = new MatchEvaluator();
        SourceTextRetriever textRetriever = getSourceTextRetriever(e);
        equal.setTextRetriever(textRetriever);

        OMAttribute regExAttr = e.getAttribute(new QName(EvaluatorConstants.REGEX));
        if (regExAttr == null) {
            handleException(EvaluatorConstants.REGEX + " attribute is required");
            return null;
        }

        equal.setRegex(Pattern.compile(regExAttr.getAttributeValue()));
        return equal;
    }
View Full Code Here

    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(new QName(EvaluatorConstants.MATCH));
        serializeSourceTextRetriever(matchEvaluator.getTextRetriever(), matchElement);

        matchElement.addAttribute(fac.createOMAttribute(EvaluatorConstants.REGEX, nullNS,
                matchEvaluator.getRegex().toString()));

        if (parent != null) {
            parent.addChild(matchElement);
        }
View Full Code Here

        action3.setFragmentIndex(URIFragments.PORT);

        RewriteRule rule2 = new RewriteRule();
        rule2.addRewriteAction(action2);
        rule2.addRewriteAction(action3);
        MatchEvaluator eval2 = new MatchEvaluator();
        URLTextRetriever txtRtvr2 = new URLTextRetriever();
        txtRtvr2.setSource(EvaluatorConstants.URI_FRAGMENTS.path.name());
        eval2.setTextRetriever(txtRtvr2);
        eval2.setRegex(Pattern.compile(".*/MyService"));
        rule2.setCondition(eval2);
        mediator.addRule(rule2);

        MessageContext msgCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>");
        msgCtx.setTo(new EndpointReference("http://myhost:8280/MyService"));
View Full Code Here

        action3.setFragmentIndex(URIFragments.PORT);

        RewriteRule rule2 = new RewriteRule();
        rule2.addRewriteAction(action2);
        rule2.addRewriteAction(action3);
        MatchEvaluator eval2 = new MatchEvaluator();
        URLTextRetriever txtRtvr2 = new URLTextRetriever();
        txtRtvr2.setSource(EvaluatorConstants.URI_FRAGMENTS.path.name());
        eval2.setTextRetriever(txtRtvr2);
        eval2.setRegex(Pattern.compile(".*/MyService"));
        rule2.setCondition(eval2);
        mediator.addRule(rule2);

        MessageContext msgCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>");
        msgCtx.setTo(new EndpointReference("http://myhost:8280/MyService"));
View Full Code Here

TOP

Related Classes of org.apache.synapse.commons.evaluators.MatchEvaluator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.