/** * Allow the mediator factory finder to act as an XMLToObjectMapper for Mediators * (i.e. Sequence Mediator) loaded dynamically from a Registry * @param om node from which the object is expected * @return Object buit from the om node */ public Object getObjectFromOMNode(OMNode om, Properties properties) { if (om instanceof OMElement) { return getMediator((OMElement) om, properties); } else { handleException("Invalid mediator configuration XML : " + om); } return null; }
/** * Allow the mediator factory finder to act as an XMLToObjectMapper for Mediators * (i.e. Sequence Mediator) loaded dynamically from a Registry * @param om node from which the object is expected * @return Object buit from the om node */ public Object getObjectFromOMNode(OMNode om, Properties properties) { if (om instanceof OMElement) { return getMediator((OMElement) om, properties); } else { handleException("Invalid mediator configuration XML : " + om); } return null; }
protected static void addChildren(OMElement el, ListMediator m, Properties properties) { Iterator it = el.getChildElements(); while (it.hasNext()) { OMElement child = (OMElement) it.next(); if (!DESCRIPTION_Q.equals(child.getQName())) { // neglect the description tag Mediator med = MediatorFactoryFinder.getInstance().getMediator(child, properties); if (med != null) { m.addChild(med); } else { String msg = "Unknown mediator : " + child.getLocalName(); log.error(msg); throw new SynapseException(msg); } } } } }
public Object getObjectFromOMNode(OMNode om, Properties properties) { if (!(om instanceof OMElement)) { throw new SynapseException("Configuration is not in proper format."); } OMElement elem = (OMElement) om; OMElement element = elem.getFirstChildWithName( new QName(SynapseConstants.SYNAPSE_NAMESPACE, "sequence")); if (element != null) { return MediatorFactoryFinder.getInstance().getMediator(elem, properties); } element = elem.getFirstChildWithName( new QName(SynapseConstants.SYNAPSE_NAMESPACE, "endpoint")); if (element != null) { TemplateFactory templateFactory = new TemplateFactory(); return templateFactory.createEndpointTemplate(elem, properties); } return null; } }
public static Mediator defineMediatorTemplate(SynapseConfiguration config, OMElement ele, Properties properties) { Mediator mediator = null; String name = ele.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "name")); if (name != null) { try { mediator = MediatorFactoryFinder.getInstance().getMediator(ele, properties); if (mediator != null) { config.addSequenceTemplate(name, (TemplateMediator) mediator) ; } } catch (Exception e) { String msg = "Template configuration: " + name + " cannot be built"; handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_TEMPLATES, msg, e); } return mediator; } else { String msg = "Invalid mediation template definition without a name"; handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_TEMPLATES, msg); } return null; }
protected boolean serialization(String inputXml, MediatorSerializer mediatorSerializer) { OMElement inputOM = createOMElement(inputXml); Mediator mediator = MediatorFactoryFinder.getInstance().getMediator(inputOM, new Properties()); OMElement resultOM = mediatorSerializer.serializeMediator(null, mediator); try { assertXMLEqual(resultOM.toString(), inputXml); return true; } catch (SAXException e) { log.error(e); } catch (IOException e) { log.error(e); } return false; }
protected boolean serialization(String inputXml, MediatorSerializer mediatorSerializer) { OMElement inputOM = createOMElement(inputXml); Mediator mediator = MediatorFactoryFinder.getInstance().getMediator(inputOM, new Properties()); OMElement resultOM = mediatorSerializer.serializeMediator(null, mediator); try { assertXMLEqual(resultOM.toString(), inputXml); return true; } catch (SAXException e) { log.error(e); } catch (IOException e) { log.error(e); } return false; }
public void testBasicExecute() throws Exception { AnnotatedCommandMediator m = new AnnotatedCommandMediator(); m.setCommand(AnnotatedCommand.class); Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement( "<annotatedCommand name='org.apache.synapse.mediators.ext.AnnotatedCommand2' xmlns='http://ws.apache.org/ns/synapse'/>"), new Properties()); MessageContext mc = TestUtils.getTestContext("<m:getQuote xmlns:m=\"http://services.samples/xsd\"><m:request><m:symbol>IBM</m:symbol></m:request></m:getQuote>"); pcm.mediate(mc); assertEquals("IBM", AnnotatedCommand2.fieldResult); assertEquals("IBM", AnnotatedCommand2.methodResult); } }
public void testMediationWithLiteralProperties() throws Exception { Mediator cm = MediatorFactoryFinder.getInstance().getMediator(createOMElement( "<class name='org.apache.synapse.mediators.ext.ClassMediatorTestMediator' " + "xmlns='http://ws.apache.org/ns/synapse'><property name='testProp' value='testValue'/></class>"), new Properties()); TestMessageContext msgContext = new TestMessageContext(); msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration())); cm.mediate(msgContext); assertTrue(ClassMediatorTestMediator.invoked); assertTrue(ClassMediatorTestMediator.testProp.equals("testValue")); }
public void testMediationWithoutProperties() throws Exception { Mediator cm = MediatorFactoryFinder.getInstance().getMediator(createOMElement( "<class name='org.apache.synapse.mediators.ext.ClassMediatorTestMediator' " + "xmlns='http://ws.apache.org/ns/synapse'/>"), new Properties()); TestMessageContext msgContext = new TestMessageContext(); msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration())); cm.mediate(msgContext); assertTrue(ClassMediatorTestMediator.invoked); }
public void testDestroy() throws Exception { Mediator cm = MediatorFactoryFinder.getInstance().getMediator(createOMElement( "<class name='org.apache.synapse.mediators.ext.ClassMediatorTestMediator' " + "xmlns='http://ws.apache.org/ns/synapse'/>"), new Properties()); TestMessageContext msgContext = new TestMessageContext(); msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration())); cm.mediate(msgContext); assertTrue(ClassMediatorTestMediator.invoked); ((ManagedLifecycle) cm).destroy(); assertTrue(ClassMediatorTestMediator.destroyed); }
public void testPojoWithoutPropertiesCommandImpl() throws Exception { Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement( "<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator' " + "xmlns='http://ws.apache.org/ns/synapse'/>"), new Properties()); POJOCommandTestHelper.reset(); TestMessageContext msgContext = new TestMessageContext(); msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration())); pcm.mediate(msgContext); assertTrue(POJOCommandTestHelper.getInstance().isExecuted()); }
public void testPojoWithoutPropertiesNotCommandImpl() throws Exception { Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement( "<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestMediator' " + "xmlns='http://ws.apache.org/ns/synapse'/>"), new Properties()); POJOCommandTestHelper.reset(); TestMessageContext msgContext = new TestMessageContext(); msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration())); pcm.mediate(msgContext); assertTrue(POJOCommandTestHelper.getInstance().isExecuted()); }
public void testPojoWithContextR$UPropertiesCommandImpl() throws Exception { Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement( "<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator' " + "xmlns='http://ws.apache.org/ns/synapse'><property name=\"ctxTest\" " + "context-name=\"testCtxProp\" action=\"ReadAndUpdateContext\"/></pojoCommand>"), new Properties()); POJOCommandTestHelper.reset(); MessageContext ctx = new TestMessageContext(); ctx.setProperty("testCtxProp", "test"); ctx.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration())); pcm.mediate(ctx); assertEquals("testcommand", ctx.getProperty("testCtxProp").toString()); assertTrue(POJOCommandTestHelper.getInstance().isExecuted()); } }
public void testPojoWithMessagePropertiesCommandImpl() throws Exception { Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement( "<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator' " + "xmlns='http://ws.apache.org/ns/synapse'><property name=\"testProp\" " + "value=\"TestProperty\" expression=\"//testNode\"/></pojoCommand>"), new Properties()); POJOCommandTestHelper.reset(); MessageContext ctx = new TestMessageContext(); SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope(); envelope.getBody().addChild(createOMElement("<original><testNode/></original>")); ctx.setEnvelope(envelope); ctx.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration())); pcm.mediate(ctx); assertEquals("TestProperty", POJOCommandTestHelper.getInstance().getChangedProperty()); assertEquals("<original>TestProperty</original>", ctx.getEnvelope().getBody().getFirstOMChild().toString()); assertTrue(POJOCommandTestHelper.getInstance().isExecuted()); }
public void testPojoWithPropertiesCommandImpl() throws Exception { Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement( "<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator' " + "xmlns='http://ws.apache.org/ns/synapse'><property name=\"testProp\" " + "expression=\"fn:concat('XPATH ', 'FUNC')\" action=\"ReadMessage\"/></pojoCommand>"), new Properties()); POJOCommandTestHelper.reset(); TestMessageContext msgContext = new TestMessageContext(); msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration())); pcm.mediate(msgContext); assertEquals("XPATH FUNC", POJOCommandTestHelper.getInstance().getChangedProperty()); assertTrue(POJOCommandTestHelper.getInstance().isExecuted()); }
public void testInitializationAndMedition() throws Exception { Mediator cm = MediatorFactoryFinder.getInstance().getMediator(createOMElement( "<class name='org.apache.synapse.mediators.ext.ClassMediatorTestMediator' " + "xmlns='http://ws.apache.org/ns/synapse'/>"), new Properties()); ((ManagedLifecycle) cm).init(new Axis2SynapseEnvironment(new SynapseConfiguration())); assertTrue(ClassMediatorTestMediator.initialized); TestMessageContext msgContext = new TestMessageContext(); msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration())); cm.mediate(msgContext); assertTrue(ClassMediatorTestMediator.invoked); }
public void testPojoWithPropertiesNotCommandImpl() throws Exception { Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement( "<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestMediator' " + "xmlns='http://ws.apache.org/ns/synapse'><property name=\"testProp\" " + "expression=\"fn:concat('XPATH ', 'FUNC')\" action=\"ReadMessage\"/></pojoCommand>"), new Properties()); POJOCommandTestHelper.reset(); TestMessageContext msgContext = new TestMessageContext(); msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration())); pcm.mediate(msgContext); assertEquals("XPATH FUNC", POJOCommandTestHelper.getInstance().getChangedProperty()); assertTrue(POJOCommandTestHelper.getInstance().isExecuted()); }
public void testPojoWithStaticPropertiesCommandImpl() throws Exception { Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement( "<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator' " + "xmlns='http://ws.apache.org/ns/synapse'><property name=\"testProp\" " + "value=\"Test Property\"/></pojoCommand>"), new Properties()); POJOCommandTestHelper.reset(); TestMessageContext msgContext = new TestMessageContext(); msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration())); pcm.mediate(msgContext); assertEquals("Test Property", POJOCommandTestHelper.getInstance().getChangedProperty()); assertTrue(POJOCommandTestHelper.getInstance().isExecuted()); }
public void testPojoWithContextPropertiesCommandImpl() throws Exception { Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement( "<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator' " + "xmlns='http://ws.apache.org/ns/synapse'><property name=\"testProp\" " + "value=\"Test Property\" context-name=\"testPropInMC\"/></pojoCommand>"), new Properties()); POJOCommandTestHelper.reset(); MessageContext ctx = new TestMessageContext(); ctx.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration())); pcm.mediate(ctx); assertEquals("Test Property", POJOCommandTestHelper.getInstance().getChangedProperty()); assertEquals("Test Property", ctx.getProperty("testPropInMC")); assertTrue(POJOCommandTestHelper.getInstance().isExecuted()); }