Search in sources :

Example 1 with TemplateParam

use of org.apache.synapse.mediators.template.TemplateParam in project wso2-synapse by wso2.

the class TemplateMediatorFactory method initParameters.

private void initParameters(OMElement templateElem, TemplateMediator templateMediator) {
    Iterator subElements = templateElem.getChildElements();
    Collection<TemplateParam> templateParams = new ArrayList<>();
    while (subElements.hasNext()) {
        OMElement child = (OMElement) subElements.next();
        if (child.getQName().equals(PARAMETER_Q)) {
            String paramName = null;
            boolean isParamMandatory = false;
            Object defaultValue = null;
            OMAttribute paramNameAttr = child.getAttribute(ATT_NAME);
            if (paramNameAttr != null) {
                paramName = paramNameAttr.getAttributeValue();
            }
            OMAttribute paramMandatoryAttr = child.getAttribute(ATT_IS_MANDATORY);
            if (paramMandatoryAttr != null) {
                isParamMandatory = Boolean.parseBoolean(paramMandatoryAttr.getAttributeValue());
            }
            OMAttribute paramDefaultValueAttr = child.getAttribute(ATT_DEFAULT_VALUE);
            if (paramDefaultValueAttr != null) {
                defaultValue = paramDefaultValueAttr.getAttributeValue();
            }
            templateParams.add(new TemplateParam(paramName, isParamMandatory, defaultValue));
        // child.detach();
        }
    }
    templateMediator.setParameters(templateParams);
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) OMElement(org.apache.axiom.om.OMElement) TemplateParam(org.apache.synapse.mediators.template.TemplateParam) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 2 with TemplateParam

use of org.apache.synapse.mediators.template.TemplateParam in project wso2-synapse by wso2.

the class DebugManagerTest method testBreakPointTemplate.

public void testBreakPointTemplate() throws Exception {
    TestMediator t1 = new TestMediator();
    t1.setHandler(new TestMediateHandler() {

        public void handle(MessageContext synCtx) {
            result.append("T1.");
        }
    });
    TestMediator t2 = new TestMediator();
    t2.setHandler(new TestMediateHandler() {

        public void handle(MessageContext synCtx) {
            result.append("T2.");
        }
    });
    TestMediator t3 = new TestMediator();
    t3.setHandler(new TestMediateHandler() {

        public void handle(MessageContext synCtx) {
            result.append("T3");
        }
    });
    TemplateMediator temp = new TemplateMediator();
    temp.addChild(t1);
    temp.addChild(t2);
    temp.addChild(t3);
    temp.setName("test_sequence_template_6");
    temp.setParameters(new HashSet<TemplateParam>());
    synConfig.addSequenceTemplate(temp.getName(), temp);
    String debug_command = "{\"command\":\"set\",\"command-argument\":\"breakpoint\",\"mediation-component\":" + "\"template\",\"template\":{\"template-key\":\"test_sequence_template_6\",\"mediator-position\": \"0\"}}";
    dm.processDebugCommand(debug_command);
    debug_command = "{\"command\":\"set\",\"command-argument\":\"breakpoint\",\"mediation-component\":\"template\"," + "\"template\":{\"template-key\":\"test_sequence_template_6\",\"mediator-position\": \"1\"}}";
    dm.processDebugCommand(debug_command);
    MessageContext synCtx = TestUtils.getTestContext("<empty/>");
    synEnv.setDebugEnabled(false);
    temp.mediate(synCtx);
    assertTrue("T1.T2.T3".equals(result.toString()));
}
Also used : TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) TestMediateHandler(org.apache.synapse.mediators.TestMediateHandler) TestMediator(org.apache.synapse.mediators.TestMediator) MessageContext(org.apache.synapse.MessageContext) TemplateParam(org.apache.synapse.mediators.template.TemplateParam)

Example 3 with TemplateParam

use of org.apache.synapse.mediators.template.TemplateParam in project wso2-synapse by wso2.

the class DebugManagerTest method testSkipTemplate.

