Search in sources :

Example 1 with HeaderMediatorFactory

use of org.apache.synapse.config.xml.HeaderMediatorFactory in project wso2-synapse by wso2.

the class HeaderMediatorTest method testEmbeddedXml.

public void testEmbeddedXml() throws Exception {
    String simpleHeader = "<header name=\"m:simpleHeader\" value=\"Simple Header\" xmlns:m=\"http://org.synapse.example\"/>";
    String complexHeader = "<header><m:complexHeader xmlns:m=\"http://org.synapse.example\"><property key=\"k1\" value=\"v1\"/><property key=\"k2\" value=\"v2\"/></m:complexHeader></header>";
    String removeHeader = "<header name=\"m:complexHeader\" action=\"remove\" xmlns:m=\"http://org.synapse.example\"/>";
    HeaderMediatorFactory fac = new HeaderMediatorFactory();
    try {
        // Adding headers.
        MessageContext synCtx = TestUtils.getTestContext("<empty/>");
        HeaderMediator headerMediator = (HeaderMediator) fac.createMediator(AXIOMUtil.stringToOM(simpleHeader), new Properties());
        headerMediator.mediate(synCtx);
        headerMediator = (HeaderMediator) fac.createMediator(AXIOMUtil.stringToOM(complexHeader), new Properties());
        headerMediator.mediate(synCtx);
        // Removing headers.
        headerMediator = (HeaderMediator) fac.createMediator(AXIOMUtil.stringToOM(removeHeader), new Properties());
        headerMediator.mediate(synCtx);
    } catch (XMLStreamException e) {
        fail("Error while parsing header mediator configuration: inline XML scenario. " + e.getMessage());
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) HeaderMediatorFactory(org.apache.synapse.config.xml.HeaderMediatorFactory) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Properties(java.util.Properties)

Aggregations

Properties (java.util.Properties)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 MessageContext (org.apache.synapse.MessageContext)1 HeaderMediatorFactory (org.apache.synapse.config.xml.HeaderMediatorFactory)1 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)1