public void testSkipTemplate() throws Exception {
    TestMediator t1 = new TestMediator();
    t1.setHandler(new TestMediateHandler() {

        public void handle(MessageContext synCtx) {
            result.append("T1.");
        }
    });
    TestMediator t2 = new TestMediator();
    t2.setHandler(new TestMediateHandler() {

        public void handle(MessageContext synCtx) {
            result.append("T2.");
        }
    });
    TestMediator t3 = new TestMediator();
    t3.setHandler(new TestMediateHandler() {

        public void handle(MessageContext synCtx) {
            result.append("T3");
        }
    });
    TemplateMediator temp = new TemplateMediator();
    temp.addChild(t1);
    temp.addChild(t2);
    temp.addChild(t3);
    temp.setName("test_sequence_template_5");
    temp.setParameters(new HashSet<TemplateParam>());
    synConfig.addSequenceTemplate(temp.getName(), temp);
    String debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\",\"mediation-component\":\"template\"," + "\"template\":{\"template-key\":\"test_sequence_template_5\",\"mediator-position\": \"0\"}}";
    dm.processDebugCommand(debug_command);
    debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\",\"mediation-component\":\"template\"," + "\"template\":{\"template-key\":\"test_sequence_template_5\",\"mediator-position\": \"1\"}}";
    dm.processDebugCommand(debug_command);
    synEnv.setDebugEnabled(true);
    MessageContextCreatorForAxis2.setSynConfig(synConfig);
    MessageContextCreatorForAxis2.setSynEnv(synEnv);
    org.apache.axis2.context.MessageContext mc = new org.apache.axis2.context.MessageContext();
    AxisConfiguration axisConfig = synConfig.getAxisConfiguration();
    if (axisConfig == null) {
        axisConfig = new AxisConfiguration();
        synConfig.setAxisConfiguration(axisConfig);
    }
    ConfigurationContext cfgCtx = new ConfigurationContext(axisConfig);
    mc.setConfigurationContext(cfgCtx);
    mc.setEnvelope(TestUtils.getTestContext("<empty/>").getEnvelope());
    MessageContext synCtx = MessageContextCreatorForAxis2.getSynapseMessageContext(mc);
    temp.mediate(synCtx);
    assertTrue("T3".equals(result.toString()));
    synEnv.setDebugEnabled(false);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) TestMediator(org.apache.synapse.mediators.TestMediator) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) TestMediateHandler(org.apache.synapse.mediators.TestMediateHandler) MessageContext(org.apache.synapse.MessageContext) TemplateParam(org.apache.synapse.mediators.template.TemplateParam)

Example 4 with TemplateParam

use of org.apache.synapse.mediators.template.TemplateParam in project wso2-synapse by wso2.

the class TemplateMediatorSerializer method serializeParams.

private void serializeParams(OMElement templateElem, TemplateMediator mediator) {
    Collection<TemplateParam> params = mediator.getParameters();
    for (TemplateParam param : params) {
        OMElement paramEl = fac.createOMElement("parameter", synNS);
        paramEl.addAttribute(fac.createOMAttribute("name", nullNS, param.getName()));
        paramEl.addAttribute(fac.createOMAttribute("isMandatory", nullNS, Boolean.toString(param.isMandatory())));
        if (param.getDefaultValue() != null) {
            paramEl.addAttribute(fac.createOMAttribute("defaultValue", nullNS, param.getDefaultValue().toString()));
        }
        templateElem.addChild(paramEl);
    }
}
Also used : OMElement(org.apache.axiom.om.OMElement) TemplateParam(org.apache.synapse.mediators.template.TemplateParam)

Aggregations

TemplateParam (org.apache.synapse.mediators.template.TemplateParam)4 OMElement (org.apache.axiom.om.OMElement)2 MessageContext (org.apache.synapse.MessageContext)2 TestMediateHandler (org.apache.synapse.mediators.TestMediateHandler)2 TestMediator (org.apache.synapse.mediators.TestMediator)2 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)1 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)1